MADARA
3.2.3
|
Provides utility functions and classes for common tasks and needs. More...
Namespaces | |
java | |
Provides utility functions and classes for common Java tasks and needs. | |
Classes | |
class | EpochEnforcer |
Enforces a periodic epoch. More... | |
class | LQueue |
Defines a generic "first-in/first-out" (FIFO) Abstract Data Type (ADT) using a circular linked list. More... | |
class | LQueueConstIterator |
Implements a forward iterator for LQueue type classes. More... | |
class | LQueueIterator |
Implements a forward iterator for LQueue type classes. More... | |
class | LQueueNode |
Defines a node in the LQueue that's implemented as a circular linked list. More... | |
class | LStack |
Defines a generic "last-in/first-out" (LIFO) Abstract Data Type (ADT) using a stack that's implemented as a linked list. More... | |
class | LStackConstIterator |
Implements a forward iterator for LStack type classes. More... | |
class | LStackIterator |
Implements a forward iterator for LStack type classes. More... | |
class | LStackNode |
Defines a node in the LStack that's implemented as a linked list. More... | |
class | Refcounter |
This template class provides transparent reference counting of its template parameter T. More... | |
class | ScopedArray |
This template class provides transparent reference counting of its template parameter T. More... | |
class | ThreadSafeVector |
Manages a thread safe STL vector. More... | |
class | Timer |
Manages a timer for duration testing. More... | |
Typedefs | |
typedef std::chrono::steady_clock | Clock |
default clock type More... | |
typedef std::chrono::nanoseconds | Duration |
default clock duration More... | |
typedef std::chrono::duration< double > | SecondsDuration |
default clock duration More... | |
typedef std::chrono::time_point< Clock > | TimeValue |
time point More... | |
Functions | |
TimeValue | add_seconds (const TimeValue &start, double seconds) |
Returns an offset of a time by seconds in double format. More... | |
bool | approx_equal (double value1, double value2, double epsilon=0.0001) |
Checks two doubles for approximate equality. More... | |
MADARA_EXPORT bool | begins_with (const std::string &input, const std::string &prefix) |
Check if input contains prefix at the beginning. More... | |
template<typename T > | |
T | bitmask_add (T mask, T values) |
Adds values to a bit mask. More... | |
template<typename T > | |
bool | bitmask_check (T mask, T values) |
Returns true if mask contains values. More... | |
template<typename T > | |
T | bitmask_remove (T mask, T values) |
Removes values from a bit mask. More... | |
std::string | clean_dir_name (const std::string &target) |
Substitutes the appropriate directory delimiter, which may help with portability between operating systems. More... | |
std::string & | dds_topicify (std::string &input) |
Changes periods to underscores in compliance with OpenSplice needs. More... | |
bool | endian_is_little () |
uint64_t | endian_swap (uint64_t value) |
Converts a host format uint64_t into big endian. More... | |
int64_t | endian_swap (int64_t value) |
Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian. More... | |
uint32_t | endian_swap (uint32_t value) |
Converts a host format uint64_t into big endian. More... | |
int32_t | endian_swap (int32_t value) |
Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian. More... | |
uint16_t | endian_swap (uint16_t value) |
Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian. More... | |
int16_t | endian_swap (int16_t value) |
Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian. More... | |
double | endian_swap (double value) |
Converts a host format double precision into big endian. More... | |
MADARA_EXPORT bool | ends_with (const std::string &input, const std::string &ending) |
Check if input contains a pattern at the end. More... | |
std::string | expand_envs (const std::string &source) |
Expand any environment variables in a string. More... | |
std::string | extract_filename (const std::string &name) |
Extracts the file name of an absolute or relative path. More... | |
std::string | extract_path (const std::string &name) |
Extracts the path of a filename. More... | |
bool | file_exists (const std::string &filename) |
Checks if a file exists. More... | |
unsigned int | file_size (const std::string &filename) |
Returns the size of a file. More... | |
std::string | file_to_string (const std::string &filename) |
Reads a file into a string. More... | |
int64_t | get_time (void) |
Returns a time of day in nanoseconds If simtime feature is enabled, this may be simulation time instead of real rtime. More... | |
TimeValue | get_time_value (void) |
Returns a time of day as a chrono time value If simtime feature is enabled, this may be simulation time instead of real rtime. More... | |
uint32_t | get_uint_version (void) |
Gets the MADARA version number. More... | |
char * | get_var (const std::string &source, size_t cur, size_t &end) |
grab an environment variable value ( More... | |
std::string | get_version (void) |
Gets the MADARA version number. More... | |
template<typename T > | |
bool | greater_compare (const T &left, const T &right) |
Returns true if right < left. More... | |
template<typename T > | |
void | heap_sort (T *input, int size, bool(*comparator)(const T &left, const T &right)=greater_compare< T >) |
Sorts an array with heap sort. More... | |
template<typename T > | |
void | heapify (T *input, int size, bool(*comparator)(const T &left, const T &right)=greater_compare< T >) |
Builds a heap out of an array of elements. More... | |
template<typename T > | |
bool | less_compare (const T &left, const T &right) |
Returns true if left < right. More... | |
std::string & | lower (std::string &input) |
Converts the string to lower. More... | |
int | merge_hostport_identifier (std::string &key, const std::string &host, const std::string &port) |
Merges a host and port into a host:port key. More... | |
int | merge_hostport_identifier (std::string &key, const std::string &host, unsigned short u_port) |
Merges a host and port into a host:port key. More... | |
int64_t | nearest_int (double input) |
Rounds a double to the nearest integer. More... | |
std::pair< std::string, uint16_t > | parse_address (std::string addr) |
double | rand_double (double floor=0.0, double ceiling=1.0, bool set_seed_to_time=true) |
Returns a random double between floor and ceiling. More... | |
int64_t | rand_int (int64_t floor=0, int64_t ceiling=RAND_MAX, bool set_seed_to_time=true) |
Returns a random integer between a floor and ceiling. More... | |
int | read_file (const std::string &filename, void *&buffer, size_t &size, bool add_zero_char=false) |
Reads a file into a provided void pointer. More... | |
Duration | seconds_to_duration (double seconds) |
Returns seconds in double format as nanosecond duration. More... | |
SecondsDuration | seconds_to_seconds_duration (double seconds) |
Returns seconds in double format as seconds duration. More... | |
TimeValue | seconds_to_time (double seconds) |
Returns seconds in double format as nanosecond since epoch. More... | |
MADARA_EXPORT bool | set_thread_priority (int priority=20) |
Sets the thread priority in a FIFO scheme. More... | |
template<typename T > | |
void | sift_down (T *input, int start, int end, bool(*comparator)(const T &left, const T &right)=greater_compare< T >) |
Sifts elements down a heap according to a comparator. More... | |
double | sleep (double sleep_time) |
Sleeps for a certain amount of time. More... | |
SecondsDuration | sleep (const SecondsDuration &sleep_time) |
Sleeps for a certain amount of time. More... | |
int | split_hostport_identifier (const std::string &key, std::string &host, std::string &port) |
Splits a key of host:port into a corresponding host and port. More... | |
std::string & | string_remove (std::string &input, char unwanted) |
Strips an unwanted character. More... | |
size_t | string_replace (std::string &source, const std::string &old_phrase, const std::string &new_phrase, bool replace_all=true) |
Replaces an old phrase with a new phrase within a string. More... | |
std::string & | strip_comments (std::string &input) |
Strips all comments (single-line and multi-line). More... | |
std::string & | strip_extra_white_space (std::string &input) |
Strip whitespace from front and end of string and also condense multiple whitespace into a single space. More... | |
std::string | strip_prefix (const std::string &input, const std::string &prefix) |
Strips a prefix from an input string and returns the result. More... | |
std::string & | strip_white_space (std::string &input) |
Strip all whitespace. More... | |
std::string | to_string_version (uint32_t version) |
Converts a MADARA uint32_t version number to human-readable. More... | |
void | tokenizer (const std::string &input, const ::std::vector< std::string > &splitters,::std::vector< std::string > &tokens,::std::vector< std::string > &pivots) |
Split a string into tokens. More... | |
std::string & | upper (std::string &input) |
Converts the string to upper. More... | |
bool | wait_false (knowledge::KnowledgeBase &knowledge, const std::string &variable, const knowledge::WaitSettings &settings=knowledge::WaitSettings()) |
Waits on a knowledge record to be false without needing KaRL language. More... | |
bool | wait_true (knowledge::KnowledgeBase &knowledge, const std::string &variable, const knowledge::WaitSettings &settings=knowledge::WaitSettings()) |
Waits on a knowledge record to be true without needing KaRL language. More... | |
ssize_t | write_file (const std::string &filename, void *buffer, size_t size) |
Writes a file with provided contents. More... | |
Variables | |
static const uint64_t | micro_per = milli_per * 1000 |
static const uint64_t | milli_per = 1000 |
static const uint64_t | nano_per = micro_per * 1000 |
static const uint64_t | simtime_min_sleep = 100 * (nano_per / milli_per) |
Provides utility functions and classes for common tasks and needs.
typedef std::chrono::steady_clock madara::utility::Clock |
typedef std::chrono::nanoseconds madara::utility::Duration |
typedef std::chrono::duration<double> madara::utility::SecondsDuration |
typedef std::chrono::time_point<Clock> madara::utility::TimeValue |
Returns an offset of a time by seconds in double format.
Definition at line 261 of file Utility.inl.
|
inline |
Checks two doubles for approximate equality.
Doubles, unlike integers, are approximations of fractions. Consequently, two doubles cannot be checked for equality as easily and as portably as integers. To compare doubles for equality, use this function with an epsilon, which by default is accurate to the 10,000th (4 decimal places)
value1 | the first value to compare, order does not matter |
value2 | the second value to compare, order does not matter |
epsilon | the minimum difference between two values before equality does not hold. |
Definition at line 282 of file Utility.inl.
|
inline |
Check if input contains prefix at the beginning.
input | string to check for prefix |
prefix | string to match |
Definition at line 317 of file Utility.inl.
T madara::utility::bitmask_add | ( | T | mask, |
T | values | ||
) |
Adds values to a bit mask.
mask | the target bit mask |
values | values to bitwise add to mask |
Definition at line 347 of file Utility.inl.
bool madara::utility::bitmask_check | ( | T | mask, |
T | values | ||
) |
Returns true if mask contains values.
mask | the bit mask to check |
values | values to check for inclusion in mask |
Definition at line 356 of file Utility.inl.
T madara::utility::bitmask_remove | ( | T | mask, |
T | values | ||
) |
Removes values from a bit mask.
mask | the target bit mask |
values | values to bitwise remove from mask |
Definition at line 365 of file Utility.inl.
MADARA_EXPORT std::string madara::utility::clean_dir_name | ( | const std::string & | target | ) |
Substitutes the appropriate directory delimiter, which may help with portability between operating systems.
target | the string to modify |
Definition at line 457 of file Utility.cpp.
|
inline |
Changes periods to underscores in compliance with OpenSplice needs.
Convert string to lowercase.
This function will modify and return the input, so make a copy if needed.
input | the string to change |
Definition at line 72 of file Utility.inl.
|
inline |
Definition at line 97 of file Utility.inl.
|
inline |
Converts a host format uint64_t into big endian.
Can also be used to convert back into host form.
value | the value to convert |
Definition at line 115 of file Utility.inl.
|
inline |
Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian.
Converts a host format signed knowledge::KnowledgeRecord::Integer into big endian.
Can also be used to convert back into host form.
value | the value to convert |
Definition at line 134 of file Utility.inl.
|
inline |
Converts a host format uint64_t into big endian.
Can also be used to convert back into host form.
value | the value to convert |
Definition at line 154 of file Utility.inl.
|
inline |
Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian.
Converts a host format signed knowledge::KnowledgeRecord::Integer into big endian.
Can also be used to convert back into host form.
value | the value to convert |
Definition at line 171 of file Utility.inl.
|
inline |
Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian.
Converts a host format signed knowledge::KnowledgeRecord::Integer into big endian.
Can also be used to convert back into host form.
value | the value to convert |
Definition at line 188 of file Utility.inl.
|
inline |
Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian.
Converts a host format signed knowledge::KnowledgeRecord::Integer into big endian.
Can also be used to convert back into host form.
value | the value to convert |
Definition at line 203 of file Utility.inl.
|
inline |
Converts a host format double precision into big endian.
Converts a host format double into big endian.
Can also be used to convert back into host form.
value | the value to convert |
Definition at line 218 of file Utility.inl.
|
inline |
Check if input contains a pattern at the end.
input | string to check for prefix |
ending | string to match |
Definition at line 331 of file Utility.inl.
MADARA_EXPORT std::string madara::utility::expand_envs | ( | const std::string & | source | ) |
Expand any environment variables in a string.
Expands environment variables referenced in the string.
The environment variables must be specified as and not $var.
source | the string to expand |
Definition at line 421 of file Utility.cpp.
MADARA_EXPORT std::string madara::utility::extract_filename | ( | const std::string & | name | ) |
Extracts the file name of an absolute or relative path.
name | name of the file to extract path of |
Definition at line 400 of file Utility.cpp.
MADARA_EXPORT std::string madara::utility::extract_path | ( | const std::string & | name | ) |
Extracts the path of a filename.
name | name of the file to extract path of |
Definition at line 380 of file Utility.cpp.
|
inline |
Checks if a file exists.
filename | path and name of the file to open |
Definition at line 289 of file Utility.inl.
|
inline |
Returns the size of a file.
filename | path and name of the file to open |
Definition at line 303 of file Utility.inl.
MADARA_EXPORT std::string madara::utility::file_to_string | ( | const std::string & | filename | ) |
Reads a file into a string.
filename | name of the file to read |
Definition at line 347 of file Utility.cpp.
|
inline |
Returns a time of day in nanoseconds If simtime feature is enabled, this may be simulation time instead of real rtime.
Definition at line 253 of file Utility.inl.
|
inline |
Returns a time of day as a chrono time value If simtime feature is enabled, this may be simulation time instead of real rtime.
Definition at line 243 of file Utility.inl.
MADARA_EXPORT uint32_t madara::utility::get_uint_version | ( | void | ) |
Gets the MADARA version number.
Definition at line 32 of file Utility.cpp.
char * madara::utility::get_var | ( | const std::string & | source, |
size_t | cur, | ||
size_t & | end | ||
) |
grab an environment variable value (
Helper function for madara::utility::expand_envs which retrieves an environment variable.
source | the string to expand |
cur | the current focus position of expand_vars |
end | the end of the variable |
Definition at line 442 of file Utility.cpp.
MADARA_EXPORT std::string madara::utility::get_version | ( | void | ) |
Gets the MADARA version number.
Definition at line 22 of file Utility.cpp.
bool madara::utility::greater_compare | ( | const T & | left, |
const T & | right | ||
) |
Returns true if right < left.
Definition at line 380 of file Utility.inl.
void madara::utility::heap_sort | ( | T * | input, |
int | size, | ||
bool(*)(const T &left, const T &right) | comparator = greater_compare<T> |
||
) |
Sorts an array with heap sort.
input | the array to heapify |
size | the size of the array |
comparator | a function for comparing two elements |
Definition at line 428 of file Utility.inl.
void madara::utility::heapify | ( | T * | input, |
int | size, | ||
bool(*)(const T &left, const T &right) | comparator = greater_compare<T> |
||
) |
Builds a heap out of an array of elements.
input | the array to heapify |
size | the size of the array |
comparator | a function for comparing two elements |
Definition at line 416 of file Utility.inl.
bool madara::utility::less_compare | ( | const T & | left, |
const T & | right | ||
) |
Returns true if left < right.
Definition at line 373 of file Utility.inl.
|
inline |
Converts the string to lower.
Convert string to lowercase.
This function will modify and return the input, so make a copy if needed.
input | the string to change |
Definition at line 87 of file Utility.inl.
MADARA_EXPORT int madara::utility::merge_hostport_identifier | ( | std::string & | key, |
const std::string & | host, | ||
const std::string & | port | ||
) |
Merges a host and port into a host:port key.
key | a string containing a host:port |
host | the host in the key |
port | the port in the key |
Definition at line 323 of file Utility.cpp.
MADARA_EXPORT int madara::utility::merge_hostport_identifier | ( | std::string & | key, |
const std::string & | host, | ||
unsigned short | u_port | ||
) |
Merges a host and port into a host:port key.
key | a string containing a host:port |
host | the host in the key |
u_port | the port in the key |
Definition at line 337 of file Utility.cpp.
MADARA_EXPORT int64_t madara::utility::nearest_int | ( | double | input | ) |
Rounds a double to the nearest integer.
input | real number to round to integer |
Definition at line 606 of file Utility.cpp.
std::pair< std::string, uint16_t > madara::utility::parse_address | ( | std::string | addr | ) |
Definition at line 789 of file Utility.cpp.
MADARA_EXPORT double madara::utility::rand_double | ( | double | floor = 0.0 , |
double | ceiling = 1.0 , |
||
bool | set_seed_to_time = true |
||
) |
Returns a random double between floor and ceiling.
floor | lowest possible double |
ceiling | highest possible double |
set_seed_to_time | if true, seed the random generator with time |
Definition at line 580 of file Utility.cpp.
MADARA_EXPORT int64_t madara::utility::rand_int | ( | int64_t | floor = 0 , |
int64_t | ceiling = RAND_MAX , |
||
bool | set_seed_to_time = true |
||
) |
Returns a random integer between a floor and ceiling.
floor | lowest possible integer |
ceiling | highest possible integer |
set_seed_to_time | if true, seed the random generator with time |
Definition at line 598 of file Utility.cpp.
MADARA_EXPORT int madara::utility::read_file | ( | const std::string & | filename, |
void *& | buffer, | ||
size_t & | size, | ||
bool | add_zero_char = false |
||
) |
Reads a file into a provided void pointer.
The void pointer will point to an allocated buffer that the user will need to delete.
filename | the name of the file |
buffer | a buffer that contains the contents of the file |
size | the size of the allocated buffer (will change) |
add_zero_char | add a zero char to the end of the buffer |
Definition at line 480 of file Utility.cpp.
|
inline |
Returns seconds in double format as nanosecond duration.
Definition at line 266 of file Utility.inl.
|
inline |
Returns seconds in double format as seconds duration.
Definition at line 272 of file Utility.inl.
|
inline |
Returns seconds in double format as nanosecond since epoch.
Definition at line 277 of file Utility.inl.
|
inline |
Sets the thread priority in a FIFO scheme.
priority | the priority to attempt to set |
Definition at line 17 of file Utility.inl.
void madara::utility::sift_down | ( | T * | input, |
int | start, | ||
int | end, | ||
bool(*)(const T &left, const T &right) | comparator = greater_compare<T> |
||
) |
Sifts elements down a heap according to a comparator.
input | the array to heapify |
start | index to start from |
end | index that signifies end of range to sift |
comparator | a function for comparing two elements |
Definition at line 387 of file Utility.inl.
MADARA_EXPORT double madara::utility::sleep | ( | double | sleep_time | ) |
Sleeps for a certain amount of time.
Unlike other sleep timers this will sleep for the amount of time regardless of OS interrupts
sleep_time | time in seconds to sleep for |
Definition at line 619 of file Utility.cpp.
MADARA_EXPORT SecondsDuration madara::utility::sleep | ( | const SecondsDuration & | sleep_time | ) |
Sleeps for a certain amount of time.
Unlike other sleep timers this will sleep for the amount of time regardless of OS interrupts
sleep_time | time to sleep for |
Definition at line 627 of file Utility.cpp.
MADARA_EXPORT int madara::utility::split_hostport_identifier | ( | const std::string & | key, |
std::string & | host, | ||
std::string & | port | ||
) |
Splits a key of host:port into a corresponding host and port.
key | a string containing a host:port |
host | the host in the key |
port | the port in the key |
Definition at line 298 of file Utility.cpp.
MADARA_EXPORT std::string & madara::utility::string_remove | ( | std::string & | input, |
char | unwanted | ||
) |
Strips an unwanted character.
This function will modify and return the input, so make a copy if needed.
This function will modify and return the input, so make a copy if needed.
input | the string to change |
unwanted | the character value to remove from input |
Definition at line 160 of file Utility.cpp.
MADARA_EXPORT size_t madara::utility::string_replace | ( | std::string & | source, |
const std::string & | old_phrase, | ||
const std::string & | new_phrase, | ||
bool | replace_all = true |
||
) |
Replaces an old phrase with a new phrase within a string.
source | source string to change |
old_phrase | old phrase in the source string to replace |
new_phrase | new phrase to replace the old phrase |
replace_all | if true, replace all instances of old phrase. if false, replace first instance of old phrase. |
Definition at line 183 of file Utility.cpp.
MADARA_EXPORT std::string & madara::utility::strip_comments | ( | std::string & | input | ) |
Strips all comments (single-line and multi-line).
This function will modify and return the input, so make a copy if needed.
input | the string to change |
Definition at line 210 of file Utility.cpp.
MADARA_EXPORT std::string & madara::utility::strip_extra_white_space | ( | std::string & | input | ) |
Strip whitespace from front and end of string and also condense multiple whitespace into a single space.
Strips whitespace from front and end of string and also condenses multiple whitespace into a single space.
This function will modify and return the input, so make a copy if needed.
input | the string to change |
Definition at line 90 of file Utility.cpp.
|
inline |
Strips a prefix from an input string and returns the result.
Convert string to uppercase.
The prefix should be at the front of the input. This does not perform checks for speed reasons.
input | the string to change |
prefix | the start of the string |
Definition at line 52 of file Utility.inl.
std::string & madara::utility::strip_white_space | ( | std::string & | input | ) |
Strip all whitespace.
Strips all whitespace characters from a string.
This function will modify and return the input, so make a copy if needed.
input | the string to change |
Definition at line 132 of file Utility.cpp.
MADARA_EXPORT std::string madara::utility::to_string_version | ( | uint32_t | version | ) |
Converts a MADARA uint32_t version number to human-readable.
version | the 4 byte version number |
Definition at line 68 of file Utility.cpp.
MADARA_EXPORT void madara::utility::tokenizer | ( | const std::string & | input, |
const ::std::vector< std::string > & | splitters, | ||
::std::vector< std::string > & | tokens, | ||
::std::vector< std::string > & | pivot_list | ||
) |
Split a string into tokens.
Splits an input string into tokens.
input | a string to be split by splitters |
splitters | a vector of strings to look for in input |
tokens | the sections in between splitters |
pivot_list | the actual splitters that were found between the tokens |
Definition at line 242 of file Utility.cpp.
|
inline |
Converts the string to upper.
Convert string to uppercase.
This function will modify and return the input, so make a copy if needed.
input | the string to change |
Definition at line 61 of file Utility.inl.
MADARA_EXPORT bool madara::utility::wait_false | ( | knowledge::KnowledgeBase & | knowledge, |
const std::string & | variable, | ||
const knowledge::WaitSettings & | settings = knowledge::WaitSettings() |
||
) |
Waits on a knowledge record to be false without needing KaRL language.
knowledge | the knowledge base |
variable | the variable to wait on |
settings | the Wait Settings. Only uses poll_frequency and max_wait. |
Definition at line 721 of file Utility.cpp.
MADARA_EXPORT bool madara::utility::wait_true | ( | knowledge::KnowledgeBase & | knowledge, |
const std::string & | variable, | ||
const knowledge::WaitSettings & | settings = knowledge::WaitSettings() |
||
) |
Waits on a knowledge record to be true without needing KaRL language.
knowledge | the knowledge base |
variable | the variable to wait on |
settings | the Wait Settings. Only uses poll_frequency and max_wait. |
Definition at line 653 of file Utility.cpp.
MADARA_EXPORT ssize_t madara::utility::write_file | ( | const std::string & | filename, |
void * | buffer, | ||
size_t | size | ||
) |
Writes a file with provided contents.
filename | the name of the file |
buffer | a buffer that contains the contents of the file |
size | the size of the allocated buffer |
Definition at line 547 of file Utility.cpp.
|
static |
Definition at line 237 of file Utility.inl.
|
static |
Definition at line 236 of file Utility.inl.
|
static |
Definition at line 238 of file Utility.inl.
Definition at line 240 of file Utility.inl.