23#include <boost/lexical_cast.hpp> 
   24#include <boost/algorithm/string.hpp> 
  143template<
typename Value>
 
  164  explicit Scoped_setter(Value* target, Value&& val_src_moved);
 
  205template<
typename Value>
 
  207  m_target_or_null(target),
 
  208  m_saved_value(std::move(*m_target_or_null))
 
  213template<
typename Value>
 
  215  m_target_or_null(src_moved.m_target_or_null),
 
  216  m_saved_value(std::move(src_moved.m_saved_value))
 
  218  assert(
m_target_or_null && 
"Should not be moving-from a thing that has already been moved-from.");
 
  220  src_moved.m_target_or_null = 
nullptr;
 
  224template<
typename Value>
 
  227  if (m_target_or_null)
 
  229    *m_target_or_null = std::move(m_saved_value);
 
  236template<
typename Time_unit, 
typename N_items>
 
  253    double(items_per_time) * double(bits_per_item) * double(Time_unit::period::den)
 
  254    / (double(Time_unit::period::num) * double(1000 * 1000));
 
  257template<
typename Integer>
 
  261  static_assert(std::is_integral_v<Integer>, 
"ceil_div<T>: T must be an integer type.");
 
  262  assert(dividend >= 0);
 
  265  return (dividend + divisor - 1) / divisor;
 
  274  return ((min_val < val) || (!(val < min_val))) &&
 
  275         ((val < max_val) || (!(max_val < val)));
 
  282  return (min_val < val) &&
 
  283         ((val < max_val) || (!(max_val < val)));
 
  290  return (val < max_val) &&
 
  291         ((min_val < val) || (!(val < min_val)));
 
  297  return (min_val < val) && (val < max_val);
 
  300template<
typename Container>
 
  301bool key_exists(
const Container& container, 
const typename Container::key_type& key)
 
  303  return container.find(key) != container.end();
 
  306template<
typename Cleanup_func>
 
  320                      [func](
void*) { func(); });
 
  323template<
typename Minuend, 
typename Subtrahend>
 
  332  const Minuend converted_subtrahend = Minuend(subtrahend);
 
  335  if ((*minuend - floor) <= converted_subtrahend)
 
  341  *minuend -= converted_subtrahend;
 
  345template<
typename From, 
typename To>
 
  348  return ((num_froms * 
sizeof(From)) + 
sizeof(To) - 1) / 
sizeof(To);
 
  351template<
typename T1, 
typename ...T_rest>
 
  363  *os << only_ostream_arg;
 
  366template<
typename ...T>
 
  380template<
typename ...T>
 
  390template<
typename Map, 
typename Sequence>
 
  392       (Sequence 
const & src_seq, Map* target_map,
 
  393        const Function<
typename Map::mapped_type (
size_t)>& idx_to_map_val_func)
 
  396  for (
const auto& src_element : src_seq)
 
  398    (*target_map)[src_element] = idx_to_map_val_func(idx);
 
  403template<
typename Map, 
typename Sequence>
 
  412template<
typename Const_buffer_sequence>
 
  414                                 const Const_buffer_sequence& data,
 
  415                                 const std::string& indentation,
 
  416                                 size_t bytes_per_line)
 
  418  using boost::io::ios_fill_saver;
 
  419  using boost::io::ios_flags_saver;
 
  420  using boost::io::ios_width_saver;
 
  421  using boost::asio::buffers_iterator;
 
  426  using Bufs_iter = buffers_iterator<Const_buffer_sequence, uint8_t>;
 
  428  constexpr size_t BYTES_PER_LINE_DEFAULT = 16;
 
  429  bool single_line_mode = 
false;
 
  430  if (bytes_per_line == 0)
 
  432    bytes_per_line = BYTES_PER_LINE_DEFAULT;
 
  434  else if (bytes_per_line == 
size_t(-1))
 
  438    bytes_per_line = buffer_size(data);
 
  442    single_line_mode = 
