utils.h file
Global utilities.
Functions
- auto fileToTag(const char* file) -> string
-
template<typename StrType>void log(const string& tag, StrType str)
-
template<typename StrType>void apnd(const string& tag, stringstream& ss, StrType str)
-
template<typename StrType, typename... StrTypes>void apnd(const string& tag, stringstream& ss, StrType str, StrTypes... msgs)
-
template<typename StrType, typename... StrTypes>void log(const string& tag, StrType str, StrTypes... msgs)
-
template<typename InputIt, typename SourceLen, typename T, size_t size>void copy_min_to_buffer(InputIt source, SourceLen source_length, T(&target)[size])
-
template<typename T, size_t size>void copy_min_to_buffer(string&& source, T(&target)[size])
-
template<typename FP, FP(*)(FP) rnd>auto to_string(FP fp, uint8_t precision = 2) -> std::string
- auto to_string(float fp, uint8_t precision = 2) -> std::string
- auto to_string(double fp, uint8_t precision = 2) -> std::string
Defines
Function documentation
string fileToTag(const char* file)
| Parameters | |
|---|---|
| file | a file path |
| Returns | the file's basename |
Converts a file path to its basename.
template<typename StrType>
void log(const string& tag,
StrType str)
| Template parameters | |
|---|---|
| StrType | type of string (C-style or C++ string) |
| Parameters | |
| tag | the tag for this message |
| str | the message to log |
Logs a message with the specified tag.
template<typename StrType>
void apnd(const string& tag,
stringstream& ss,
StrType str)
| Template parameters | |
|---|---|
| StrType | type of string (C-style or C++ string) |
| Parameters | |
| tag | the tag for this message |
| ss | the string stream to combine strings into |
| str | the message to log |
Logs a message with the specified tag.
template<typename StrType, typename... StrTypes>
void apnd(const string& tag,
stringstream& ss,
StrType str,
StrTypes... msgs)
| Template parameters | |
|---|---|
| StrType | type of string (C-style or C++ string) |
| StrTypes | type of any additional strings |
| Parameters | |
| tag | the tag for this message |
| ss | the string stream to combine strings into |
| str | the message to log |
| msgs | additional messages to log |
Logs all messages with the specified tag as a single message.
template<typename StrType, typename... StrTypes>
void log(const string& tag,
StrType str,
StrTypes... msgs)
| Template parameters | |
|---|---|
| StrType | type of string (C-style or C++ string) |
| StrTypes | type of any additional strings |
| Parameters | |
| tag | the tag for this message |
| str | the message to log |
| msgs | additional messages to log |
Logs all messages with the specified tag as a single message.
template<typename InputIt, typename SourceLen, typename T, size_t size>
void copy_min_to_buffer(InputIt source,
SourceLen source_length,
T(&target)[size])
| Template parameters | |
|---|---|
| InputIt | input iterator |
| SourceLen | the source length |
| T | output iterator |
| size | size of source |
| Parameters | |
| source | the source input |
| source_length | the source length |
| target | output |
Copies at min(SourceLen, size) bytes from source to target buffer.
template<typename T, size_t size>
void copy_min_to_buffer(string&& source,
T(&target)[size])
| Template parameters | |
|---|---|
| T | output type |
| size | size of bytes |
| Parameters | |
| source | input source |
| target | output |
Copies at min(SourceLen, size) bytes from source to target buffer.
template<typename FP, FP(*)(FP) rnd>
std::string to_string(FP fp,
uint8_t precision = 2)
| Template parameters | |
|---|---|
| FP | the type of floating point number |
| rnd | the rounding function |
| Parameters | |
| fp | the floating point number |
| precision | the number of decimal points |
| Returns | a string representation |
Helper to create a string representation of a floating point number with a certain number of decimal point precision.
std::string to_string(float fp, uint8_t precision = 2)
| Parameters | |
|---|---|
| fp | the number |
| precision | the decimal points |
| Returns | the string representation |
Helper to convert a float to a string with a certain number of decimal points.
std::string to_string(double fp, uint8_t precision = 2)
| Parameters | |
|---|---|
| fp | the number |
| precision | the decimal points |
| Returns | the string representation |
Helper to convert a double to a string with a certain number of decimal points.