Visual Computing Library  devel
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 "base/component.h"
27#include "base/predicates.h"
28
29#include <vclib/base.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 void serialize(std::ostream& os) const { vcl::serialize(os, name()); }
104
105 void deserialize(std::istream& is) { vcl::deserialize(is, name()); }
106};
107
108/* concept */
109
121template<typename T>
122concept HasName = TB::IsDerivedFromSpecializationOfV<T, Name>;
123
124/* importFrom function */
125
126template<typename ParentElemType, bool OPT>
127template<typename Element>
128void Name<ParentElemType, OPT>::importFrom(const Element& e, bool)
129{
130 if constexpr (HasName<Element>) {
131 name() = e.name();
132 }
133}
134
135/* Detector function to check if a class has Name available */
136
148bool isNameAvailableOn(const auto& element)
149{
151}
152
153} // namespace vcl::comp
154
155#endif // VCL_MESH_COMPONENTS_NAME_H
A class representing a box in N-dimensional space.
Definition box.h:46
The Element class.
Definition element.h:75
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
A concept that checks whether a type T (that should be a Mesh) has the Name component (inherits from ...
Definition name.h:122