MADARA  3.2.3
Utility.h File Reference
#include <vector>
#include <string>
#include <cmath>
#include <limits.h>
#include <cstdlib>
#include <cstring>
#include <chrono>
#include "madara/MadaraExport.h"
#include "madara/utility/StdInt.h"
#include "madara/knowledge/WaitSettings.h"
#include "madara/utility/IntTypes.h"
#include "Utility.inl"

Go to the source code of this file.

Namespaces

 madara
 Copyright (c) 2015 Carnegie Mellon University.
 
 madara::knowledge
 Provides functions and classes for the distributed knowledge base.
 
 madara::utility
 Provides utility functions and classes for common tasks and needs.
 

Typedefs

typedef std::chrono::steady_clock madara::utility::Clock
 default clock type More...
 
typedef std::chrono::nanoseconds madara::utility::Duration
 default clock duration More...
 
typedef std::chrono::duration< double > madara::utility::SecondsDuration
 default clock duration More...
 
typedef std::chrono::time_point< Clock > madara::utility::TimeValue
 time point More...
 

Functions

TimeValue madara::utility::add_seconds (const TimeValue &start, double seconds)
 Returns an offset of a time by seconds in double format. More...
 
bool madara::utility::approx_equal (double value1, double value2, double epsilon=0.0001)
 Checks two doubles for approximate equality. More...
 
MADARA_EXPORT bool madara::utility::begins_with (const std::string &input, const std::string &prefix)
 Check if input contains prefix at the beginning. More...
 
template<typename T >
madara::utility::bitmask_add (T mask, T values)
 Adds values to a bit mask. More...
 
template<typename T >
bool madara::utility::bitmask_check (T mask, T values)
 Returns true if mask contains values. More...
 
template<typename T >
madara::utility::bitmask_remove (T mask, T values)
 Removes values from a bit mask. More...
 
std::string madara::utility::clean_dir_name (const std::string &target)
 Substitutes the appropriate directory delimiter, which may help with portability between operating systems. More...
 
std::string & madara::utility::dds_topicify (std::string &input)
 Changes periods to underscores in compliance with OpenSplice needs. More...
 
uint64_t madara::utility::endian_swap (uint64_t value)
 Converts a host format uint64_t into big endian. More...
 
int64_t madara::utility::endian_swap (int64_t value)
 Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian. More...
 
uint32_t madara::utility::endian_swap (uint32_t value)
 Converts a host format uint64_t into big endian. More...
 
int32_t madara::utility::endian_swap (int32_t value)
 Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian. More...
 
uint16_t madara::utility::endian_swap (uint16_t value)
 Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian. More...
 
int16_t madara::utility::endian_swap (int16_t value)
 Converts a host format signed madara::knowledge::KnowledgeRecord::Integer into big endian. More...
 
double madara::utility::endian_swap (double value)
 Converts a host format double precision into big endian. More...
 
MADARA_EXPORT bool madara::utility::ends_with (const std::string &input, const std::string &ending)
 Check if input contains a pattern at the end. More...
 
std::string madara::utility::expand_envs (const std::string &source)
 Expand any environment variables in a string. More...
 
std::string madara::utility::extract_filename (const std::string &name)
 Extracts the file name of an absolute or relative path. More...
 
std::string madara::utility::extract_path (const std::string &name)
 Extracts the path of a filename. More...
 
bool madara::utility::file_exists (const std::string &filename)
 Checks if a file exists. More...
 
unsigned int madara::utility::file_size (const std::string &filename)
 Returns the size of a file. More...
 
std::string madara::utility::file_to_string (const std::string &filename)
 Reads a file into a string. More...
 
int64_t madara::utility::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 madara::utility::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 madara::utility::get_uint_version (void)
 Gets the MADARA version number. More...
 
char * madara::utility::get_var (const std::string &source, size_t cur, size_t &end)
 grab an environment variable value ( More...
 
std::string madara::utility::get_version (void)
 Gets the MADARA version number. More...
 
template<typename T >
bool madara::utility::greater_compare (const T &left, const T &right)
 Returns true if right < left. More...
 
template<typename T >
void madara::utility::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 madara::utility::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 madara::utility::less_compare (const T &left, const T &right)
 Returns true if left < right. More...
 
std::string & madara::utility::lower (std::string &input)
 Converts the string to lower. More...
 
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. More...
 
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. More...
 
int64_t madara::utility::nearest_int (double input)
 Rounds a double to the nearest integer. More...
 
std::pair< std::string, uint16_t > madara::utility::parse_address (std::string addr)
 
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. More...
 
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. More...
 
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. More...
 
Duration madara::utility::seconds_to_duration (double seconds)
 Returns seconds in double format as nanosecond duration. More...
 
SecondsDuration madara::utility::seconds_to_seconds_duration (double seconds)
 Returns seconds in double format as seconds duration. More...
 
TimeValue madara::utility::seconds_to_time (double seconds)
 Returns seconds in double format as nanosecond since epoch. More...
 
MADARA_EXPORT bool madara::utility::set_thread_priority (int priority=20)
 Sets the thread priority in a FIFO scheme. More...
 
template<typename T >
void madara::utility::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 madara::utility::sleep (double sleep_time)
 Sleeps for a certain amount of time. More...
 
SecondsDuration madara::utility::sleep (const SecondsDuration &sleep_time)
 Sleeps for a certain amount of time. More...
 
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. More...
 
std::string & madara::utility::string_remove (std::string &input, char unwanted)
 Strips an unwanted character. More...
 
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. More...
 
std::string & madara::utility::strip_comments (std::string &input)
 Strips all comments (single-line and multi-line). More...
 
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. More...
 
std::string madara::utility::strip_prefix (const std::string &input, const std::string &prefix)
 Strips a prefix from an input string and returns the result. More...
 
std::string & madara::utility::strip_white_space (std::string &input)
 Strip all whitespace. More...
 
std::string madara::utility::to_string_version (uint32_t version)
 Converts a MADARA uint32_t version number to human-readable. More...
 
void madara::utility::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 & madara::utility::upper (std::string &input)
 Converts the string to upper. More...
 
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. More...
 
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. More...
 
ssize_t madara::utility::write_file (const std::string &filename, void *buffer, size_t size)
 Writes a file with provided contents. More...