true;
 
  446  ios_flags_saver flags_saver(os);
 
  447  ios_fill_saver fill_saver(os);
 
  448  ios_width_saver width_saver(os);
 
  452  os.setf(std::ios::right | std::ios::hex, std::ios::adjustfield | std::ios::basefield);
 
  453  os << std::setfill(
'0');
 
  455  const Bufs_iter end_byte_it = Bufs_iter::end(data);
 
  457  for (Bufs_iter cur_byte_it = Bufs_iter::begin(data);
 
  458       cur_byte_it != end_byte_it;
 
  462    os << indentation << 
'[' 
  463       << std::setw(2) << int(*cur_byte_it); 
 
  466    size_t n_bytes_printed;
 
  467    for ((n_bytes_printed = 1), ++cur_byte_it; 
 
  468         (n_bytes_printed != bytes_per_line) && (cur_byte_it != end_byte_it);
 
  469         ++cur_byte_it, ++n_bytes_printed)
 
  471      os << 
' ' << std::setw(2) << int(*cur_byte_it); 
 
  475    for (
size_t n_bytes_printed_including_padding = n_bytes_printed;
 
  476         n_bytes_printed_including_padding != bytes_per_line;
 
  477         ++n_bytes_printed_including_padding)
 
  483    cur_byte_it -= n_bytes_printed;
 
  486    for (
size_t n_chars_printed = 0;
 
  487         n_chars_printed != n_bytes_printed;
 
  488         ++cur_byte_it, ++n_chars_printed)
 
  490      char c = *cur_byte_it;
 
  491      os << (isprint(c) ? c : 
'.');
 
  494    if (!single_line_mode)
 
  505template<
typename Const_buffer_sequence>
 
  507                                size_t bytes_per_line)
 
  522template<
typename Enum>
 
  524                     bool accept_num_encoding, 
bool case_sensitive,
 
  527  using boost::lexical_cast;
 
  528  using boost::bad_lexical_cast;
 
  529  using boost::algorithm::equals;
 
  530  using boost::algorithm::is_iequal;
 
  535  using Traits = std::char_traits<char>;
 
  536  using enum_t = std::underlying_type_t<Enum>;
 
  540  assert(enum_t(enum_lowest) >= 0); 
 
  542  const is_iequal i_equal_func(locale::classic());
 
  547  while (((ch = is.peek()) != Traits::eof()) && (isalnum(ch) || (ch == 
'_')))
 
  553  Enum val = enum_default;
 
  557    if (accept_num_encoding && isdigit(token.front())) 
 
  562        num_enum = lexical_cast<enum_t>(token);
 
  564        if ((num_enum >= enum_t(enum_sentinel) || (num_enum < enum_t(enum_lowest))))
 
  566          num_enum = enum_t(enum_default);
 
  568        val = Enum(num_enum);
 
  570      catch (
const bad_lexical_cast& exc)
 
  572        assert(val == enum_default);
 
  579      for (idx = enum_t(enum_lowest); idx != enum_t(enum_sentinel); ++idx)
 
  581        const auto candidate = Enum(idx);
 
  585        if (case_sensitive ? equals(token, lexical_cast<string>(candidate))
 
  586                           : equals(token, lexical_cast<string>(candidate), i_equal_func))
 
  592      assert((idx != enum_t(enum_sentinel)) || (val == enum_default));
 
