Visual Computing Library
Loading...
Searching...
No Matches
name.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_MESH_COMPONENTS_NAME_H
24#define VCL_MESH_COMPONENTS_NAME_H
25
26#include "bases/component.h"
27
28#include <vclib/concepts/mesh/components/name.h>
29#include <vclib/misc/string.h>
30
31namespace vcl::comp {
32
58template<typename ParentElemType = void, bool OPT = false>
59class Name :
60 public Component<
61 Name<ParentElemType, OPT>,
62 CompId::NAME,
63 std::string,
64 ParentElemType,
65 !std::is_same_v<ParentElemType, void>,
66 OPT>
67{
68 using Base = Component<
70 CompId::NAME,
71 std::string,
73 !std::is_same_v<ParentElemType, void>,
74 OPT>;
75
76public:
77 /* Constructors */
78
82 Name() = default;
83
84 /* Member functions */
85
90 std::string& name() { return Base::data(); }
91
96 const std::string& name() const { return Base::data(); }
97
98protected:
99 // Component interface functions
100 template<typename Element>
101 void importFrom(const Element& e, bool = true)
102 {
103 if constexpr (HasName<Element>) {
104 name() = e.name();
105 }
106 }
107
108 void serialize(std::ostream& os) const { vcl::serialize(os, name()); }
109
110 void deserialize(std::istream& is) { vcl::deserialize(is, name()); }
111};
112
113/* Detector function to check if a class has Name available */
114
127bool isNameAvailableOn(const ElementOrMeshConcept auto& element)
128{
129 return isComponentAvailableOn<CompId::NAME>(element);
130}
131
132} // namespace vcl::comp
133
134#endif // VCL_MESH_COMPONENTS_NAME_H
The Element class.
Definition element.h:57
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The Name component class represents a simple name stored as string. This class is usually used as a c...
Definition name.h:67
Name()=default
Initilizes an empty name.
std::string & name()
Returns the name of this object.
Definition name.h:90
const std::string & name() const
Returns the name of this object.
Definition name.h:96
HasName concept is satisfied only if a Element or Mesh class provides the member functions specified ...
Definition name.h:40