Developer Documentation

OpenVolumeMeshBaseProperty.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 #ifndef OPENVOLUMEMESHBASEPROPERTY_HH
36 #define OPENVOLUMEMESHBASEPROPERTY_HH
37
38 #include <iosfwd>
39 #include <string>
40 #include <vector>
41
42 #include "OpenVolumeMeshHandle.hh"
43
44 namespace OpenVolumeMesh {
45
52 class OpenVolumeMeshBaseProperty {
53 public:
54
55 friend class ResourceManager;
56 template <class PropT, class HandleT> friend class PropertyPtr;
57
59 static const size_t UnknownSize;
60
61 public:
62
63 explicit OpenVolumeMeshBaseProperty(
64 const std::string& _name,
65 const std::string& _internal_type_name)
66 : name_(_name),
67 internal_type_name_(_internal_type_name),
68 persistent_(false),
69 handle_(-1)
70 {}
71
72 OpenVolumeMeshBaseProperty(const OpenVolumeMeshBaseProperty& _rhs) = default;
73
74 virtual ~OpenVolumeMeshBaseProperty() {}
75
76 public:
77
79 virtual void reserve(size_t _n) = 0;
80
82 virtual void resize(size_t _n) = 0;
83
85 virtual size_t size() const = 0;
86
88 virtual void clear() = 0;
89
91 virtual void push_back() = 0;
92
94 virtual void swap(size_t _i0, size_t _i1) = 0;
95
97 virtual void delete_element(size_t _idx) = 0;
98
100 virtual OpenVolumeMeshBaseProperty* clone() const = 0;
101
103 const std::string& name() const {
104 return name_;
105 }
106
107 const std::string& internal_type_name() const {
108 return internal_type_name_;
109 }
110
111 // Function to serialize a property
112 virtual void serialize(std::ostream& /*_ostr*/) const {}
113
114 // Function to deserialize a property
115 virtual void deserialize(std::istream& /*_istr*/) {}
116 // I/O support
117
118 void set_persistent(bool _persistent) { persistent_ = _persistent; }
119
120 bool persistent() const { return persistent_; }
121
123 virtual size_t n_elements() const = 0;
124
126 virtual size_t element_size() const = 0;
127
129 virtual size_t size_of() const {
130 return size_of(n_elements());
131 }
132
135 virtual size_t size_of(size_t _n_elem) const {
136 return (element_size() != UnknownSize) ? (_n_elem * element_size())
137 : UnknownSize;
138 }
139
140 const OpenVolumeMeshHandle& handle() const { return handle_; }
141
142 void set_handle(const OpenVolumeMeshHandle& _handle) { handle_.idx(_handle.idx()); }
143
144 protected:
145
147 virtual void delete_multiple_entries(const std::vector<bool>&) = 0;
148
149 private:
150
151 std::string name_;
152 std::string internal_type_name_;
153
154 bool persistent_;
155
156 OpenVolumeMeshHandle handle_;
157 };
158
159 } // Namespace OpenVolumeMesh
160
161 #endif //OPENVOLUMEMESHBASEPROPERTY_HH
162
OpenVolumeMesh
Definition: ColorAttrib.hh:53
OpenVolumeMesh::OpenVolumeMeshBaseProperty::name
const std::string & name() const
Return the name of the property.
Definition: OpenVolumeMeshBaseProperty.hh:103
OpenVolumeMesh::ResourceManager
Definition: ResourceManager.hh:54
OpenVolumeMesh::OpenVolumeMeshBaseProperty::reserve
virtual void reserve(size_t _n)=0
Reserve memory for n elements.
OpenVolumeMesh::PropertyPtr
Definition: ForwardDeclarations.hh:12
OpenVolumeMesh::OpenVolumeMeshBaseProperty::size_of
virtual size_t size_of(size_t _n_elem) const
Definition: OpenVolumeMeshBaseProperty.hh:135
OpenVolumeMesh::OpenVolumeMeshBaseProperty::delete_multiple_entries
virtual void delete_multiple_entries(const std::vector< bool > &)=0
Delete multiple entries in list.
OpenVolumeMesh::OpenVolumeMeshBaseProperty::size
virtual size_t size() const =0
Return underlying container size.
OpenVolumeMesh::OpenVolumeMeshBaseProperty::clear
virtual void clear()=0
Clear all elements and free memory.
OpenVolumeMesh::OpenVolumeMeshBaseProperty::n_elements
virtual size_t n_elements() const =0
Number of elements in property.
OpenVolumeMesh::OpenVolumeMeshBaseProperty::delete_element
virtual void delete_element(size_t _idx)=0
Erase an element of the vector.
OpenVolumeMesh::OpenVolumeMeshHandle
Definition: OpenVolumeMeshHandle.hh:50
OpenVolumeMesh::OpenVolumeMeshBaseProperty::swap
virtual void swap(size_t _i0, size_t _i1)=0
Let two elements swap their storage place.
OpenVolumeMesh::OpenVolumeMeshBaseProperty::element_size
virtual size_t element_size() const =0
Size of one element in bytes or UnknownSize if not known.
OpenVolumeMesh::OpenVolumeMeshBaseProperty::size_of
virtual size_t size_of() const
Return size of property in bytes.
Definition: OpenVolumeMeshBaseProperty.hh:129
OpenVolumeMesh::OpenVolumeMeshBaseProperty::UnknownSize
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
Definition: OpenVolumeMeshBaseProperty.hh:59
OpenVolumeMesh::OpenVolumeMeshBaseProperty::push_back
virtual void push_back()=0
Extend the number of elements by one.
OpenVolumeMesh::OpenVolumeMeshBaseProperty::resize
virtual void resize(size_t _n)=0
Resize storage to hold n elements.
OpenVolumeMesh::OpenVolumeMeshBaseProperty
Definition: OpenVolumeMeshBaseProperty.hh:52
OpenVolumeMesh::OpenVolumeMeshBaseProperty::clone
virtual OpenVolumeMeshBaseProperty * clone() const =0
Return a deep copy of self.