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