OGS 6.2.0-405-gb717f6088
SecondaryVariable.cpp
Go to the documentation of this file.
1 
10 #include "SecondaryVariable.h"
11 
12 namespace ProcessLib
13 {
15  std::string const& internal_name, std::string const& external_name)
16 {
17  // TODO check for missing secondary vars.
18  // TODO check primary vars, too
20  _map_external_to_internal, external_name, internal_name,
21  "Secondary variable names must be unique.");
22 }
23 
25  std::string const& internal_name, SecondaryVariableFunctions&& fcts)
26 {
28  .emplace(std::make_pair(
29  internal_name,
30  SecondaryVariable{internal_name /* TODO change */,
31  std::move(fcts)}))
32  .second)
33  {
34  OGS_FATAL(
35  "The secondary variable with internal name `%s' has already been "
36  "set up.",
37  internal_name.c_str());
38  }
39 }
40 
41 std::map<std::string, std::string>::const_iterator
43 {
44  return _map_external_to_internal.cbegin();
45 }
46 
47 std::map<std::string, std::string>::const_iterator
49 {
50  return _map_external_to_internal.cend();
51 }
52 
54  std::string const& external_name) const
55 {
56  auto const it = _map_external_to_internal.find(external_name);
57 
58  if (it == _map_external_to_internal.cend())
59  {
60  OGS_FATAL(
61  "A secondary variable with external name '%s' has not been set up.",
62  external_name.c_str());
63  }
64 
65  auto const& internal_name = it->second;
66  auto const it2 = _configured_secondary_variables.find(internal_name);
67 
68  if (it2 == _configured_secondary_variables.end())
69  {
70  OGS_FATAL(
71  "A secondary variable with internal name '%s' has not been set up.",
72  internal_name.c_str());
73  }
74 
75  return it2->second;
76 }
77 
78 } // namespace ProcessLib
std::map< std::string, std::string >::const_iterator end() const
std::map< std::string, std::string > _map_external_to_internal
Stores information about a specific secondary variable.
void addNameMapping(std::string const &internal_name, std::string const &external_name)
Register a variable with the given internal and external names.
std::map< std::string, std::string >::const_iterator begin() const
SecondaryVariable const & get(std::string const &external_name) const
Returns the secondary variable with the given external name.
void insertIfKeyUniqueElseError(Map &map, Key const &key, Value &&value, std::string const &error_message)
Definition: Algorithm.h:104
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
void addSecondaryVariable(std::string const &internal_name, SecondaryVariableFunctions &&fcts)
std::map< std::string, SecondaryVariable > _configured_secondary_variables