MADARA  3.4.1
Utility.cpp
Go to the documentation of this file.
1 #include <ctype.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <ios>
5 #include <iostream>
6 #include <sstream>
7 #include <fstream>
8 #include <thread>
9 
11 #include "madara/utility/Utility.h"
13 
15 
16 #include "Utility.h"
17 #include "Timer.h"
18 
19 namespace madara
20 {
21 namespace utility
22 {
24 {
25 #include "madara/Version.h"
26 
27  return version + std::string(" compiled on ") + __DATE__ + " at " + __TIME__;
28 }
29 
30 uint32_t get_uint_version(const std::string& str_version)
31 {
32  unsigned char version_buffer[4] = {0, 0, 0, 0};
33  uint32_t* return_value = (uint32_t*)version_buffer;
34  unsigned int major, minor, revision;
35  char version_delimiter;
36 
37  std::stringstream buffer;
38 
39  // copy the stringified version
40  buffer << str_version;
41 
42  // major version
43  buffer >> major;
44 
45  buffer >> version_delimiter;
46 
47  // minor version
48  buffer >> minor;
49 
50  buffer >> version_delimiter;
51 
52  // revision number
53  buffer >> revision;
54 
55  // copy these into the version_buffer
56 
57  version_buffer[1] = (unsigned char)major;
58  version_buffer[2] = (unsigned char)minor;
59  version_buffer[3] = (unsigned char)revision;
60 
61  return *return_value;
62 }
63 
64 std::string to_string_version(uint32_t version)
65 {
66  std::stringstream new_version;
67  unsigned char* version_ptr = (unsigned char*)&version;
68  unsigned int major, minor, revision;
69 
70  major = (unsigned int)version_ptr[1];
71  minor = (unsigned int)version_ptr[2];
72  revision = (unsigned int)version_ptr[3];
73 
74  new_version << major;
75  new_version << '.';
76  new_version << minor;
77  new_version << '.';
78  new_version << revision;
79 
80  return new_version.str();
81 }
82 
86 {
87  std::string::iterator cur = input.begin();
88  char prev = 0;
89 
90  for (std::string::iterator eval = cur; eval != input.end(); ++eval)
91  {
92  // if it isn't whitespace, then copy it over immediately
93  if (*eval != ' ' && *eval != '\t' && *eval != '\n' && *eval != '\r')
94  {
95  prev = *cur = *eval;
96  ++cur;
97  }
98  // if it is whitespace, only insert whitespace if the previous char
99  // was non-whitespace
100  else if (prev)
101  {
102  *cur = ' ';
103  prev = 0;
104  ++cur;
105  }
106  }
107 
108  // if the last char is actually whitespace, then move cur back one spot
109  if (cur != input.end())
110  {
111  --cur;
112  if (*cur != ' ' && *cur != '\t' && *cur != '\n' && *cur != '\r')
113  ++cur;
114  }
115 
116  // erase everything from cur to end of input string
117  if (cur != input.end())
118  input.erase(cur, input.end());
119 
120  return input;
121 }
122 
125 {
126  std::string::iterator cur = input.begin();
127 
128  for (std::string::iterator eval = cur; eval != input.end(); ++eval)
129  {
130  // if it isn't whitespace, then copy it over immediately
131  if (*eval != ' ' && *eval != '\t' && *eval != '\n' && *eval != '\r')
132  {
133  *cur = *eval;
134  ++cur;
135  }
136  }
137 
138  // erase everything from cur to end of input string
139  if (cur != input.end())
140  input.erase(cur, input.end());
141 
142  return input;
143 }
144 
149 std::string& string_remove(std::string& input, char unwanted)
150 {
151  std::string::iterator cur = input.begin();
152 
153  for (std::string::iterator eval = cur; eval != input.end(); ++eval)
154  {
155  // if it isn't whitespace, then copy it over immediately
156  if (*eval != unwanted)
157  {
158  *cur = *eval;
159  ++cur;
160  }
161  }
162 
163  // erase everything from cur to end of input string
164  if (cur != input.end())
165  input.erase(cur, input.end());
166 
167  return input;
168 }
169 
170 size_t string_replace(std::string& source, const std::string& old_phrase,
171  const std::string& new_phrase, bool replace_all)
172 {
173  // return value
174  size_t replacements = 0;
175 
176  if (old_phrase != "")
177  {
178  for (std::string::size_type i = source.find(old_phrase, 0);
179  i != source.npos; i = source.find(old_phrase, i))
180  {
181  source.replace(i, old_phrase.size(), new_phrase);
182  i += new_phrase.size();
183 
184  ++replacements;
185 
186  if (!replace_all)
187  break;
188  }
189  }
190 
191  return replacements;
192 }
193 
195 {
196  std::stringstream source, dest;
197  std::string cur;
198  std::vector<std::string> splitters;
199  splitters.resize(2);
200 
201  splitters[0] = "//";
202 
203  // place the input in the string stream
204  source << input;
205 
206  while (std::getline(source, cur))
207  {
208  std::vector<std::string> tokens;
209  std::vector<std::string> pivots;
210  tokenizer(cur, splitters, tokens, pivots);
211 
212  if (tokens.size())
213  {
214  dest << tokens[0];
215  dest << "\n";
216  }
217  }
218 
219  input = dest.str();
220  return input;
221 }
222 
224 void tokenizer(const std::string& input,
225  const ::std::vector<std::string>& splitters,
226  ::std::vector<std::string>& tokens, ::std::vector<std::string>& pivots)
227 {
228  std::string::size_type last = 0;
229  std::string::size_type cur = 0;
230  tokens.clear();
231  pivots.clear();
232 
233  for (; cur < input.size(); ++cur)
234  {
235  for (std::string::size_type i = 0; i < splitters.size(); ++i)
236  {
237  // if the splitter string length is greater than zero
238  if (splitters[i].size() > 0)
239  {
240  // if the first char of the splitter string is equal to the char
241  if (input[cur] == splitters[i][0])
242  {
243  std::string::size_type checker = cur;
244  std::string::size_type j = 1;
245  for (++checker; checker < input.size() && j < splitters[i].size() &&
246  input[checker] == splitters[i][j];
247  ++j, ++checker)
248  ;
249 
250  // we have found a splitter. Tokenize from last to splitter.
251  if (j == splitters[i].size())
252  {
253  // need to update this to only have as many pivots as tokens - 1
254  pivots.push_back(input.substr(cur, j));
255 
256  if (cur - last >= splitters[i].size() - 1)
257  tokens.push_back(input.substr(last, cur - last));
258  else
259  tokens.push_back("");
260 
261  // we want last to point to the last valid token begin
262  cur = checker - 1;
263  last = checker;
264  } // if found a splitter
265  } // if first char == splitter first char
266  } // if splitter length >= 1
267  } // for splitters
268 
269  } // for chars
270 
271  if (last != cur)
272  {
273  tokens.push_back(input.substr(last, cur - last));
274  }
275 }
276 
277 // split a key into a corresponding host and port
279  const std::string& key, std::string& host, std::string& port)
280 {
281  // delimiter is either a : or an @
282  std::string::size_type delim = key.rfind(':');
283  delim = delim == key.npos ? key.rfind('@') : delim;
284 
285  // no delimiter found
286  if (delim == key.npos)
287  {
288  host = key;
289  port = "";
290 
291  return 1;
292  }
293 
294  // otherwise, set the host and port appropriately
295  host = key.substr(0, delim);
296  port = key.substr(delim + 1, key.size() - delim);
297 
298  return 0;
299 }
300 
301 // merge a host and port into a key
303  std::string& key, const std::string& host, const std::string& port)
304 {
305  if ((const std::string*)&key != &host)
306  key = host;
307 
308  key += ':';
309  key += port;
310 
311  return 0;
312 }
313 
314 // merge a host and ushort port into a key
316  std::string& key, const std::string& host, unsigned short u_port)
317 {
318  std::stringstream port_stream;
319  port_stream << u_port;
320 
321  return merge_hostport_identifier(key, host, port_stream.str());
322 }
323 
325 {
326  std::string line;
327  std::stringstream buffer;
328 
329  std::ifstream file(filename.c_str());
330 
331  // if the file was able to open
332  if (file.is_open())
333  {
334  std::getline(file, line);
335 
336  if (line != "")
337  buffer << line;
338 
339  // while there is still a line left in the file, read that line
340  // into our stringstream buffer
341  while (std::getline(file, line))
342  buffer << "\n" << line;
343  file.close();
344  }
345  else
346  {
348  "utility::file_to_string:"
349  " failed to open file: %s\n",
350  filename.c_str());
351  }
352 
353  return buffer.str();
354 }
355 
358 {
359  std::stringstream buffer;
360 
361  for (size_t i = 0; i < source.size(); ++i)
362  {
363  // environment variable must be larger than $()
364  if (source[i] == '$' && i + 3 < source.size())
365  {
366  char* value = get_var(source, i + 2, i);
367  if (value)
368  buffer << value;
369  }
370  else
371  buffer << source[i];
372  }
373  return buffer.str();
374 }
375 
376 MADARA_EXPORT void strncpy_safe(char * dst, const char * src, size_t dst_size)
377 {
378  strncpy(dst, src, dst_size);
379  dst[dst_size - 1] = 0;
380 }
381 
383 char* get_var(const std::string& source, size_t cur, size_t& end)
384 {
385  for (end = cur; end < source.size(); ++end)
386  {
387  if (source[end] == ')' || source[end] == '}')
388  {
389  return getenv(source.substr(cur, end - cur).c_str());
390  }
391  }
392 
393  return getenv(source.substr(cur, source.size() - cur).c_str());
394 }
395 
397 {
398 // define the characters we'll want to replace
399 #ifdef _WIN32
400 #define REPLACE_THIS '/'
401 #define REPLACE_WITH '\\'
402 #else
403 #define REPLACE_THIS '\\'
404 #define REPLACE_WITH '/'
405 #endif
406 
407  std::string target(source);
408 
409  for (std::string::iterator i = target.begin(); i != target.end(); ++i)
410  {
411  if (*i == REPLACE_THIS)
412  *i = REPLACE_WITH;
413  }
414 
415  return target;
416 }
417 
418 int read_file(const std::string& filename, void*& buffer, size_t& size,
419  bool add_zero_char)
420 {
421  int ret_value = 0;
422  size = 0;
423 
424  if (filename != "")
425  {
426  try
427  {
428  std::ifstream file(filename, std::ifstream::binary);
429 
430  if (file)
431  {
432  file.seekg(0, file.end);
433  size = (size_t)file.tellg();
434  file.seekg(0, file.beg);
435 
437  "utility::read_file:"
438  " reading %d bytes from %s\n",
439  (int)size, filename.c_str());
440 
441  if (add_zero_char)
442  {
443  ++size;
444  }
445 
446  buffer = new unsigned char[size];
447 
448  if (size > 0)
449  {
450  file.read((char*)buffer, size);
451 
453  "utility::read_file:"
454  " successfully read %d bytes from %s\n",
455  (int)size, filename.c_str());
456 
457  if (add_zero_char)
458  {
459  unsigned char* zeroed = (unsigned char*)buffer;
460  zeroed[size - 1] = 0;
461  } // end if adding a zero char
462 
463  ret_value = 0;
464  }
465 
466  file.close();
467  } // end if file is open
468  else
469  ret_value = -1;
470  } // end try
471  catch (const std::exception& e)
472  {
474  "utility::read_file:"
475  " exception: %s\n",
476  e.what());
477 
478  ret_value = -1;
479  }
480  }
481  else
482  ret_value = -1;
483 
484  return ret_value;
485 }
486 
487 ssize_t write_file(const std::string& filename, void* buffer, size_t size)
488 {
489  // error is -1
490  ssize_t actual = -1;
491 
492  std::ofstream file;
493 
494  try
495  {
496  file.open(filename, std::ios::out | std::ios::binary);
497  if (file.write((char*)buffer, size))
498  {
499  actual = size;
500  }
501  file.close();
502 
504  "utility::write_file:"
505  " wrote %d bytes to %s\n",
506  (int)actual, filename.c_str());
507  }
508  catch (const std::exception& e)
509  {
511  "utility::write_file:"
512  " exception: %s\n",
513  e.what());
514  }
515 
516  // return the actual bytes written. -1 if error
517  return actual;
518 }
519 
520 double rand_double(double floor, double ceiling, bool set_seed_to_time)
521 {
522  // check if the user has specified setting through srand
523  if (set_seed_to_time)
524  {
525  srand((unsigned int)get_time());
526  }
527 
528  // Get a double number between 0 and 1.
529  double position_in_range = ((double)rand()) / ((double)RAND_MAX);
530 
531  if (floor < ceiling)
532  return (position_in_range * (ceiling - floor)) + floor;
533  else
534  return (position_in_range * (floor - ceiling)) + ceiling;
535 }
536 
537 int64_t rand_int(int64_t floor, int64_t ceiling, bool set_seed_to_time)
538 {
539  double random = rand_double((double)floor, (double)ceiling, set_seed_to_time);
540  return nearest_int(random);
541 }
542 
543 int64_t nearest_int(double input)
544 {
545  int change = input >= 0 ? 1 : -1;
546  int64_t left = (int64_t)input;
547  int64_t right = (int64_t)input + change;
548 
549  if (input - left < -input + right)
550  return left;
551  else
552  return right;
553 }
554 
555 double sleep(double sleep_time)
556 {
557  SecondsDuration period = seconds_to_seconds_duration(sleep_time);
558  period = sleep(period);
559 
560  return period.count();
561 }
562 
564 {
565 #ifdef MADARA_FEATURE_SIMTIME
566  static const SecondsDuration max_sleep{0.01};
567 #endif
568 
569  using TVal = std::chrono::time_point<Clock, SecondsDuration>;
570 
571  TVal start = get_time_value();
572  TVal target = start + sleep_time;
573  TVal current;
574 
575  while ((current = get_time_value()) < target)
576  {
577 #ifndef MADARA_FEATURE_SIMTIME
579 #else
580  double rate = utility::SimTime::rate();
581  SecondsDuration actual_dur = ((target - current) / rate);
582 #if 0
583  std::cerr << (target - current).count() << " " << rate << " " <<
584  actual_dur.count() << std::endl;
585 #endif
586  TVal actual_current = Clock::now();
587  TVal actual_target = actual_current + actual_dur;
588  TVal max_target = actual_current + max_sleep;
589 #if 0
590  std::cerr <<
591  start.time_since_epoch().count() << " " <<
592  target.time_since_epoch().count() << " " <<
593  current.time_since_epoch().count() << " " <<
594  SimTime::time() << " " <<
595  actual_target.time_since_epoch().count() << " " <<
596  max_target.time_since_epoch().count() << std::endl;
597 #endif
598  if (actual_target < max_target)
599  {
600  std::this_thread::sleep_until(actual_target);
601  }
602  else
603  {
604  std::this_thread::sleep_until(max_target);
605  }
606 #endif
607  }
608 
609  return current - start;
610 }
611 
613 {
614 #ifdef MADARA_FEATURE_SIMTIME
615  static const Duration max_sleep{10000000};
616 #endif
617 
618  TimeValue start = get_time_value();;
619  TimeValue current;
620 
621  while ((current = get_time_value()) < wake)
622  {
623 #ifndef MADARA_FEATURE_SIMTIME
625 #else
626 #if 0
627  std::cerr << (target - current).count() << " " << rate << " " <<
628  actual_dur.count() << std::endl;
629 #endif
630  TimeValue actual_target =
631  TimeValue(Duration(SimTime::realtime(wake.time_since_epoch().count())));
632 
633  TimeValue actual_current = Clock::now();
634  TimeValue max_target = actual_current + max_sleep;
635 #if 0
636  std::cerr <<
637  start.time_since_epoch().count() << " " <<
638  target.time_since_epoch().count() << " " <<
639  current.time_since_epoch().count() << " " <<
640  SimTime::time() << " " <<
641  actual_target.time_since_epoch().count() << " " <<
642  max_target.time_since_epoch().count() << std::endl;
643 #endif
644  if (actual_target < max_target)
645  {
646  std::this_thread::sleep_until(actual_target);
647  }
648  else
649  {
650  std::this_thread::sleep_until(max_target);
651  }
652 #endif
653  }
654 
655  return current - start;
656 }
657 
658 Duration sleep_until(uint64_t wake)
659 {
660  return sleep_until(TimeValue(Duration(wake)));
661 }
662 
664  const knowledge::WaitSettings& settings)
665 {
666  // use the EpochEnforcer utility to keep track of sleeps
668  settings.poll_frequency, settings.max_wait_time);
669 
670  knowledge::VariableReference ref = knowledge.get_ref(variable);
671 
672  // print the post statement at highest log level (cannot be masked)
673  if (settings.pre_print_statement != "")
675 
676  knowledge::KnowledgeRecord last_value = knowledge.get(ref, settings);
677 
679  "utility::wait_true:"
680  " variable returned %s\n",
681  last_value.to_string().c_str());
682 
683  // wait for expression to be true
684  while (!last_value.is_true() &&
685  (settings.max_wait_time < 0 || !enforcer.is_done()))
686  {
688  "utility::wait_true:"
689  " last value didn't result in success\n");
690 
691  // Unlike the other wait statements, we allow for a time based wait.
692  // To do this, we allow a user to specify a
693  if (settings.poll_frequency > 0)
694  {
695  enforcer.sleep_until_next();
696  }
697  else
698  {
699  knowledge.wait_for_change();
700  }
701 
703  "utility::wait_true:"
704  " waiting on %s\n",
705  variable.c_str());
706 
707  last_value = knowledge.get(ref, settings);
708 
710  "utility::wait_true:"
711  " completed eval to get %s\n",
712  last_value.to_string().c_str());
713  } // end while (!last)
714 
715  if (enforcer.is_done())
716  {
718  "utility::wait_true:"
719  " Evaluate did not succeed. Timeout occurred\n",
720  last_value.to_string().c_str());
721  }
722 
723  // print the post statement at highest log level (cannot be masked)
724  if (settings.post_print_statement != "")
726 
727  return last_value.is_true();
728 }
729 
731  const std::string& variable, const knowledge::WaitSettings& settings)
732 {
733  // use the EpochEnforcer utility to keep track of sleeps
735  settings.poll_frequency, settings.max_wait_time);
736 
737  knowledge::VariableReference ref = knowledge.get_ref(variable);
738 
739  // print the post statement at highest log level (cannot be masked)
740  if (settings.pre_print_statement != "")
742 
743  knowledge::KnowledgeRecord last_value(!knowledge.get(ref, settings));
744 
746  "utility::wait_false:"
747  " variable returned %s\n",
748  last_value.to_string().c_str());
749 
750  // wait for expression to be true
751  while (last_value.is_true() &&
752  (settings.max_wait_time < 0 || !enforcer.is_done()))
753  {
755  "utility::wait_false:"
756  " last value didn't result in success\n");
757 
758  // Unlike the other wait statements, we allow for a time based wait.
759  // To do this, we allow a user to specify a
760  if (settings.poll_frequency > 0)
761  {
762  enforcer.sleep_until_next();
763  }
764  else
765  {
766  knowledge.wait_for_change();
767  }
768 
770  "utility::wait_false:"
771  " waiting on %s\n",
772  variable.c_str());
773 
774  last_value = knowledge::KnowledgeRecord(!knowledge.get(ref, settings));
775 
777  "utility::wait_false:"
778  " completed eval to get %s\n",
779  last_value.to_string().c_str());
780  } // end while (!last)
781 
782  if (enforcer.is_done())
783  {
785  "utility::wait_false:"
786  " Evaluate did not succeed. Timeout occurred\n",
787  last_value.to_string().c_str());
788  }
789 
790  // print the post statement at highest log level (cannot be masked)
791  if (settings.post_print_statement != "")
793 
794  return last_value.is_true();
795 }
796 
797 std::pair<std::string, uint16_t> parse_address(std::string addr)
798 {
799  size_t colon_pos = addr.find(':');
800  if (colon_pos == std::string::npos || colon_pos >= addr.size() - 1)
801  {
802  return {addr, 0};
803  }
804 
805  int16_t port = std::atoi(addr.c_str() + colon_pos + 1);
806  addr.resize(colon_pos);
807  return {std::move(addr), port};
808 }
809 
810 
811 void safe_clear(std::vector<std::string> & strings)
812 {
813  strings.clear();
814 }
815 
816 }
817 }
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
#define REPLACE_WITH
#define REPLACE_THIS
madara::knowledge::KnowledgeRecord KnowledgeRecord
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class encapsulates an entry in a KnowledgeBase.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
bool is_true(void) const
Checks to see if the record is true.
Optimized reference to a variable within the knowledge base.
Enforces a periodic epoch.
Definition: EpochEnforcer.h:18
bool is_done(void) const
Checks to see if max duration is finished.
void sleep_until_next(void)
Sleeps until the next epoch.
Definition: EpochEnforcer.h:91
constexpr string_t string
constexpr binary_t binary
Provides functions and classes for the distributed knowledge base.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
Definition: GetRecord.h:121
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:15
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...
Definition: Utility.cpp:85
std::string file_to_string(const std::string &filename)
Reads a file into a string.
Definition: Utility.cpp:324
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.
Definition: Utility.cpp:302
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.
Definition: Utility.cpp:730
void safe_clear(std::vector< std::string > &strings)
Safely clear a vector of STL strings when an application has been compiled with a different version o...
Definition: Utility.cpp:811
ssize_t write_file(const std::string &filename, void *buffer, size_t size)
Writes a file with provided contents.
Definition: Utility.cpp:487
std::string & strip_white_space(std::string &input)
Strip all whitespace.
Definition: Utility.cpp:124
std::string & string_remove(std::string &input, char unwanted)
Strips an unwanted character.
Definition: Utility.cpp:149
int64_t rand_int(int64_t floor, int64_t ceiling, bool set_seed_to_time)
Returns a random integer between a floor and ceiling.
Definition: Utility.cpp:537
std::chrono::time_point< Clock > TimeValue
time point
Definition: Utility.h:36
std::string to_string_version(uint32_t version)
Converts a MADARA uint32_t version number to human-readable.
Definition: Utility.cpp:64
double rand_double(double floor, double ceiling, bool set_seed_to_time)
Returns a random double between floor and ceiling.
Definition: Utility.cpp:520
std::chrono::nanoseconds Duration
default clock duration
Definition: Utility.h:30
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.
Definition: Utility.cpp:224
double sleep(double sleep_time)
Sleeps for a certain amount of time.
Definition: Utility.cpp:555
char * get_var(const std::string &source, size_t cur, size_t &end)
grab an environment variable value (
Definition: Utility.cpp:383
std::string get_version(void)
Gets the MADARA version number.
Definition: Utility.cpp:23
int64_t nearest_int(double input)
Rounds a double to the nearest integer.
Definition: Utility.cpp:543
SecondsDuration seconds_to_seconds_duration(double seconds)
Returns seconds in double format as seconds duration.
Definition: Utility.inl:283
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.
Definition: Utility.cpp:170
std::string & strip_comments(std::string &input)
Strips all comments (single-line and multi-line).
Definition: Utility.cpp:194
Duration sleep_until(uint64_t wake)
Definition: Utility.cpp:658
int64_t get_time(void)
Returns a time of day in nanoseconds If simtime feature is enabled, this may be simulation time inste...
Definition: Utility.inl:265
MADARA_EXPORT void strncpy_safe(char *dst, const char *src, size_t dst_size)
Performs a strncpy in a way that will compile without warnings.
Definition: Utility.cpp:376
Duration sleep_until(TimeValue wake)
Definition: Utility.cpp:612
std::string expand_envs(const std::string &source)
Expand any environment variables in a string.
Definition: Utility.cpp:357
std::chrono::duration< double > SecondsDuration
default clock duration
Definition: Utility.h:33
std::pair< std::string, uint16_t > parse_address(std::string addr)
Definition: Utility.cpp:797
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...
Definition: Utility.inl:256
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.
Definition: Utility.cpp:663
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.
Definition: Utility.cpp:278
int read_file(const std::string &filename, void *&buffer, size_t &size, bool add_zero_char)
Reads a file into a provided void pointer.
Definition: Utility.cpp:418
std::string clean_dir_name(const std::string &source)
Substitutes the appropriate directory delimiter, which may help with portability between operating sy...
Definition: Utility.cpp:396
uint32_t get_uint_version(const std::string &str_version)
Converts a string version to a uint32.
Definition: Utility.cpp:30
Copyright(c) 2020 Galois.
std::string post_print_statement
Statement to print after evaluations.
Definition: EvalSettings.h:151
std::string pre_print_statement
Statement to print before evaluations.
Definition: EvalSettings.h:146
Encapsulates settings for a wait statement.
Definition: WaitSettings.h:25
double max_wait_time
Maximum time to wait for an expression to become true (in seconds)
Definition: WaitSettings.h:136
double poll_frequency
Frequency to poll an expression for truth (in seconds)
Definition: WaitSettings.h:131