3 #include <framework/logging/Logger.h>
44 for (
int i = 0; i < size; i++) {
45 if (count[i] >= 0 && count[i] < 9) {
48 B2WARNING(
"invalid signal detected: " <<
static_cast<int>(count[i]));
59 int ini = padding ? signal.size() % 4 : 0;
60 std::string res(ini,
'0');
61 for (
auto const& bit : signal) {
62 if (bit >= 0 && bit < 9) {
65 B2WARNING(
"invalid signal detected: " <<
static_cast<int>(bit));
76 std::ios oldState(
nullptr);
77 oldState.copyfmt(std::cout);
78 if (std::any_of(signal.begin(), signal.end(), [](
char i)
79 {return i != zero_val && i != one_val;})) {
80 B2WARNING(
"Some bit in the signal vector is neither 0 nor 1. \n" <<
81 "Displaying binary values instead.");
85 std::cout << std::setfill(
'0');
86 for (
unsigned i = 0; i < signal.size(); i += 4) {
87 std::bitset<4> set(binString.substr(i, 4));
88 std::cout << std::setw(1) << std::hex << set.to_ulong();
92 std::cout.copyfmt(oldState);
99 if (std::any_of(signal.begin(), signal.end(), [](
char i)
100 {return i != zero_val;})) {
112 template<
size_t nbits,
size_t min,
size_t max>
113 std::bitset < max - min + 1 >
subset(std::bitset<nbits> set)
115 const size_t outWidth = max - min + 1;
116 std::string str = set.to_string();
117 return std::bitset<outWidth>(str.substr(nbits - max - 1, outWidth));
121 #include <ext/stdio_filebuf.h>
123 using __gnu_cxx::stdio_filebuf;
127 inline stdio_filebuf<char>* fileBufFromFD(
int fd, std::_Ios_Openmode mode)
129 return (
new stdio_filebuf<char> (fd, mode));
132 istream* createInStreamFromFD(
int fd)
134 stdio_filebuf<char>* fileBuf = fileBufFromFD(fd, std::ios::in);
135 return (
new istream(fileBuf));
138 ostream* createOutStreamFromFD(
int fd)
140 stdio_filebuf<char>* fileBuf = fileBufFromFD(fd, std::ios::out);
141 return (
new ostream(fileBuf));
144 std::string getcurrentdir()
147 getcwd(buf,
sizeof(buf) - 1);
148 buf[
sizeof(buf) - 1] = 0;