23#ifndef VCL_MESH_CONTAINERS_CUSTOM_COMPONENTS_VECTOR_MAP_H
24#define VCL_MESH_CONTAINERS_CUSTOM_COMPONENTS_VECTOR_MAP_H
26#include <vclib/exceptions/mesh.h>
27#include <vclib/misc/compactness.h>
28#include <vclib/types.h>
33#include <unordered_map>
64template<
bool HasCustomComponent>
74 std::unordered_map<std::string, std::vector<std::any>> mMap;
81 mutable std::unordered_map<std::string, bool> mNeedToInitialize;
83 std::unordered_map<std::string, std::type_index> mCompType;
92 mNeedToInitialize.clear();
102 for (
auto&
p : mMap) {
103 p.second.reserve(size);
114 for (
auto&
p : mMap) {
121 if (
p.second.size() < size)
122 mNeedToInitialize.at(
p.first) =
true;
123 p.second.resize(size);
141 for (
auto&
p : mMap) {
159 template<
typename CompType>
162 std::vector<std::any>& v = mMap[name];
164 mNeedToInitialize[name] =
false;
165 mCompType.emplace(name,
typeid(
CompType));
176 mNeedToInitialize.erase(name);
177 mCompType.erase(name);
198 return (mMap.find(
compName) != mMap.end());
208 std::vector<std::string>
names;
209 names.reserve(mMap.size());
210 for (
const auto&
p : mMap)
224 template<
typename CompType>
227 std::type_index t(
typeid(
CompType));
254 template<
typename CompType>
257 std::vector<std::string>
names;
258 std::type_index t(
typeid(
CompType));
259 for (
const auto&
p : mCompType) {
278 template<
typename CompType>
283 std::vector<std::any>& v =
284 const_cast<std::vector<std::any>&
>(mMap.at(
compName));
286 if (mNeedToInitialize.at(
compName)) {
287 for (std::any&
a : v) {
291 mNeedToInitialize.at(
compName) =
false;
311 template<
typename CompType>
315 std::vector<std::any>& v = mMap.at(
compName);
317 if (mNeedToInitialize.at(
compName)) {
318 for (std::any&
a : v) {
322 mNeedToInitialize.at(
compName) =
false;
327 void importSameCustomComponentFrom(
341 template<
typename CompType>
342 void checkComponentType(
const std::string& compName)
const
344 std::type_index t(
typeid(CompType));
345 if (t != mCompType.at(compName)) {
346 throw BadCustomComponentTypeException(
347 "Expected type " + std::string(mCompType.at(compName).name()) +
348 " for " + compName +
", but was " + std::string(t.name()) +
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
const std::vector< std::any > & componentVector(const std::string &compName) const
Returns a const reference of std::vector<std::any> of the custom component with the given name and th...
Definition custom_components_vector_map.h:279
std::vector< std::string > allComponentNames() const
Returns a vector of std::string containing all the custom components, regardless the types of the cus...
Definition custom_components_vector_map.h:206
std::vector< std::string > allComponentNamesOfType() const
Returns a vector of strings of all the custom components having as type the given template argument C...
Definition custom_components_vector_map.h:255
void deleteComponent(const std::string &name)
Deletes the custom component vector with the given name. It does nothing if the element does not exis...
Definition custom_components_vector_map.h:173
bool isComponentOfType(const std::string &compName) const
Returns true if the type associated to the compName custom component is the same of the given templat...
Definition custom_components_vector_map.h:225
void compact(const std::vector< uint > &newIndices)
Compacts each custom component vector according to the given indices.
Definition custom_components_vector_map.h:139
void clear()
Removes all the custom component vectors stored in the mMap.
Definition custom_components_vector_map.h:89
std::vector< std::any > & componentVector(const std::string &compName)
Returns a reference of std::vector<std::any> of the custom component with the given name and the give...
Definition custom_components_vector_map.h:312
bool componentExists(const std::string &compName) const
Returns true if the compName exists.
Definition custom_components_vector_map.h:196
void addNewComponent(const std::string &name, uint size)
Adds a new vector of custom components having the given size, the given name and with the template ar...
Definition custom_components_vector_map.h:160
void reserve(uint size)
For each custom component vector, it reserves the given size.
Definition custom_components_vector_map.h:100
void assertComponentExists(const std::string &compName) const
Asserts that the compName component exists.
Definition custom_components_vector_map.h:185
std::type_index componentType(const std::string &compName) const
Returns the std::type_index of the type of the CustomComponent having the input name.
Definition custom_components_vector_map.h:241
void resize(uint size)
For each custom component vector, it resizes the vector to the given size.
Definition custom_components_vector_map.h:112
The CustomComponentsVectorMap class stores a map of vectors of custom components.
Definition custom_components_vector_map.h:66