26#include "neml2/base/Registry.h"
27#include "neml2/base/NEML2Object.h"
28#include "neml2/misc/error.h"
29#include "neml2/base/OptionCollection.h"
64 static std::shared_ptr<T>
get_object_ptr(
const std::string & section,
65 const std::string & name,
86 static T &
get_object(
const std::string & section,
87 const std::string & name,
110 static void print(std::ostream &
os = std::cout);
127 std::map<std::string, std::map<std::string, std::vector<std::shared_ptr<NEML2Object>>>> _objects;
131inline std::shared_ptr<T>
133 const std::string & name,
141 if (
factory._objects.count(section) &&
factory._objects.at(section).count(name))
149 "While retrieving object named '",
153 ", additional option '",
157 "While retrieving object named '",
161 ", encountered option clash for '",
169 "Found object named ",
173 ". But dynamic cast failed. Did you specify the correct object type?");
179 for (
auto & options :
factory._all_options[section])
180 if (options.first == name)
189 "Failed to get object named ",
194 return Factory::get_object_ptr<T>(section, name,
OptionSet(),
false);
200 const std::string & name,
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
static void load(const OptionCollection &all_options)
Provide all objects' options to the factory. The factory is ready to manufacture objects after this c...
Definition Factory.cxx:39
void create_object(const std::string §ion, const OptionSet &options)
Manufacture a single NEML2Object.
Definition Factory.cxx:45
static std::vector< std::string > pipeline
The sequence which we use to manufacture objects.
Definition Factory.h:42
static std::shared_ptr< T > get_object_ptr(const std::string §ion, const std::string &name, const OptionSet &additional_options=OptionSet(), bool force_create=false)
Retrive an object pointer under the given section with the given object name.
Definition Factory.h:132
static void clear()
Destruct all the objects.
Definition Factory.cxx:73
static T & get_object(const std::string §ion, const std::string &name, const OptionSet &additional_options=OptionSet(), bool force_create=false)
Retrive an object reference under the given section with the given object name.
Definition Factory.h:199
static Factory & get()
Get the global Factory singleton.
Definition Factory.cxx:32
static void print(std::ostream &os=std::cout)
List all the manufactured objects.
Definition Factory.cxx:58
A data structure that holds options of multiple objects.
Definition OptionCollection.h:38
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
Definition CrossRef.cxx:32
void neml_assert_dbg(bool assertion, Args &&... args)
Definition error.h:85
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73