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 #include <map>
42 
43 #include "Entities.hh"
44 #include "PropertyHandles.hh"
45 #include "PropertyPtr.hh"
46 
47 namespace OpenVolumeMesh {
48 
49 template <class T>
50 class OpenVolumeMeshPropertyT;
51 
52 class ResourceManager;
53 
54 template <class T>
55 const std::string typeName();
56 
57 template <> OVM_EXPORT const std::string typeName<int>();
58 template <> OVM_EXPORT const std::string typeName<unsigned int>();
59 template <> OVM_EXPORT const std::string typeName<short>();
60 template <> OVM_EXPORT const std::string typeName<long>();
61 template <> OVM_EXPORT const std::string typeName<unsigned long>();
62 template <> OVM_EXPORT const std::string typeName<char>();
63 template <> OVM_EXPORT const std::string typeName<unsigned char>();
64 template <> OVM_EXPORT const std::string typeName<bool>();
65 template <> OVM_EXPORT const std::string typeName<float>();
66 template <> OVM_EXPORT const std::string typeName<double>();
67 template <> OVM_EXPORT const std::string typeName<std::string>();
68 template <> OVM_EXPORT const std::string typeName<std::map<HalfEdgeHandle, int> >();
69 template <> OVM_EXPORT const std::string typeName<std::vector<double> >();
70 template <> OVM_EXPORT const std::string typeName<std::vector<VertexHandle> >();
71 template <> OVM_EXPORT const std::string typeName<std::vector<HalfFaceHandle> >();
72 template <> OVM_EXPORT const std::string typeName<std::vector<std::vector<HalfFaceHandle> > >();
73 
74 template<typename Entity>
75 const std::string entityTypeName();
76 
77 template <> OVM_EXPORT const std::string entityTypeName<Entity::Vertex>();
78 template <> OVM_EXPORT const std::string entityTypeName<Entity::HalfEdge>();
79 template <> OVM_EXPORT const std::string entityTypeName<Entity::Edge>();
80 template <> OVM_EXPORT const std::string entityTypeName<Entity::Face>();
81 template <> OVM_EXPORT const std::string entityTypeName<Entity::HalfFace>();
82 template <> OVM_EXPORT const std::string entityTypeName<Entity::Cell>();
83 template <> OVM_EXPORT const std::string entityTypeName<Entity::Mesh>();
84 
85 template<typename T, typename Entity>
86 class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity> {
87 public:
88  using value_type = T;
89  using entity_type = Entity;
90  template<typename MeshT>
91  PropertyTT(MeshT *mesh, const std::string& _name, const T &_def = T())
92  : PropertyTT(std::move(mesh->template request_property<T, Entity>(_name, _def)))
93  {}
94  PropertyTT (const PropertyTT<T, Entity>&) = default;
95  PropertyTT (PropertyTT<T,Entity>&&) = default;
96  // copy assignment can be confusing for users - instead of the property contents
97  // being assigned, the PropertyPtr just points to the rhs now.
98  PropertyTT<T, Entity>& operator=(const PropertyTT<T, Entity>&) = delete;
99  PropertyTT<T, Entity>& operator=(PropertyTT<T, Entity>&&) = default;
100 
102  PropertyTT(const std::string& _name, const std::string& _internal_type_name, ResourceManager& _resMan, PropertyHandleT _handle, const T &_def = T());
103  ~PropertyTT() override = default;
104  BaseProperty* clone(ResourceManager &_resMan, OpenVolumeMeshHandle _handle) const override;
105  const std::string entityType() const override { return entityTypeName<Entity>(); }
106  const std::string typeNameWrapper() const override { return typeName<T>(); }
107 private:
108  PropertyTT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, PropertyHandleT _handle);
109 };
110 
111 template<typename T> using VertexPropertyT = PropertyTT<T, Entity::Vertex>;
112 template<typename T> using EdgePropertyT = PropertyTT<T, Entity::Edge>;
113 template<typename T> using HalfEdgePropertyT = PropertyTT<T, Entity::HalfEdge>;
114 template<typename T> using FacePropertyT = PropertyTT<T, Entity::Face>;
115 template<typename T> using HalfFacePropertyT = PropertyTT<T, Entity::HalfFace>;
116 template<typename T> using CellPropertyT = PropertyTT<T, Entity::Cell>;
117 template<typename T> using MeshPropertyT = PropertyTT<T, Entity::Mesh>;
118 
119 
120 } // Namespace OpenVolumeMesh
121 
122 #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYDEFINEST_CC)
123 #include "PropertyDefinesT_impl.hh"
124 #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