OGS
Properties.cpp
Go to the documentation of this file.
1
13#include "Properties.h"
14
15namespace MeshLib
16{
17void Properties::removePropertyVector(std::string_view name)
18{
19 auto it(_properties.find(std::string(name)));
20 if (it == _properties.end())
21 {
22 WARN("A property of the name '{:s}' does not exist.", name);
23 return;
24 }
25 delete it->second;
26 _properties.erase(it);
27}
28
29bool Properties::hasPropertyVector(std::string_view name) const
30{
31 return _properties.find(std::string(name)) != _properties.end();
32}
33
34std::vector<std::string> Properties::getPropertyVectorNames() const
35{
36 std::vector<std::string> names;
37 std::transform(_properties.begin(), _properties.end(),
38 std::back_inserter(names),
39 [](auto const& pair) { return std::string(pair.first); });
40 return names;
41}
42
43std::vector<std::string> Properties::getPropertyVectorNames(
45{
46 std::vector<std::string> names;
47 for (auto p : _properties)
48 {
49 if (p.second->getMeshItemType() == t)
50 {
51 names.push_back(std::string(p.first));
52 }
53 }
54 return names;
55}
56
58 std::vector<std::size_t> const& exclude_elem_ids,
59 std::vector<std::size_t> const& exclude_node_ids) const
60{
61 Properties exclude_copy;
62 for (auto name_vector_pair : _properties)
63 {
64 if (name_vector_pair.second->getMeshItemType() == MeshItemType::Cell)
65 {
66 exclude_copy._properties.insert(std::make_pair(
67 name_vector_pair.first,
68 name_vector_pair.second->clone(exclude_elem_ids)));
69 }
70 else if (name_vector_pair.second->getMeshItemType() ==
72 {
73 exclude_copy._properties.insert(std::make_pair(
74 name_vector_pair.first,
75 name_vector_pair.second->clone(exclude_node_ids)));
76 }
77 }
78 return exclude_copy;
79}
80
82 std::vector<MeshItemType> const& exclude_mesh_item_types) const
83{
84 Properties new_properties;
85 for (auto name_vector_pair : _properties)
86 {
87 if (std::find(exclude_mesh_item_types.begin(),
88 exclude_mesh_item_types.end(),
89 name_vector_pair.second->getMeshItemType()) !=
90 exclude_mesh_item_types.end())
91 {
92 continue;
93 }
94
95 std::vector<std::size_t> const exclude_positions{};
96 new_properties._properties.insert(
97 std::make_pair(name_vector_pair.first,
98 name_vector_pair.second->clone(exclude_positions)));
99 }
100 return new_properties;
101}
102
104 : _properties(properties._properties)
105{
106 for (auto& name_vector_pair : _properties)
107 {
108 PropertyVectorBase* t(name_vector_pair.second->clone({}));
109 name_vector_pair.second = t;
110 }
111}
112
114{
115 if (&properties == this)
116 {
117 return *this;
118 }
119
120 _properties = properties._properties;
121 std::vector<std::size_t> exclude_positions;
122 for (auto& name_vector_pair : _properties)
123 {
125 name_vector_pair.second->clone(exclude_positions));
126 name_vector_pair.second = t;
127 }
128
129 return *this;
130}
131
133{
134 for (auto name_vector_pair : _properties)
135 {
136 delete name_vector_pair.second;
137 }
138}
139
140std::map<std::string, PropertyVectorBase*>::const_iterator Properties::begin()
141 const
142{
143 return _properties.cbegin();
144}
145
146std::map<std::string, PropertyVectorBase*>::const_iterator Properties::end()
147 const
148{
149 return _properties.cend();
150}
151
152std::map<std::string, PropertyVectorBase*>::iterator Properties::begin()
153{
154 return _properties.begin();
155}
156
157std::map<std::string, PropertyVectorBase*>::iterator Properties::end()
158{
159 return _properties.end();
160}
161
162std::map<std::string, PropertyVectorBase*>::size_type Properties::size() const
163{
164 return _properties.size();
165}
166
167std::map<std::string, PropertyVectorBase*>::size_type Properties::size(
168 MeshItemType const mesh_item_type) const
169{
170 return count_if(begin(), end(),
171 [&](auto const p)
172 { return p.second->getMeshItemType() == mesh_item_type; });
173}
174
175} // end namespace MeshLib
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Definition of the class Properties that implements a container of properties.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition Properties.h:36
std::vector< std::string > getPropertyVectorNames() const
std::map< std::string, PropertyVectorBase * > _properties
Definition Properties.h:173
bool hasPropertyVector(std::string_view name) const
std::map< std::string, PropertyVectorBase * >::size_type size() const
Properties excludeCopyProperties(std::vector< std::size_t > const &exclude_elem_ids, std::vector< std::size_t > const &exclude_node_ids) const
std::map< std::string, PropertyVectorBase * >::const_iterator begin() const
std::map< std::string, PropertyVectorBase * >::const_iterator end() const
void removePropertyVector(std::string_view name)
Properties & operator=(Properties const &properties)
MeshItemType
Definition Location.h:21