OGS
ProjectData.h File Reference
#include <map>
#include <memory>
#include <optional>
#include <string>
#include "BaseLib/ConfigTree.h"
#include "ChemistryLib/ChemicalSolverInterface.h"
#include "MaterialLib/MPL/Medium.h"
#include "MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h"
#include "ParameterLib/CoordinateSystem.h"
#include "ParameterLib/Parameter.h"
#include "ProcessLib/Process.h"
#include "ProcessLib/ProcessVariable.h"
Include dependency graph for ProjectData.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ProjectData
 

Namespaces

 MeshLib
 
 NumLib
 
 ProcessLib
 

Functions

std::vector< int > splitMaterialIdString (std::string const &material_id_string)
 

Function Documentation

◆ splitMaterialIdString()

std::vector<int> splitMaterialIdString ( std::string const &  material_id_string)

Parses a comma separated list of integers. Such lists occur in the medium definition in the OGS prj file. Error messages in this function refer to this specific purpose.

Definition at line 1199 of file ProjectData.cpp.

1200 {
1201  auto const material_ids_strings =
1202  BaseLib::splitString(material_id_string, ',');
1203 
1204  std::vector<int> material_ids;
1205  for (auto& mid_str : material_ids_strings)
1206  {
1207  std::size_t num_chars_processed = 0;
1208  int material_id;
1209  try
1210  {
1211  material_id = std::stoi(mid_str, &num_chars_processed);
1212  }
1213  catch (std::invalid_argument&)
1214  {
1215  OGS_FATAL(
1216  "Could not parse material ID from '{}' to a valid "
1217  "integer.",
1218  mid_str);
1219  }
1220  catch (std::out_of_range&)
1221  {
1222  OGS_FATAL(
1223  "Could not parse material ID from '{}'. The integer value "
1224  "of the given string exceeds the permitted range.",
1225  mid_str);
1226  }
1227 
1228  if (num_chars_processed != mid_str.size())
1229  {
1230  // Not the whole string has been parsed. Check the rest.
1231  if (auto const it = std::find_if_not(
1232  begin(mid_str) + num_chars_processed, end(mid_str),
1233  [](unsigned char const c) { return std::isspace(c); });
1234  it != end(mid_str))
1235  {
1236  OGS_FATAL(
1237  "Could not parse material ID from '{}'. Please "
1238  "separate multiple material IDs by comma only. "
1239  "Invalid character: '{}' at position {}.",
1240  mid_str, *it, distance(begin(mid_str), it));
1241  }
1242  }
1243 
1244  material_ids.push_back(material_id);
1245  };
1246 
1247  return material_ids;
1248 }
#define OGS_FATAL(...)
Definition: Error.h:26
std::vector< std::string > splitString(std::string const &str)
Definition: StringTools.cpp:28

References MaterialPropertyLib::c, OGS_FATAL, and BaseLib::splitString().

Referenced by ProjectData::parseMedia().