HermesCommon  3.0
mixins.cpp
1 // This file is part of HermesCommon
2 //
3 // Hermes is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes; if not, see <http://www.gnu.prg/licenses/>.
15 #include "mixins.h"
16 #include "common.h"
17 #include "matrix.h"
18 #include "util/memory_handling.h"
19 #ifdef WIN32
20 #include <Windows.h>
21 #endif
22 
23 namespace Hermes
24 {
25  namespace Mixins
26  {
27  void StateQueryable::check() const
28  {
29  if (!this->isOkay())
30  {
31  std::stringstream ss;
32  ss << "The instance of " << this->getClassName() << " is not OK.";
33  throw Hermes::Exceptions::Exception(ss.str().c_str());
34  }
35  }
36 
37  char* Loggable::staticLogFileName = nullptr;
38 
39  Loggable::Loggable(bool verbose_output, callbackFn verbose_callback, bool add_newline) :
40  verbose_output(verbose_output),
41  verbose_callback(verbose_callback),
42  logFileName(NULL),
43  print_timestamps(true),
44  erase_on_beginning(false),
45  file_output_only(false),
46  log_file_written(false),
47  add_newline(add_newline)
48  {
49  }
50 
51  void Loggable::set_logFile_name(const char* filename)
52  {
53  free_with_check(this->logFileName);
54  int strlength = std::strlen(filename);
55  this->logFileName = malloc_with_check<char>(strlength + 1);
56  strcpy(this->logFileName, filename);
57  }
58 
59  void Loggable::set_logFile_name(std::string filename)
60  {
61  this->set_logFile_name(filename.c_str());
62  }
63 
64  void Loggable::set_static_logFile_name(const char* filename)
65  {
66  free_with_check(Loggable::staticLogFileName);
67  int strlength = std::strlen(filename);
68  Loggable::staticLogFileName = malloc_with_check<char>(strlength + 1);
69  strcpy(Loggable::staticLogFileName, filename);
70  }
71 
72  void Loggable::set_static_logFile_name(std::string filename)
73  {
74  Loggable::set_static_logFile_name(filename.c_str());
75  }
76 
77  void Loggable::set_file_output_only(bool onOff)
78  {
79  this->file_output_only = onOff;
80  }
81 
83  {
84  return this->verbose_output;
85  }
86 
87  Loggable::callbackFn Loggable::get_verbose_callback() const
88  {
89  return this->verbose_callback;
90  }
91 
92  void Loggable::Static::info(const char* msg, ...)
93  {
94  char text[BUF_SZ];
95  char* text_contents = text + 1;
96 
97  text[0] = HERMES_EC_INFO;
98  text[1] = ' ';
99  text_contents++;
100 
101  //print the message
102  va_list arglist;
103  va_start(arglist, msg);
104  vsprintf(text_contents, msg, arglist);
105  va_end(arglist);
106 
107  //Windows platform
108 #ifdef _WINDOWS
109  HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE);
110 
111  //generate console settings
112  WORD console_attr_red = FOREGROUND_RED, console_attr_green = FOREGROUND_GREEN, console_attr_blue = FOREGROUND_BLUE;
113 
114  WORD console_attrs = 0;
115  console_attrs |= console_attr_green;
116 
117  //set new_ console settings
118  SetConsoleTextAttribute(h_console, console_attrs);
119 
120  //write text
121  DWORD num_written;
122  BOOL write_success = WriteConsoleA(h_console, text_contents, strlen(text_contents), &num_written, nullptr);
123  std::cout << std::endl;
124 
125  //Linux platform
126 #else
127 # define FOREGROUND_RED 1
128 # define FOREGROUND_GREEN 2
129 # define FOREGROUND_BLUE 4
130  //console color code
131  int console_attrs = 0;
132  bool console_bold = true;
133 
134  printf("\033[%dm", console_attrs + 30);
135 
136  //emphasize and console bold
137  if (console_bold)
138  printf("\033[1m");
139 
140  //print text and reset settings
141  printf("%s\033[0m\n", text_contents);
142 
143 #endif
144  }
145 
146  void Loggable::Static::warn(const char* msg, ...)
147  {
148  char text[BUF_SZ];
149  char* text_contents = text + 1;
150 
151  text[0] = HERMES_EC_WARNING;
152  text[1] = ' ';
153  text_contents++;
154 
155  //print the message
156  va_list arglist;
157  va_start(arglist, msg);
158  vsprintf(text_contents, msg, arglist);
159  va_end(arglist);
160 
161  //Windows platform
162 #ifdef _WINDOWS
163  HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE);
164 
165  //generate console settings
166  WORD console_attr_red = FOREGROUND_RED, console_attr_green = FOREGROUND_GREEN, console_attr_blue = FOREGROUND_BLUE;
167 
168  WORD console_attrs = 0;
169  console_attrs |= console_attr_red | console_attr_green;
170 
171  //set new_ console settings
172  SetConsoleTextAttribute(h_console, console_attrs);
173 
174  //write text
175  DWORD num_written;
176  BOOL write_success = WriteConsoleA(h_console, text_contents, strlen(text_contents), &num_written, nullptr);
177  std::cout << std::endl;
178  //Linux platform
179 #else
180 # define FOREGROUND_RED 1
181 # define FOREGROUND_GREEN 2
182 # define FOREGROUND_BLUE 4
183  //console color code
184  int console_attrs = 1;
185  console_attrs |= FOREGROUND_RED | FOREGROUND_GREEN;
186  bool console_bold = false;
187 
188  printf("\033[%dm", console_attrs + 30);
189 
190  //emphasize and console bold
191  if (console_bold)
192  printf("\033[1m");
193 
194  //print text and reset settings
195  printf("%s\033[0m\n", text_contents);
196 
197 #endif
198  }
199 
200  void Loggable::Static::error(const char* msg, ...)
201  {
202  char text[BUF_SZ];
203  char* text_contents = text + 1;
204 
205  text[0] = HERMES_EC_ERROR;
206  text[1] = ' ';
207  text_contents++;
208 
209  //print the message
210  va_list arglist;
211  va_start(arglist, msg);
212  vsprintf(text_contents, msg, arglist);
213  va_end(arglist);
214 
215  //Windows platform
216 #ifdef _WINDOWS
217  HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE);
218 
219  //generate console settings
220  WORD console_attr_red = FOREGROUND_RED, console_attr_green = FOREGROUND_GREEN, console_attr_blue = FOREGROUND_BLUE;
221 
222  WORD console_attrs = 0;
223  console_attrs |= console_attr_red;
224 
225  //set new_ console settings
226  SetConsoleTextAttribute(h_console, console_attrs);
227 
228  //write text
229  DWORD num_written;
230  BOOL write_success = WriteConsoleA(h_console, text_contents, strlen(text_contents), &num_written, nullptr);
231  std::cout << std::endl;
232  //Linux platform
233 #else
234 # define FOREGROUND_RED 1
235 # define FOREGROUND_GREEN 2
236 # define FOREGROUND_BLUE 4
237  //console color code
238  int console_attrs = 1;
239  console_attrs |= FOREGROUND_RED;
240  bool console_bold = false;
241 
242  printf("\033[%dm", console_attrs + 30);
243 
244  //emphasize and console bold
245  if (console_bold)
246  printf("\033[1m");
247 
248  //print text and reset settings
249  printf("%s\033[0m\n", text_contents);
250 
251 #endif
252  }
253 
254  void Loggable::error(const char* msg, ...) const
255  {
256  if (!this->verbose_output)
257  return;
258 
259  char text[BUF_SZ];
260  char* text_contents = text + 1;
261 
262  text[0] = HERMES_EC_ERROR;
263  text[1] = ' ';
264  text_contents++;
265 
266  //print the message
267  va_list arglist;
268  va_start(arglist, msg);
269  vsprintf(text_contents, msg, arglist);
270  va_end(arglist);
271  hermes_log_message(HERMES_EC_ERROR, text_contents);
272  }
273 
274  void Loggable::error_if(bool cond, const char* msg, ...) const
275  {
276  if (!this->verbose_output)
277  return;
278 
279  if (cond)
280  {
281  char text[BUF_SZ];
282  char* text_contents = text + 1;
283 
284  text[0] = HERMES_EC_ERROR;
285  text[1] = ' ';
286  text_contents++;
287 
288  //print the message
289  va_list arglist;
290  va_start(arglist, msg);
291  vsprintf(text_contents, msg, arglist);
292  va_end(arglist);
293  hermes_log_message(HERMES_EC_ERROR, text_contents);
294  }
295  }
296 
297  void Loggable::warn(const char* msg, ...) const
298  {
299  if (!this->verbose_output)
300  return;
301 
302  char text[BUF_SZ];
303  char* text_contents = text + 1;
304 
305  text[0] = HERMES_EC_WARNING;
306  text[1] = ' ';
307  text_contents++;
308 
309  //print the message
310  va_list arglist;
311  va_start(arglist, msg);
312  vsprintf(text_contents, msg, arglist);
313  va_end(arglist);
314  hermes_log_message(HERMES_EC_WARNING, text_contents);
315  }
316 
317  void Loggable::warn_if(bool cond, const char* msg, ...) const
318  {
319  if (!this->verbose_output)
320  return;
321 
322  if (cond)
323  {
324  char text[BUF_SZ];
325  char* text_contents = text + 1;
326 
327  text[0] = HERMES_EC_WARNING;
328  text[1] = ' ';
329  text_contents++;
330 
331  //print the message
332  va_list arglist;
333  va_start(arglist, msg);
334  vsprintf(text_contents, msg, arglist);
335  va_end(arglist);
336  hermes_log_message(HERMES_EC_WARNING, text_contents);
337  }
338  }
339  void Loggable::info(const char* msg, ...) const
340  {
341  if (!this->verbose_output)
342  return;
343 
344  char text[BUF_SZ];
345  char* text_contents = text + 1;
346 
347  text[0] = HERMES_EC_INFO;
348  text[1] = ' ';
349  text_contents++;
350 
351  //print the message
352  va_list arglist;
353  va_start(arglist, msg);
354  vsprintf(text_contents, msg, arglist);
355  va_end(arglist);
356  hermes_log_message(HERMES_EC_INFO, text_contents);
357  }
358  void Loggable::info_if(bool cond, const char* msg, ...) const
359  {
360  if (!this->verbose_output)
361  return;
362 
363  if (cond)
364  {
365  char text[BUF_SZ];
366  char* text_contents = text + 1;
367 
368  text[0] = HERMES_EC_INFO;
369  text[1] = ' ';
370  text_contents++;
371 
372  //print the message
373  va_list arglist;
374  va_start(arglist, msg);
375  vsprintf(text_contents, msg, arglist);
376  va_end(arglist);
377  hermes_log_message(HERMES_EC_INFO, text_contents);
378  }
379  }
380 
381  bool Loggable::write_console(const char code, const char* text) const
382  {
383  //Windows platform
384 #ifdef _WINDOWS
385  HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE);
386  if (h_console == INVALID_HANDLE_VALUE)
387  return false;
388 
389  //read current console settings
390  CONSOLE_SCREEN_BUFFER_INFO console_info;
391  if (!GetConsoleScreenBufferInfo(h_console, &console_info))
392  return false;
393 
394  //generate console settings
395  WORD console_attr_red = FOREGROUND_RED, console_attr_green = FOREGROUND_GREEN, console_attr_blue = FOREGROUND_BLUE;
396 
397  WORD console_attrs = 0;
398  switch (code)
399  {
400  case HERMES_EC_ERROR: console_attrs |= console_attr_red; break;
401  case HERMES_EC_WARNING: console_attrs |= console_attr_red | console_attr_green; break;
402  case HERMES_EC_INFO:console_attrs |= console_attr_green; break;
403  default: throw Hermes::Exceptions::Exception("Unknown error code: '%c'", code);
404  }
405 
406  //set new_ console settings
407  SetConsoleTextAttribute(h_console, console_attrs);
408 
409  //write text
410  DWORD num_written;
411  BOOL write_success = WriteConsoleA(h_console, text, strlen(text), &num_written, nullptr);
412 
413  //return previous settings
414  SetConsoleTextAttribute(h_console, console_info.wAttributes);
415 
416  if (write_success)
417  return true;
418  else
419  return false;
420  //Linux platform
421 #else
422 # define FOREGROUND_RED 1
423 # define FOREGROUND_GREEN 2
424 # define FOREGROUND_BLUE 4
425  //console color code
426  int console_attrs = 0;
427  bool console_bold = false;
428  switch (code)
429  {
430  case HERMES_EC_WARNING: console_attrs |= FOREGROUND_RED | FOREGROUND_GREEN; break;
431  case HERMES_EC_INFO: console_bold = true; break;
432  default: throw Hermes::Exceptions::Exception("Unknown error code: '%c'", code);
433  }
434 
435  printf("\033[%dm", console_attrs + 30);
436 
437  //emphasize and console bold
438  if (console_bold)
439  printf("\033[1m");
440 
441  //print text and reset settings
442  printf("%s\033[0m", text);
443 
444  return true;
445 #endif
446  }
447 
448  Loggable::HermesLogEventInfo* Loggable::hermes_build_log_info(char event) const
449  {
450  return new Loggable::HermesLogEventInfo(event, __CURRENT_FUNCTION, __FILE__, __LINE__);
451  }
452 
453  void Loggable::hermes_fwrite(const void* ptr, size_t size, size_t nitems, FILE* stream) const
454  {
455  if (fwrite(ptr, size, nitems, stream) != nitems || ferror(stream))
456  throw Hermes::Exceptions::Exception("Error writing to file: %s", strerror(ferror(stream)));
457  }
458 
459  void Loggable::hermes_fread(void* ptr, size_t size, size_t nitems, FILE* stream) const
460  {
461  size_t ret = fread(ptr, size, nitems, stream);
462  if (ret < nitems)
463  throw Hermes::Exceptions::Exception("Premature end of file.");
464  else if (ferror(stream))
465  throw Hermes::Exceptions::Exception("Error reading file: %s", strerror(ferror(stream)));
466  }
467 
468  Loggable::HermesLogEventInfo::HermesLogEventInfo(const char code, const char* src_function, const char* src_file, const int src_line)
469  : code(code), src_function(src_function), src_file(src_file), src_line(src_line)
470  {}
471 
472  void Loggable::set_timestamps(bool onOff)
473  {
474  this->print_timestamps = onOff;
475  }
476 
478  {
479  this->erase_on_beginning = onOff;
480  }
481 
482  void Loggable::hermes_log_message(const char code, const char* msg) const
483  {
484 #pragma omp critical (hermes_log_message)
485  {
486  //print the message
487  if (!this->file_output_only)
488  {
489  if (!write_console(code, msg))
490  //safe fallback
491  printf("%s", msg);
492 
493  //write a new line
494  printf("\n");
495  }
496 
497  HermesLogEventInfo* info = this->hermes_build_log_info(code);
498 
499  //print to file
500  char* log_file_name = (this->logFileName ? this->logFileName : Loggable::staticLogFileName);
501  if (log_file_name)
502  {
503  FILE* file;
504  if (this->erase_on_beginning && !this->log_file_written)
505  file = fopen(log_file_name, "wt");
506  else
507  file = fopen(log_file_name, "at");
508  if (file != NULL)
509  {
510  //check whether log file was already written
511  if (!log_file_written)
512  {
513  //first write, write delimited to a file
514  (const_cast<Loggable*>(this))->log_file_written = true;
515  if (!this->erase_on_beginning)
516  {
517  fprintf(file, "\n");
518  for (int i = 0; i < HERMES_LOG_FILE_DELIM_SIZE; i++)
519  fprintf(file, "-");
520  fprintf(file, "\n\n");
521  }
522  }
523 
524  if (print_timestamps)
525  {
526  //get time
527  time_t now;
528  time(&now);
529  struct tm* now_tm = gmtime(&now);
530  char time_buf[BUF_SZ];
531  strftime(time_buf, BUF_SZ, "%y%m%d-%H:%M", now_tm);
532  //write
533  fprintf(file, "%s\t%s", time_buf, msg);
534  }
535  else
536  fprintf(file, "%s", msg);
537 
538  if (this->add_newline)
539  fprintf(file, "\n");
540 
541  fclose(file);
542 
543  if (this->verbose_callback != nullptr)
544  this->verbose_callback(msg);
545  }
546  }
547 
548  delete info;
549  }
550  }
551 
553  {
554  this->verbose_output = to_set;
555  }
556 
557  void Loggable::set_verbose_callback(callbackFn callback)
558  {
559  this->verbose_callback = callback;
560  }
561 
562  TimeMeasurable::TimeMeasurable(const char *name) : period_name(name == nullptr ? "unnamed" : name)
563  {
564  //initialization
565 #ifdef _WINDOWS //Windows
566  LARGE_INTEGER freq;
567  if (QueryPerformanceFrequency(&freq))
568  frequency = (double)freq.QuadPart;
569  else
570  frequency = -1;
571 #endif //Linux
572  tick_reset();
573  }
574 
575  TimeMeasurable::SysTime TimeMeasurable::get_time() const
576  {
577 #ifdef _WINDOWS //Windows
578  if (frequency > 0)
579  {
580  LARGE_INTEGER ticks;
581  QueryPerformanceCounter(&ticks);
582  return ticks.QuadPart;
583  }
584  else
585  {
586  return clock();
587  }
588 #elif defined(__APPLE__) //Mac
589  // FIXME: implement time measurement on Mac
590  timespec tm;
591  return tm;
592 #else //Linux
593  timespec tm;
594  clock_gettime(CLOCK_REALTIME, &tm);
595  return tm;
596 #endif
597  }
598 
599  double TimeMeasurable::period_in_seconds(const SysTime& begin, const SysTime& end) const
600  {
601 #ifdef _WINDOWS //Windows
602  uint64_t period = end - begin;
603  if (frequency > 0)
604  return period / frequency;
605  else
606  return period / (double)CLOCKS_PER_SEC;
607 #else //Linux
608  int sec_corr = 0;
609  long period_nsec = end.tv_nsec - begin.tv_nsec;
610  if (period_nsec < 0)
611  {
612  sec_corr += -1;
613  period_nsec += 1000000000UL;
614  }
615  long period_sec = (long)(end.tv_sec - begin.tv_sec) + sec_corr;
616  return period_sec + (period_nsec / 1E9);
617 #endif
618  }
619 
621  {
622  SysTime cur_time = get_time();
623  if (type == HERMES_ACCUMULATE)
624  {
625  double secs = period_in_seconds(last_time, cur_time);
626  accum += secs;
627  last_period = secs;
628  }
629  else
630  last_period = 0.0;
631 
632  last_time = cur_time;
633  return *this;
634  }
635 
636  const std::string& TimeMeasurable::name() const
637  {
638  return period_name;
639  }
640 
642  {
643  return accum;
644  }
645 
646  std::string TimeMeasurable::accumulated_str() const {
647  return to_string(accum);
648  }
649 
650  double TimeMeasurable::last() const
651  {
652  return last_period;
653  }
654 
655  std::string TimeMeasurable::last_str() const
656  {
657  return to_string(last_period);
658  }
659 
661  {
662  tick(HERMES_SKIP);
663  reset();
664  return *this;
665  }
666 
668  {
669  accum = 0;
670  last_time = get_time();
671  last_period = 0.0;
672  return *this;
673  }
674 
675  std::string TimeMeasurable::to_string(double secs) const
676  {
677  if (secs < 0)
678  return "NO TIME";
679  else
680  {
681  int hours = (int)secs / (3600);
682  int mins = (int)fmod(secs, 3600) / 60;
683  secs = fmod(secs, 60);
684 
685  std::stringstream str;
686  if (hours > 0)
687  str << hours << "h ";
688  if (hours > 0 || mins > 0)
689  str << mins << "m ";
690  str << secs << "s";
691 
692  return str.str();
693  }
694  }
695 
696  IntegrableWithGlobalOrder::IntegrableWithGlobalOrder() : global_integration_order_set(false), global_integration_order(0)
697  {}
698 
700  {
701  this->global_integration_order = order;
702  this->global_integration_order_set = true;
703  }
704 
705  SettableComputationTime::SettableComputationTime() : time(0.0), time_step(0.0)
706  {
707  }
708 
710  {
711  this->time = time;
712  }
713 
714  void SettableComputationTime::set_time_step(double time_step)
715  {
716  this->time_step = time_step;
717  }
718 
719  OutputAttachable::OutputAttachable()
720  {
721  }
722 
724  {
725  return true;
726  }
727 
729  {
730  return true;
731  }
732 
734  {
735  return true;
736  }
737 
739  {
740  return true;
741  }
742 
744  {
745  return true;
746  }
747 
748  template<typename T>
749  const T& OutputAttachable::get_parameter_value(const Parameter<T>& parameter)
750  {
751  return *parameter.value;
752  }
753 
754  template<typename T>
755  T& OutputAttachable::get_parameter_value(Parameter<T>& parameter)
756  {
757  return *parameter.value;
758  }
759 
760  template<typename T>
761  void OutputAttachable::set_parameter_value(Parameter<T>& parameter, T* value)
762  {
763  parameter.value = value;
764  }
765 
766  template HERMES_API const unsigned int& OutputAttachable::get_parameter_value<unsigned int>(const Parameter<unsigned int>& parameter);
767  template HERMES_API const double& OutputAttachable::get_parameter_value<double>(const Parameter<double>& parameter);
768  template HERMES_API const bool& OutputAttachable::get_parameter_value<bool>(const Parameter<bool>& parameter);
769  template HERMES_API const std::vector<unsigned int>& OutputAttachable::get_parameter_value<std::vector<unsigned int> >(const Parameter<std::vector<unsigned int> >& parameter);
770  template HERMES_API const std::vector<double>& OutputAttachable::get_parameter_value<std::vector<double> >(const Parameter<std::vector<double> >& parameter);
771  template HERMES_API const std::vector<bool>& OutputAttachable::get_parameter_value<std::vector<bool> >(const Parameter<std::vector<bool> >& parameter);
772 
773  template HERMES_API unsigned int& OutputAttachable::get_parameter_value<unsigned int>(Parameter<unsigned int>& parameter);
774  template HERMES_API double& OutputAttachable::get_parameter_value<double>(Parameter<double>& parameter);
775  template HERMES_API bool& OutputAttachable::get_parameter_value<bool>(Parameter<bool>& parameter);
776  template HERMES_API std::vector<unsigned int>& OutputAttachable::get_parameter_value<std::vector<unsigned int> >(Parameter<std::vector<unsigned int> >& parameter);
777  template HERMES_API std::vector<double>& OutputAttachable::get_parameter_value<std::vector<double> >(Parameter<std::vector<double> >& parameter);
778  template HERMES_API std::vector<bool>& OutputAttachable::get_parameter_value<std::vector<bool> >(Parameter<std::vector<bool> >& parameter);
779 
780  template HERMES_API void OutputAttachable::set_parameter_value<unsigned int>(Parameter<unsigned int>& parameter, unsigned int* value);
781  template HERMES_API void OutputAttachable::set_parameter_value<double>(Parameter<double>& parameter, double* value);
782  template HERMES_API void OutputAttachable::set_parameter_value<bool>(Parameter<bool>& parameter, bool* value);
783  template HERMES_API void OutputAttachable::set_parameter_value<std::vector<unsigned int> >(Parameter<std::vector<unsigned int> >& parameter, std::vector<unsigned int>* value);
784  template HERMES_API void OutputAttachable::set_parameter_value<std::vector<double> >(Parameter<std::vector<double> >& parameter, std::vector<double>* value);
785  template HERMES_API void OutputAttachable::set_parameter_value<std::vector<bool> >(Parameter<std::vector<bool> >& parameter, std::vector<bool>* value);
786  }
787 }
virtual void set_verbose_callback(callbackFn callback)
Definition: mixins.cpp:557
General namespace for the Hermes library.
double last() const
Returns last measured period (in seconds).
Definition: mixins.cpp:650
Exception interface Basically a std::exception, but with a constructor with string and with print_msg...
Definition: exceptions.h:49
virtual bool isOkay() const =0
Ask if the instance is fine.
const TimeMeasurable & tick_reset()
Starts a new_ period and resets accumulated time.
Definition: mixins.cpp:660
File containing common definitions, and basic global enums etc. for HermesCommon. ...
#define HERMES_LOG_FILE_DELIM_SIZE
A size of a delimiter in a log file.
Definition: common.h:201
std::string accumulated_str() const
Returns accumulated time in human readable form.
Definition: mixins.cpp:646
virtual bool on_initialization()
Definition: mixins.cpp:723
void check() const
Method to handle the state.
Definition: mixins.cpp:27
#define HERMES_EC_ERROR
An event code: warnings.
Definition: common.h:196
Class using time measurement Can be used directly (is not abstract), so one can use e...
Definition: mixins.h:183
virtual void set_time(double time)
set time information for time-dependent problems.
Definition: mixins.cpp:709
virtual void set_global_integration_order(unsigned int order)
Definition: mixins.cpp:699
#define HERMES_EC_WARNING
An event code: warnings.
Definition: common.h:197
virtual bool on_initial_step_end()
Definition: mixins.cpp:733
#define HERMES_EC_INFO
An event code: info about results.
Definition: common.h:198
char * logFileName
Logfile name.
Definition: mixins.h:112
const std::string & name() const
Returns a name of the time period if any.
Definition: mixins.cpp:636
const TimeMeasurable & tick(TimeMeasurable::TimerPeriodTickType type=HERMES_ACCUMULATE)
Starts/ends a new_ period.
Definition: mixins.cpp:620
TimeMeasurable(const char *name=nullptr)
Constructs internal structures and starts measuring.
Definition: mixins.cpp:562
Basic matrix classes and operations.
Skip period between ticks, i.e., do not accumulate it.
Definition: mixins.h:193
void set_erase_on_beginning(bool onOff)
Sets the logFile being always erased before logging.
Definition: mixins.cpp:477
TimerPeriodTickType
Tick type. Used by the class Hermes::TimePeriod.
Definition: mixins.h:190
const TimeMeasurable & reset()
Resets accumulated time.
Definition: mixins.cpp:667
std::string last_str() const
Returns last measured period in human readable form.
Definition: mixins.cpp:655
double accumulated() const
Returns accumulated time (in seconds).
Definition: mixins.cpp:641
bool get_verbose_output() const
Returns the current value of verbose_output;.
Definition: mixins.cpp:82
void set_timestamps(bool onOff)
Sets the addition of a time stamp on each line in the log file. By default it is on.
Definition: mixins.cpp:472
virtual std::string getClassName() const =0
Get class name, for the purpose of messaging.
Mix-in classes for one functionality, for various classes to be derived from.
File containing common definitions, and basic global enums etc. for HermesCommon. ...
virtual void set_verbose_output(bool to_set)
Definition: mixins.cpp:552
Accumulate a period between ticks.
Definition: mixins.h:192
callbackFn get_verbose_callback() const
Returns the current value of verbose_callback;.
Definition: mixins.cpp:87
#define __CURRENT_FUNCTION
A platform-dependent string defining a current function.
Definition: common.h:214