1 #ifndef _MADARA_UTILITY_H_ 2 #define _MADARA_UTILITY_H_ 11 #include "madara/MadaraExport.h" 27 typedef std::chrono::steady_clock
Clock;
76 bool replace_all =
true);
190 const ::std::vector< std::string> & splitters,
191 ::std::vector< std::string> & tokens,
192 ::std::vector< std::string> & pivot_list);
308 void *& buffer,
size_t & size,
bool add_zero_char =
false);
318 void * buffer,
size_t size);
342 TimeValue
add_seconds (
const TimeValue & start,
double seconds);
369 MADARA_EXPORT
double rand_double (
double floor = 0.0,
370 double ceiling = 1.0,
bool set_seed_to_time =
true);
379 MADARA_EXPORT int64_t
rand_int (int64_t floor = 0,
380 int64_t ceiling = RAND_MAX,
bool set_seed_to_time =
true);
412 MADARA_EXPORT
double sleep (
double sleep_time);
419 MADARA_EXPORT SecondsDuration
sleep (
const SecondsDuration & sleep_time);
433 double value1,
double value2,
double epsilon = 0.0001);
477 template <
typename T>
483 template <
typename T>
493 template <
typename T>
494 void sift_down (T * input,
int start,
int end,
495 bool (*comparator) (
const T & left,
const T & right) =
504 template <
typename T>
505 void heapify (T * input,
int size,
506 bool (*comparator) (
const T & left,
const T & right) =
515 template <
typename T>
517 bool (*comparator) (
const T & left,
const T & right) =
526 template <
typename T>
535 template <
typename T>
544 template <
typename T>
553 #endif // _MADARA_UTILITY_H_
std::string extract_filename(const std::string &name)
Extracts the file name of an absolute or relative path.
std::chrono::duration< double > SecondsDuration
default clock duration
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.
bool bitmask_check(T mask, T values)
Returns true if mask contains values.
TimeValue add_seconds(const TimeValue &start, double seconds)
Returns an offset of a time by seconds in double format.
std::pair< std::string, uint16_t > parse_address(std::string addr)
int read_file(const std::string &filename, void *&buffer, size_t &size, bool add_zero_char)
Reads a file into a provided void pointer.
std::string & strip_comments(std::string &input)
Strips all comments (single-line and multi-line).
int64_t get_time(void)
Returns a time of day in nanoseconds If simtime feature is enabled, this may be simulation time inste...
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 spa...
SecondsDuration seconds_to_seconds_duration(double seconds)
Returns seconds in double format as seconds duration.
MADARA_EXPORT bool set_thread_priority(int priority=20)
Sets the thread priority in a FIFO scheme.
T bitmask_add(T mask, T values)
Adds values to a bit mask.
bool wait_false(knowledge::KnowledgeBase &knowledge, const std::string &variable, const knowledge::WaitSettings &settings)
Waits on a knowledge record to be false without needing KaRL language.
std::string strip_prefix(const std::string &input, const std::string &prefix)
Strips a prefix from an input string and returns the result.
unsigned int file_size(const std::string &filename)
Returns the size of a file.
Duration seconds_to_duration(double seconds)
Returns seconds in double format as nanosecond duration.
std::string & lower(std::string &input)
Converts the string to lower.
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.
std::string extract_path(const std::string &name)
Extracts the path of a filename.
std::chrono::time_point< Clock > TimeValue
time point
std::chrono::steady_clock Clock
default clock type
std::string & upper(std::string &input)
Converts the string to upper.
bool greater_compare(const T &left, const T &right)
Returns true if right < left.
void heap_sort(T *input, int size, bool(*comparator)(const T &left, const T &right)=greater_compare< T >)
Sorts an array with heap sort.
double sleep(double sleep_time)
Sleeps for a certain amount of time.
TimeValue get_time_value(void)
Returns a time of day as a chrono time value If simtime feature is enabled, this may be simulation ti...
std::string to_string_version(uint32_t version)
Converts a MADARA uint32_t version number to human-readable.
This class provides a distributed knowledge base to users.
int64_t nearest_int(double input)
Rounds a double to the nearest integer.
std::string file_to_string(const std::string &filename)
Reads a file into a string.
std::string & dds_topicify(std::string &input)
Changes periods to underscores in compliance with OpenSplice needs.
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.
uint32_t get_uint_version(void)
Gets the MADARA version number.
bool wait_true(knowledge::KnowledgeBase &knowledge, const std::string &variable, const knowledge::WaitSettings &settings)
Waits on a knowledge record to be true without needing KaRL language.
std::string & strip_white_space(std::string &input)
Strip all whitespace.
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.
double endian_swap(double value)
Converts a host format double precision into big endian.
std::string clean_dir_name(const std::string &source)
Substitutes the appropriate directory delimiter, which may help with portability between operating sy...
TimeValue seconds_to_time(double seconds)
Returns seconds in double format as nanosecond since epoch.
T bitmask_remove(T mask, T values)
Removes values from a bit mask.
double rand_double(double floor, double ceiling, bool set_seed_to_time)
Returns a random double between floor and ceiling.
std::string expand_envs(const std::string &source)
Expand any environment variables in a string.
int64_t rand_int(int64_t floor, int64_t ceiling, bool set_seed_to_time)
Returns a random integer between a floor and ceiling.
Provides utility functions and classes for common tasks and needs.
Provides functions and classes for the distributed knowledge base.
bool file_exists(const std::string &filename)
Checks if a file exists.
bool less_compare(const T &left, const T &right)
Returns true if left < right.
std::string & string_remove(std::string &input, char unwanted)
Strips an unwanted character.
Copyright (c) 2015 Carnegie Mellon University.
MADARA_EXPORT bool begins_with(const std::string &input, const std::string &prefix)
Check if input contains prefix at the beginning.
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.
Encapsulates settings for a wait statement.
std::string get_version(void)
Gets the MADARA version number.
ssize_t write_file(const std::string &filename, void *buffer, size_t size)
Writes a file with provided contents.
bool approx_equal(double value1, double value2, double epsilon=0.0001)
Checks two doubles for approximate equality.
char * get_var(const std::string &source, size_t cur, size_t &end)
grab an environment variable value (
std::chrono::nanoseconds Duration
default clock duration
MADARA_EXPORT bool ends_with(const std::string &input, const std::string &ending)
Check if input contains a pattern at the end.
size_t string_replace(std::string &source, const std::string &old_phrase, const std::string &new_phrase, bool replace_all)
Replaces an old phrase with a new phrase within a string.