oomph::DebugHelpers Namespace Reference

Functions

std::string debug_string (const std::string &filename, const int &line, const bool &make_new_line)
 

Detailed Description

Namespace for debugging helpers. Currently only contains a function to prett-ify file name and line numbers (in red) to use when debugging. Makes it easy to identify where a std::cout statement was called.

Function Documentation

◆ debug_string()

std::string oomph::DebugHelpers::debug_string ( const std::string &  filename,
const int line,
const bool make_new_line 
)

Return the concaternation of the initials of the input file name and line number. The make_new_line flag indicates whether the string starts with a "\n", i.e. a new line

Return the concaternation of the initials of the input file name and line number. The make_new_line flag indicates whether the string starts on a new line or not

95  {
96  // Make a string
98 
99  // Temporary storage for the filename which can be edited
100  std::string file = filename;
101 
102  // The delimeter
103  std::string delimiter = "_";
104 
105  // Posiiton of the delimiter
106  size_t pos = 0;
107 
108  // The string before the delimiter
109  std::string token;
110 
111  // Get the filename (gets rid of e.g. ./ before filename)
112  while ((pos = file.find("/")) != std::string::npos)
113  {
114  // Get the string before the delimiter
115  token = file.substr(0, pos);
116 
117  // Erase the string before the delimeter
118  file = file.substr(pos + delimiter.length());
119  }
120 
121  // While we can find delimeters
122  while ((pos = file.find(delimiter)) != std::string::npos)
123  {
124  // Get the string before the delimiter
125  token = file.substr(0, pos);
126 
127  // Output the string
128  debug_string += toupper(token.at(0));
129 
130  // Erase the delimeter
131  file = file.substr(pos + delimiter.length());
132  }
133 
134  // Output the string
135  debug_string += toupper(file.at(0));
136 
137  // String stream
138  std::ostringstream debug_stream;
139 
140  // If they want a new line
141  if (make_new_line)
142  {
143  // Add a newline string
144  debug_stream << "\n";
145  }
146 
147  // Create debug string
148  debug_stream << "\033[1;31m" << debug_string << line << ":\033[0m ";
149 
150  // Return the string
151  return debug_stream.str();
152  } // End of create_debug_string
string filename
Definition: MergeRestartFiles.py:39
line
Definition: calibrate.py:103
std::string debug_string(const std::string &filename, const int &line, const bool &make_new_line)
Definition: oomph_utilities.cc:92
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References MergeRestartFiles::filename, calibrate::line, and oomph::Global_string_for_annotation::string().