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