OGS 6.2.2-330-gf48c72f61.dirty.20200225212913
SecondaryVariable.cpp
Go to the documentation of this file.
1 
11 #include "SecondaryVariable.h"
12 
13 namespace ProcessLib
14 {
16  std::string const& internal_name, std::string const& external_name)
17 {
18  // TODO check for missing secondary vars.
19  // TODO check primary vars, too
21  _map_external_to_internal, external_name, internal_name,
22  "Secondary variable names must be unique.");
23 }
24 
26  std::string const& internal_name, SecondaryVariableFunctions&& fcts)
27 {
29  .emplace(std::make_pair(
30  internal_name,
31  SecondaryVariable{internal_name /* TODO change */,
32  std::move(fcts)}))
33  .second)
34  {
35  OGS_FATAL(
36  "The secondary variable with internal name `%s' has already been "
37  "set up.",
38  internal_name.c_str());
39  }
40 }
41 
42 std::map<std::string, std::string>::const_iterator
44 {
45  return _map_external_to_internal.cbegin();
46 }
47 
48 std::map<std::string, std::string>::const_iterator
50 {
51  return _map_external_to_internal.cend();
52 }
53 
55  std::string const& external_name) const
56 {
57  auto const it = _map_external_to_internal.find(external_name);
58 
59  if (it == _map_external_to_internal.cend())
60  {
61  OGS_FATAL(
62  "A secondary variable with external name '%s' has not been set up.",
63  external_name.c_str());
64  }
65 
66  auto const& internal_name = it->second;
67  auto const it2 = _configured_secondary_variables.find(internal_name);
68 
69  if (it2 == _configured_secondary_variables.end())
70  {
71  OGS_FATAL(
72  "A secondary variable with internal name '%s' has not been set up.",
73  internal_name.c_str());
74  }
75 
76  return it2->second;
77 }
78 
79 } // 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:105
#define OGS_FATAL(fmt,...)
Definition: Error.h:64
void addSecondaryVariable(std::string const &internal_name, SecondaryVariableFunctions &&fcts)
std::map< std::string, SecondaryVariable > _configured_secondary_variables