-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d806245
commit bf9b9e9
Showing
10 changed files
with
395 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <cinttypes> | ||
#include <limits> | ||
#include <string> | ||
|
||
#include "nigiri/types.h" | ||
|
||
namespace nigiri::routing { | ||
|
||
using clasz_mask_t = std::uint16_t; | ||
|
||
constexpr inline clasz_mask_t all_clasz_allowed() { | ||
return std::numeric_limits<clasz_mask_t>::max(); | ||
} | ||
|
||
constexpr inline clasz_mask_t to_mask(clasz const c) { | ||
auto const c_as_int = static_cast<std::underlying_type_t<clasz>>(c); | ||
return static_cast<clasz_mask_t>(1U << c_as_int); | ||
} | ||
|
||
constexpr inline bool is_allowed(clasz_mask_t const mask, clasz const c) { | ||
auto const c_as_mask = to_mask(c); | ||
return (mask & c_as_mask) == c_as_mask; | ||
} | ||
|
||
std::string to_str(clasz_mask_t const x); | ||
|
||
} // namespace nigiri::routing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "nigiri/routing/clasz_mask.h" | ||
|
||
namespace nigiri::routing { | ||
|
||
std::string to_str(clasz_mask_t const x) { | ||
auto s = std::string{}; | ||
s += ", x=" + std::to_string(x); | ||
for (auto i = std::underlying_type_t<clasz>{0U}; | ||
i != sizeof(clasz_mask_t) * 8; ++i) { | ||
auto const allowed = is_allowed(x, clasz{i}); | ||
s.insert(0, 1, allowed ? '1' : '0'); | ||
} | ||
return s; | ||
} | ||
|
||
} // namespace nigiri::routing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.