1 #ifndef _MADARA_UTILITY_H_ 2 #define _MADARA_UTILITY_H_ 6 #include "ace/SOCK_Dgram.h" 7 #include "ace/High_Res_Timer.h" 8 #include "madara/MADARA_export.h" 54 bool replace_all =
true);
168 const ::std::vector< std::string> & splitters,
169 ::std::vector< std::string> & tokens,
170 ::std::vector< std::string> & pivot_list);
182 bool increase_until_bound =
true);
238 MADARA_Export uint64_t
endian_swap (uint64_t value);
254 MADARA_Export uint32_t
endian_swap (uint32_t value);
270 MADARA_Export uint16_t
endian_swap (uint16_t value);
298 void *& buffer,
size_t & size,
bool add_zero_char =
false);
308 void * buffer,
size_t size);
314 MADARA_Export int64_t
get_time (
void);
323 MADARA_Export
double rand_double (
double floor = 0.0,
324 double ceiling = 1.0,
bool set_seed_to_time =
true);
333 MADARA_Export int64_t
rand_int (int64_t floor = 0,
334 int64_t ceiling = RAND_MAX,
bool set_seed_to_time =
true);
366 MADARA_Export
double sleep (
double sleep_time);
373 MADARA_Export ACE_Time_Value
sleep (
const ACE_Time_Value & sleep_time);
387 double value1,
double value2,
double epsilon = 0.0001);
431 template <
typename T>
437 template <
typename T>
447 template <
typename T>
448 void sift_down (T * input,
int start,
int end,
449 bool (*comparator) (
const T & left,
const T & right) =
458 template <
typename T>
459 void heapify (T * input,
int size,
460 bool (*comparator) (
const T & left,
const T & right) =
469 template <
typename T>
471 bool (*comparator) (
const T & left,
const T & right) =
480 template <
typename T>
489 template <
typename T>
498 template <
typename T>
506 #endif // _MADARA_UTILITY_H_
MADARA_Export 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.
MADARA_Export 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.
MADARA_Export 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.
bool bitmask_check(T mask, T values)
Returns true if mask contains values.
MADARA_Export int bind_to_ephemeral_port(ACE_SOCK_Dgram &socket, std::string &host, unsigned short &port, bool increase_until_bound=true)
Binds to an ephemeral port.
MADARA_Export std::string get_version(void)
Gets the MADARA version number.
MADARA_Export 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.
MADARA_Export int64_t get_time(void)
Returns a time of day in nanoseconds.
T bitmask_add(T mask, T values)
Adds values to a bit mask.
MADARA_Export std::string strip_prefix(const std::string &input, const std::string &prefix)
Strips a prefix from an input string and returns the result.
MADARA_Export unsigned int file_size(const std::string &filename)
Returns the size of a file.
MADARA_Export 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.
MADARA_Export ACE_Time_Value sleep(const ACE_Time_Value &sleep_time)
Sleeps for a certain amount of time.
MADARA_Export 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.
MADARA_Export uint32_t get_uint_version(void)
Gets the MADARA version number.
MADARA_Export 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.
MADARA_Export int64_t nearest_int(double input)
Rounds a double to the nearest integer.
MADARA_Export 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.
MADARA_Export std::string extract_path(const std::string &name)
Extracts the path of a filename.
MADARA_Export 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.
MADARA_Export ssize_t write_file(const std::string &filename, void *buffer, size_t size)
Writes a file with provided contents.
This class provides a distributed knowledge base to users.
MADARA_Export std::string & dds_topicify(std::string &input)
Changes periods to underscores in compliance with OpenSplice needs.
MADARA_Export std::string & strip_white_space(std::string &input)
Strips all whitespace characters from a string.
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.
MADARA_Export double endian_swap(double value)
Converts a host format double precision into big endian.
MADARA_Export std::string & strip_extra_white_space(std::string &input)
Strips whitespace from front and end of string and also condenses multiple whitespace into a single s...
T bitmask_remove(T mask, T values)
Removes values from a bit mask.
MADARA_Export std::string to_string_version(uint32_t version)
Converts a MADARA uint32_t version number to human-readable.
MADARA_Export std::string & string_remove(std::string &input, char unwanted)
Strips an unwanted character.
Provides utility functions and classes for common tasks and needs.
MADARA_Export std::string expand_envs(const std::string &source)
Expands environment variables referenced in the string.
Provides functions and classes for the distributed knowledge base.
MADARA_Export std::string file_to_string(const std::string &filename)
Reads a file into a string.
MADARA_Export 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.
MADARA_Export 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.
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.
MADARA_Export std::string extract_filename(const std::string &name)
Extracts the file name of an absolute or relative path.
Encapsulates settings for a wait statement.
MADARA_Export void tokenizer(const std::string &input, const ::std::vector< std::string > &splitters,::std::vector< std::string > &tokens,::std::vector< std::string > &pivot_list)
Splits an input string into tokens.
MADARA_Export 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)
Helper function for madara::utility::expand_envs which retrieves an environment variable.
MADARA_Export bool ends_with(const std::string &input, const std::string &ending)
Check if input contains a pattern at the end.
MADARA_Export std::string & strip_comments(std::string &input)
Strips all comments (single-line and multi-line).
MADARA_Export std::string clean_dir_name(const std::string &target)
Substitutes the appropriate directory delimiter, which may help with portability between operating sy...