void t_log::write_raw(const string &raw) { if (log_disabled || log_report_disabled) return; if (raw.size() < MAX_LEN_LOG_STRING) { *log_stream << to_printable(raw); } else { *log_stream << to_printable(raw.substr(0, MAX_LEN_LOG_STRING)); *log_stream << "\n\n"; *log_stream << "<cut off>\n"; } }
match_result operator ()(const U &value) const { std::ostringstream ss; ostream_list_append append(ss); bool good = true; ss << "["; auto i = std::begin(value), end = std::end(value); for(auto &&m : matchers_) { if(i == end) { good = false; break; } match_result result = m(*i); good &= result; append(matcher_message(result, *i)); ++i; } // Print any remaining expected values (if `value` is longer than the list // of matchers). good &= (i == end); for(; i != end; ++i) append(to_printable(*i)); ss << "]"; return {good, ss.str()}; }
void UART_Visualization_Linux_pv::receive_from_console() { //SC_THREAD that reads from the console while(1) { if (m_console_receive_enable) { char buf[read_from_console_buffer_size]; int r = con_io->b_read(buf, sizeof(buf), m_console_read_wait_period); // int r = con_io->read(buf, sizeof(buf)); if (r > 0) { m_buffered_write->flush(); #if defined MB_DEBUG_VisualizationObject & (MB_DEBUG_VisualizationObject >= 1) char out_buf[read_from_console_buffer_size*2]; to_printable(buf, r, out_buf); cout << this-> name() << " @ " << sc_time_stamp() << " Reading from TX console: " << out_buf; //No endl is needed # endif to_UART(buf,r); } else if (r == 0) { //fprintf(stderr, "NO_DATA"); } else break; } // wait(m_console_read_wait_period); } if ( (errno != EPIPE) && (m_console_receive_enable == true) ) perror("Failed"); delete con_io; con_io = 0; }
std::string stringify_tuple(const T &tuple) { std::ostringstream ss; ss << "[" << tuple_joined(tuple, [](auto &&item) { return to_printable(item); }) << "]"; return ss.str(); }
std::string to_printable(T begin, T end) { std::ostringstream ss; ss << "[" << detail::iter_joined(begin, end, [](auto &&item) { return to_printable(item); }) << "]"; return ss.str(); }
inline auto thrown() { return make_matcher([](auto &&value) -> match_result { try { value(); return {false, "threw nothing"}; } catch(const std::exception &e) { std::ostringstream ss; ss << "threw " << to_printable(e); return {true, ss.str()}; } catch(...) { return {true, "threw unknown exception"}; } }, "threw exception"); }
static void test_strutils() { // string conversion check(to_string(integer(0)) == "0"); check(to_string(integer(-1)) == "-1"); check(to_string(INTEGER_MAX) == INTEGER_MAX_STR); check(to_string(INTEGER_MIN) == INTEGER_MIN_STR); check(to_string(1, 10, 4, '0') == "0001"); check(to_string(integer(123456789)) == "123456789"); check(to_string(-123, 10, 7, '0') == "-000123"); check(to_string(0xabcde, 16, 6) == "0ABCDE"); bool e = true, o = true; check(from_string("0", &e, &o) == 0); check(!o); check(!e); check(from_string(INTEGER_MAX_STR, &e, &o) == INTEGER_MAX); check(from_string(INTEGER_MAX_STR_PLUS, &e, &o) == uinteger(INTEGER_MAX) + 1); check(from_string("92233720368547758070", &e, &o) == 0); check(o); check(from_string("-1", &e, &o) == 0 ); check(e); check(from_string("89abcdef", &e, &o, 16) == 0x89abcdef); check(from_string("afg", &e, &o, 16) == 0); check(e); check(remove_filename_path("/usr/bin/true") == "true"); check(remove_filename_path("usr/bin/true") == "true"); check(remove_filename_path("/true") == "true"); check(remove_filename_path("true") == "true"); check(remove_filename_path("c:\\Windows\\false") == "false"); check(remove_filename_path("\\Windows\\false") == "false"); check(remove_filename_path("Windows\\false") == "false"); check(remove_filename_path("\\false") == "false"); check(remove_filename_path("false") == "false"); check(remove_filename_ext("/usr/bin/true.exe") == "/usr/bin/true"); check(remove_filename_ext("true.exe") == "true"); check(remove_filename_ext("true") == "true"); check(to_printable('a') == "a"); check(to_printable('\\') == "\\\\"); check(to_printable('\'') == "\\'"); check(to_printable('\x00') == "\\x00"); check(to_printable('\x7f') == "\\x7F"); check(to_printable("abc \x01'\\") == "abc \\x01\\'\\\\"); }
std::string desc() const { std::ostringstream ss; ss << "permutation of " << to_printable(container_.value) << " for " << to_printable(predicate_); return ss.str(); }