An empty interface, consisting of nothing but a default virtual destructor, intended as a boiler-plat...
virtual ~Null_interface()=0
Boring virtual destructor.
A simple RAII-pattern class template that, at construction, sets the specified location in memory to ...
~Scoped_setter()
Restores *target (from main ctor) to its value at entry to said ctor; or does nothing if *this has be...
Value m_saved_value
If and only if m_target_or_null is non-null, this saves *m_target_or_null. Otherwise meaningless.
Scoped_setter(const Scoped_setter &)=delete
Prohibit copying: for each explicit ctor invocation, there shall be exactly 1 non-no-op dtor invocati...
Scoped_setter & operator=(const Scoped_setter &)=delete
Prohibit copying (see deleted copy ctor).
Value * m_target_or_null
Target object location; see ctors; if null then this is a moved-from Scoped_setter that intentionally...
Scoped_setter(Value *target, Value &&val_src_moved)
Post-condition: *target contains was val_src_moved contained at ctor entry; and the destructor invoca...
Scoped_setter & operator=(Scoped_setter &&)=delete
Prohibit modifying existing *this; except that moving-from is enabled via the move ctor.
Similar to ostringstream but allows fast read-only access directly into the std::string being written...
std::ostream & os()
Access to stream that will write to owned string.
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
bool in_closed_open_range(T const &min_val, T const &val, T const &max_val)
Returns true if and only if the given value is within the given range, given as a [low,...
bool key_exists(const Container &container, const typename Container::key_type &key)
Returns true if and only if the given key is present at least once in the given associative container...
Auto_cleanup setup_auto_cleanup(const Cleanup_func &func)
Provides a way to execute arbitrary (cleanup) code at the exit of the current block.
void sequence_to_inverted_lookup_map(Sequence const &src_seq, Map *target_map, const Function< typename Map::mapped_type(size_t)> &idx_to_map_val_func)
Similar to the 2-arg overload of sequence_to_inverted_lookup_map() but with the ability to store a va...
double to_mbit_per_sec(N_items items_per_time, size_t bits_per_item)
Utility that converts a bandwidth in arbitrary units in both numerator and denominator to the same ba...
std::string buffers_dump_string(const Const_buffer_sequence &data, const std::string &indentation, size_t bytes_per_line)
Identical to buffers_to_ostream() but returns an std::string instead of writing to a given ostream.
Enum istream_to_enum(std::istream *is_ptr, Enum enum_default, Enum enum_sentinel, bool accept_num_encoding, bool case_sensitive, Enum enum_lowest)
Deserializes an enum class value from a standard input stream.
bool subtract_with_floor(Minuend *minuend, const Subtrahend &subtrahend, const Minuend &floor)
Performs *minuend -= subtrahend, subject to a floor of floor.
size_t size_unit_convert(From num_froms)
Answers the question what's the smallest integer number of Tos sufficient to verbatim store the given...
std::string ostream_op_string(T const &... ostream_args)
Equivalent to ostream_op_to_string() but returns a new string by value instead of writing to the call...
Integer ceil_div(Integer dividend, Integer divisor)
Returns the result of the given non-negative integer divided by a positive integer,...
bool in_open_open_range(T const &min_val, T const &val, T const &max_val)
Returns true if and only if the given value is within the given range, given as a (low,...
bool in_open_closed_range(T const &min_val, T const &val, T const &max_val)
Returns true if and only if the given value is within the given range, given as a (low,...
void ostream_op_to_string(std::string *target_str, T const &... ostream_args)
Writes to the specified string, as if the given arguments were each passed, via << in sequence,...
std::ostream & buffers_to_ostream(std::ostream &os, const Const_buffer_sequence &data, const std::string &indentation, size_t bytes_per_line)
Writes a multi- or single-line string representation of the provided binary data to an output stream,...
bool in_closed_range(T const &min_val, T const &val, T const &max_val)
Returns true if and only if the given value is within the given range, inclusive.
boost::shared_ptr< void > Auto_cleanup
Helper type for setup_auto_cleanup().
void feed_args_to_ostream(std::ostream *os, T1 const &ostream_arg1, T_rest const &... remaining_ostream_args)
"Induction step" version of variadic function template that simply outputs arguments 2+ via << to the...
Useful as a no-unique-address private member to make a type noncopyable while keeping that type an ag...
Noncopyable(const Noncopyable &)=delete
Forbid copying.
void operator=(const Noncopyable &)=delete
Forbid copying.
Noncopyable()=default
Makes it possible to instantiate.