Debian Codegraph @

packages/seacas/libraries/ioss/src/Ioss_PropertyManager.C

raw
1 // Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "Ioss_Property.h"
8 #include "Ioss_PropertyManager.h"
9 #include "Ioss_Utils.h"
10 #include <cstddef>
11 #include <fmt/ostream.h>
12 #include <string>
13
14 #include "Ioss_CodeTypes.h"
15 #include "robin_hash.h"
16
17 /** \brief Add a property to the property manager.
18 *
19 * \param[in] new_prop The property to add.
20 */
21 void Ioss::PropertyManager::add(const Ioss::Property &new_prop)
22 {
23 IOSS_FUNC_ENTER(m_);
24 auto iter = m_properties.find(new_prop.get_name());
25 if (iter != m_properties.end()) {
26 m_properties.erase(iter);
27 }
28 m_properties.emplace(new_prop.get_name(), new_prop);
29 }
30
31 /** \brief Checks if a property exists in the database.
32 *
33 * \param[in] property_name The property to check
34 * \returns True if the property exists, false otherwise.
35 */
36 bool Ioss::PropertyManager::exists(const std::string &property_name) const
37 {
38 return (m_properties.find(property_name) != m_properties.end());
39 }
40
41 /** \brief Get a property object from the property manager.
42 *
43 * \param[in] property_name The name of the property to get.
44 * \returns The property object.
45 */
46 Ioss::Property Ioss::PropertyManager::get(const std::string &property_name) const
47 {
48 IOSS_FUNC_ENTER(m_);
49 auto iter = m_properties.find(property_name);
50 if (iter == m_properties.end()) {
51 std::ostringstream errmsg;
52 fmt::print(errmsg, "ERROR: Could not find property '{}'\n", property_name);
53 IOSS_ERROR(errmsg);
54 }
55 return (*iter).second;
56 }
57
58 /** \brief Get an optional property object from the property manager.
59 *
60 * \param[in] property_name The name of the property to get.
61 * \param[in] optional_value The value to return if the property does not exist.
62 * \returns The property object.
63 */
64 int Ioss::PropertyManager::get_optional(const std::string &property_name, int optional_value) const
65 {
66 IOSS_FUNC_ENTER(m_);
67 auto iter = m_properties.find(property_name);
68 if (iter == m_properties.end()) {
69 return optional_value;
70 }
71 return (*iter).second.get_int();
72 }
73
74 int64_t Ioss::PropertyManager::get_optional(const std::string &property_name,
75 int64_t optional_value) const
76 {
77 IOSS_FUNC_ENTER(m_);
78 auto iter = m_properties.find(property_name);
79 if (iter == m_properties.end()) {
80 return optional_value;
81 }
82 return (*iter).second.get_int();
83 }
84
85 double Ioss::PropertyManager::get_optional(const std::string &property_name,
86 double optional_value) const
87 {
88 IOSS_FUNC_ENTER(m_);
89 auto iter = m_properties.find(property_name);
90 if (iter == m_properties.end()) {
91 return optional_value;
92 }
93 return (*iter).second.get_real();
94 }
95
96 std::string Ioss::PropertyManager::get_optional(const std::string &property_name,
97 const std::string &optional_value) const
98 {
99 IOSS_FUNC_ENTER(m_);
100 auto iter = m_properties.find(property_name);
101 if (iter == m_properties.end()) {
102 return optional_value;
103 }
104 return (*iter).second.get_string();
105 }
106
107 /** \brief Remove a property from the property manager.
108 *
109 * Assumes that the property with the given name already exists in the property manager.
110 *
111 * \param[in] property_name The name of the property to remove.
112 *
113 */
114 void Ioss::PropertyManager::erase(const std::string &property_name)
115 {
116 IOSS_FUNC_ENTER(m_);
117 auto iter = m_properties.find(property_name);
118 if (iter != m_properties.end()) {
119 m_properties.erase(iter);
120 }
121 }
122
123 /** \brief Get the names of all properties in the property manager
124 *
125 * \returns All the property names in the property manager.
126 */
127 Ioss::NameList Ioss::PropertyManager::describe() const
128 {
129 Ioss::NameList names;
130 describe(&names);
131 return names;
132 }
133
134 /** \brief Get the names of all properties in the property manager
135 *
136 * \param[out] names All the property names in the property manager.
137 * \returns The number of properties extracted from the property manager.
138 */
139 int Ioss::PropertyManager::describe(NameList *names) const
140 {
141 IOSS_FUNC_ENTER(m_);
142 int the_count = 0;
143 PropMapType::const_iterator I;
144 for (I = m_properties.begin(); I != m_properties.end(); ++I) {
145 names->push_back((*I).first);
146 the_count++;
147 }
148 return the_count;
149 }
150
151 /** \brief Get the names of all properties in the property manager that have the origin `origin`
152 *
153 * \param[in] origin The origin of the property: IMPLICIT, EXTERNAL, ATTRIBUTE
154 * \returns The number of properties extracted from the property manager.
155 */
156 Ioss::NameList Ioss::PropertyManager::describe(Ioss::Property::Origin origin) const
157 {
158 Ioss::NameList names;
159 describe(origin, &names);
160 return names;
161 }
162
163 /** \brief Get the names of all properties in the property manager that have the origin `origin`
164 *
165 * \param[in] origin The origin of the property: IMPLICIT, EXTERNAL, ATTRIBUTE
166 * \param[out] names All the property names in the property manager.
167 * \returns The number of properties extracted from the property manager.
168 */
169 int Ioss::PropertyManager::describe(Ioss::Property::Origin origin, NameList *names) const
170 {
171 IOSS_FUNC_ENTER(m_);
172 int the_count = 0;
173 PropMapType::const_iterator I;
174 for (I = m_properties.begin(); I != m_properties.end(); ++I) {
175 if ((*I).second.get_origin() == origin) {
176 names->push_back((*I).first);
177 the_count++;
178 }
179 }
180 return the_count;
181 }
182
183 /** Get the number of properties in the property manager
184 *
185 * \returns The number of properties in the property manager.
186 */
187 size_t Ioss::PropertyManager::count() const
188 {
189 IOSS_FUNC_ENTER(m_);
190 return m_properties.size();
191 }