NEML2 1.4.0
Loading...
Searching...
No Matches
Registry.cxx
1// Copyright 2023, UChicago Argonne, LLC
2// All Rights Reserved
3// Software Name: NEML2 -- the New Engineering material Model Library, version 2
4// By: Argonne National Laboratory
5// OPEN SOURCE LICENSE (MIT)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23// THE SOFTWARE.
24
25#include "neml2/base/Registry.h"
26#include "neml2/base/NEML2Object.h"
27
28namespace neml2
29{
30Registry &
36
37std::map<std::string, OptionSet>
39{
40 auto & reg = get();
41 return reg._expected_options;
42}
43
45Registry::expected_options(const std::string & name)
46{
47 auto & reg = get();
49 reg._expected_options.count(name) > 0,
50 name,
51 " is not a registered object. Did you forget to register it with register_NEML2_object?");
52 return reg._expected_options.at(name);
53}
54
55std::string
56Registry::syntax_type(const std::string & type)
57{
58 auto & reg = get();
59 return reg._syntax_type[type];
60}
61
63Registry::builder(const std::string & name)
64{
65 auto & reg = get();
67 reg._objects.count(name) > 0,
68 name,
69 " is not a registered object. Did you forget to register it with register_NEML2_object?");
70 return reg._objects.at(name);
71}
72
73void
74Registry::add_inner(const std::string & name,
75 const std::string & type,
76 const OptionSet & options,
78{
79 auto & reg = get();
80 neml_assert(reg._expected_options.count(name) == 0 && reg._objects.count(name) == 0,
81 "Duplicate registration found. Object named ",
82 name,
83 " is being registered multiple times.");
84
85 reg._expected_options[name] = options;
86 reg._objects[name] = build_ptr;
87 reg._syntax_type[name] = type;
88}
89} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
Definition Registry.h:52
static std::map< std::string, OptionSet > expected_options()
Return the expected options of all registered classs.
Definition Registry.cxx:38
static Registry & get()
Get the global Registry singleton.
Definition Registry.cxx:31
static BuildPtr builder(const std::string &name)
Return the build method pointer of a specific registered class.
Definition Registry.cxx:63
static std::string syntax_type(const std::string &type)
Return the syntax type (what appears in the input file) given a registered object's type.
Definition Registry.cxx:56
Definition CrossRef.cxx:32
std::shared_ptr< NEML2Object >(*)(const OptionSet &options) BuildPtr
Definition Registry.h:42
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73