libROM  v1.0
Data-driven physical simulation library
Utilities.h
1 
11 // Description: Utility functions for error reporting, etc.
12 
13 #ifndef included_utilities_h
14 #define included_utilities_h
15 
16 #include "CAROM_config.h"
17 #include <iostream>
18 #include <sstream>
19 #include <string>
20 
21 namespace CAROM {
22 
27 #define CAROM_NULL_USE(variable) \
28  do { \
29  if (0) { char* temp = (char *)&variable; temp++; } \
30  } while (0)
31 
37 #define CAROM_ERROR(X) \
38  do { \
39  std::ostringstream os; \
40  os << X << std::ends; \
41  CAROM::Utilities::abort(os.str(), __FILE__, __LINE__); \
42  } while (0)
43 
49 #define CAROM_VERIFY(EXP) \
50  do { \
51  if (!(EXP)) { \
52  std::ostringstream os; \
53  os << "Failed verify: " << # EXP << std::ends; \
54  CAROM::Utilities::abort(os.str(), __FILE__, __LINE__); \
55  } \
56  } while (0)
57 
63 #ifdef DEBUG_CHECK_ASSERTIONS
64 
65 #define CAROM_ASSERT(EXP) \
66  do { \
67  if (!(EXP)) { \
68  std::ostringstream os; \
69  os << "Failed assertion: " << # EXP << std::ends; \
70  CAROM::Utilities::abort(os.str(), __FILE__, __LINE__); \
71  } \
72  } while (0)
73 #else
74 
75 /*
76  * No assertion checking
77  */
78 #define CAROM_ASSERT(EXP)
79 
80 #endif
81 
86 struct Utilities
87 {
97  static void
98  abort(
99  const std::string& message,
100  const std::string& filename,
101  int line);
102 
112  static std::string
114  int processorID);
115 
123  static bool
124  file_exist(
125  const std::string& filename);
126 };
127 
128 }
129 
130 #endif
static std::string processorToString(int processorID)
Converts a processor ID to a string. Use this to ensure same width is used when converting a processo...
Definition: Utilities.cpp:55
static bool file_exist(const std::string &filename)
Verifies if a file exists.
Definition: Utilities.cpp:70
static void abort(const std::string &message, const std::string &filename, int line)
Cleanly ends the program when something horrible happened and prints a message about what took place....
Definition: Utilities.cpp:25