Flow 3.0.0
Flow project: Public API.
Classes | Namespaces | Functions
util.hpp File Reference

Classes

class  flow::util::Null_interface
 An empty interface, consisting of nothing but a default virtual destructor, intended as a boiler-plate-reducing base for any other (presumably virtual-method-having) class that would otherwise require a default virtual destructor. More...
 
struct  flow::util::Noncopyable
 Useful as a no-unique-address private member to make a type noncopyable while keeping that type an aggregate (can be direct-initialized). More...
 
class  flow::util::Scoped_setter< Value_t >
 A simple RAII-pattern class template that, at construction, sets the specified location in memory to a specified value, memorizing the previous contents; and at destruction restores the value. More...
 
class  flow::util::Locked_proxy< Target_t, Mutex_t >
 A simple locking-proxy class template (execute-around-pointer idiom): at construction locks the given mutex and provides -> access to the given target object; at destruction unlocks it. More...
 

Namespaces

namespace  flow
 Catch-all namespace for the Flow project: A collection of various production-quality modules written in modern C++17, originally by ygoldfel.
 
namespace  flow::util
 Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module.
 

Functions

template<typename Time_unit , typename N_items >
double flow::util::to_mbit_per_sec (N_items items_per_time, size_t bits_per_item=8)
 Utility that converts a bandwidth in arbitrary units in both numerator and denominator to the same bandwidth in megabits per second. More...
 
template<typename Integer , typename Integer2 >
constexpr Integer flow::util::ceil_div (Integer dividend, Integer2 divisor)
 Returns the result of the given non-negative integer divided by a positive integer, rounded up to the nearest integer. More...
 
template<typename Integer , typename Integer2 >
constexpr Integer flow::util::round_to_multiple (Integer dividend, Integer2 unit)
 Returns the smallest integer >= the given integer dividend such that it is a multiple of the given integer unit. More...
 
template<uint64_t POSITIVE_INT>
constexpr bool flow::util::is_power_of_two ()
 Compile-time check: true if and only if the given positive integer is a power of two: 1, 2, 4, 8, .... More...
 
constexpr size_t flow::util::max_align_sz ()
 Compile-time value: the most stringent alignment in the target architecture. More...
 
template<typename Data , size_t ALIGN_SZ>
constexpr size_t flow::util::aligned_sz_of ()
 Compile-time calculation: Given a type Data returns the minimum size, in bytes, of a hypothetical buffer that is able to store 1 Data and has the specified alignment. More...
 
template<typename Prefix , typename Data , size_t ALIGN_SZ>
Prefix * flow::util::aligned_prefix_before (Data *data_ptr)
 Given a pointer to an aligned area, returns the pointer to a prefix area that is equally aligned, able to store a value of the specified type (size), and otherwise minimally sized. More...
 
template<typename Prefix , typename Data , size_t ALIGN_SZ>
const Prefix * flow::util::aligned_prefix_before (const Data *data_ptr)
 Identical to the other aligned_prefix_before() overload but works with immutable memory. More...
 
template<typename Data , typename Prefix , size_t ALIGN_SZ>
Data * flow::util::after_aligned_prefix (Prefix *prefix_ptr)
 The reverse of aligned_prefix_before(): given a prefix pointer, returns the base area following it. More...
 
template<typename Data , typename Prefix , size_t ALIGN_SZ>
const Data * flow::util::after_aligned_prefix (const Prefix *prefix_ptr)
 Identical to the other after_aligned_prefix() overload but works with immutable memory. More...
 
template<typename T >
bool flow::util::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. More...
 
template<typename T >
bool flow::util::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, high] pair. More...
 
template<typename T >
bool flow::util::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, high) pair. More...
 
template<typename T >
bool flow::util::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, high) pair. More...
 
template<typename Container >
bool flow::util::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. More...
 
template<typename Cleanup_func >
Auto_cleanup flow::util::setup_auto_cleanup (Cleanup_func &&func)
 Provides a way to execute arbitrary (cleanup) code at the exit of the current block. More...
 
template<typename Minuend , typename Subtrahend >
bool flow::util::subtract_with_floor (Minuend *minuend, const Subtrahend &subtrahend, const Minuend &floor=0)
 Performs *minuend -= subtrahend, subject to a floor of floor. More...
 
template<typename From , typename To >
size_t flow::util::size_unit_convert (From num_froms)
 Answers the question what's the smallest integer number of Tos sufficient to verbatim store the given number of Froms?, where From and To are POD types. More...
 
template<typename... T>
void flow::util::feed_args_to_ostream (std::ostream *os, T &&... ostream_args)
 Function template that simply outputs arguments 2+ via << to the given ostream, in the order given. More...
 
template<typename... T>
void flow::util::ostream_op_to_string (std::string *target_str, T &&... ostream_args)
 Writes to the specified string, as if the given arguments were each passed, via << in sequence, to an ostringstream, and then the result were appended to the aforementioned string variable. More...
 
template<typename... T>
std::string flow::util::ostream_op_string (T &&... ostream_args)
 Equivalent to ostream_op_to_string() but returns a new string by value instead of writing to the caller's string. More...
 
template<typename Map , typename Sequence >
void flow::util::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 value based on the index into the input sequence instead of that index itself. More...
 
template<typename Map , typename Sequence >
void flow::util::sequence_to_inverted_lookup_map (Sequence const &src_seq, Map *target_map)
 Given a generic sequence (integer -> object) generates a generic map (object -> integer) providing inverse lookup. More...
 
template<typename Const_buffer_sequence >
std::ostream & flow::util::buffers_to_ostream (std::ostream &os, const Const_buffer_sequence &data, const std::string &indentation, size_t bytes_per_line=0)
 Writes a multi- or single-line string representation of the provided binary data to an output stream, complete with a printable and hex versions of each byte. More...
 
template<typename Const_buffer_sequence >
std::string flow::util::buffers_dump_string (const Const_buffer_sequence &data, const std::string &indentation, size_t bytes_per_line=0)
 Identical to buffers_to_ostream() but returns an std::string instead of writing to a given ostream. More...
 
template<typename Enum >
Enum flow::util::istream_to_enum (std::istream *is_ptr, Enum enum_default, Enum enum_sentinel, bool accept_num_encoding=true, bool case_sensitive=false, Enum enum_lowest=Enum(0))
 Deserializes an enum class value from a standard input stream. More...
 
template<typename T , typename... Ctor_args>
T * flow::util::construct_at (T *obj, Ctor_args &&... ctor_args)
 std::construct_at() equivalent; unavailable until C++20, so here it is. More...
 
template<typename T >
T * flow::util::default_init_at (T *obj)
 Superficially similar to construct_at(), this default-initializes the T at the given location; this can be useful to avoid object-lifetime formality pitfalls. More...