Developer Documentation
PropertyDefines.hh
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenVolumeMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 #pragma once
36 
37 #include <iosfwd>
38 #include <stdexcept>
39 #include <string>
40 #include <typeinfo>
41 
42 #include "Entities.hh"
43 #include "PropertyHandles.hh"
44 #include "PropertyPtr.hh"
45 
46 namespace OpenVolumeMesh {
47 
48 template <class T>
49 class OpenVolumeMeshPropertyT;
50 
51 class ResourceManager;
52 
53 template <class T>
54 const std::string typeName();
55 
56 template <> const std::string typeName<int>();
57 template <> const std::string typeName<unsigned int>();
58 template <> const std::string typeName<short>();
59 template <> const std::string typeName<long>();
60 template <> const std::string typeName<unsigned long>();
61 template <> const std::string typeName<char>();
62 template <> const std::string typeName<unsigned char>();
63 template <> const std::string typeName<bool>();
64 template <> const std::string typeName<float>();
65 template <> const std::string typeName<double>();
66 template <> const std::string typeName<std::string>();
67 template <> const std::string typeName<std::map<HalfEdgeHandle, int> >();
68 template <> const std::string typeName<std::vector<double> >();
69 template <> const std::string typeName<std::vector<VertexHandle> >();
70 template <> const std::string typeName<std::vector<HalfFaceHandle> >();
71 template <> const std::string typeName<std::vector<std::vector<HalfFaceHandle> > >();
72 
73 template<typename Entity>
74 const std::string entityTypeName();
75 
76 template <> const std::string entityTypeName<Entity::Vertex>();
77 template <> const std::string entityTypeName<Entity::HalfEdge>();
78 template <> const std::string entityTypeName<Entity::Edge>();
79 template <> const std::string entityTypeName<Entity::Face>();
80 template <> const std::string entityTypeName<Entity::HalfFace>();
81 template <> const std::string entityTypeName<Entity::Cell>();
82 template <> const std::string entityTypeName<Entity::Mesh>();
83 
84 template<typename T, typename Entity>
85 class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity> {
86 public:
87  using value_type = T;
88  using entity_type = Entity;
89  template<typename MeshT>
90  PropertyTT(MeshT *mesh, const std::string& _name, const T &_def = T())
91  : PropertyTT(std::move(mesh->template request_property<T, Entity>(_name, _def)))
92  {}
94  PropertyTT(const std::string& _name, const std::string& _internal_type_name, ResourceManager& _resMan, PropertyHandleT _handle, const T &_def = T());
95  ~PropertyTT() override = default;
96  BaseProperty* clone(ResourceManager &_resMan, OpenVolumeMeshHandle _handle) const override;
97  const std::string entityType() const override { return entityTypeName<Entity>(); }
98  const std::string typeNameWrapper() const override { return typeName<T>(); }
99 private:
100  PropertyTT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, PropertyHandleT _handle);
101 };
102 
103 template<typename T> using VertexPropertyT = PropertyTT<T, Entity::Vertex>;
104 template<typename T> using EdgePropertyT = PropertyTT<T, Entity::Edge>;
105 template<typename T> using HalfEdgePropertyT = PropertyTT<T, Entity::HalfEdge>;
106 template<typename T> using FacePropertyT = PropertyTT<T, Entity::Face>;
107 template<typename T> using HalfFacePropertyT = PropertyTT<T, Entity::HalfFace>;
108 template<typename T> using CellPropertyT = PropertyTT<T, Entity::Cell>;
109 template<typename T> using MeshPropertyT = PropertyTT<T, Entity::Mesh>;
110 
111 
112 } // Namespace OpenVolumeMesh
113 
114 #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYDEFINEST_CC)
115 #include "PropertyDefinesT_impl.hh"
116 #endif
The property handle, use it to access the properties.
Definition: Properties.hh:67
STL namespace.
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
Definition: Types.cc:154