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 #include "OpenVolumeMesh/Config/Export.hh"
44 
45 namespace OpenVolumeMesh {
46 
53 class OVM_EXPORT OpenVolumeMeshBaseProperty {
54 public:
55 
56  friend class ResourceManager;
57  template <class PropT, class HandleT> friend class PropertyPtr;
58 
60  static const size_t UnknownSize;
61 
62 public:
63 
65  const std::string& _name,
66  const std::string& _internal_type_name)
67  : name_(_name),
68  internal_type_name_(_internal_type_name),
69  persistent_(false),
70  handle_(-1)
71  {}
72 
74 
75  virtual ~OpenVolumeMeshBaseProperty() {}
76 
77 public:
78 
80  virtual void reserve(size_t _n) = 0;
81 
83  virtual void resize(size_t _n) = 0;
84 
86  virtual size_t size() const = 0;
87 
89  virtual void clear() = 0;
90 
92  virtual void push_back() = 0;
93 
95  virtual void swap(size_t _i0, size_t _i1) = 0;
96 
98  virtual void delete_element(size_t _idx) = 0;
99 
101  virtual OpenVolumeMeshBaseProperty* clone() const = 0;
102 
104  const std::string& name() const {
105  return name_;
106  }
107 
108  const std::string& internal_type_name() const {
109  return internal_type_name_;
110  }
111 
112  // Function to serialize a property
113  virtual void serialize(std::ostream& /*_ostr*/) const {}
114 
115  // Function to deserialize a property
116  virtual void deserialize(std::istream& /*_istr*/) {}
117  // I/O support
118 
119  void set_persistent(bool _persistent) { persistent_ = _persistent; }
120 
121  bool persistent() const { return persistent_; }
122 
124  virtual size_t n_elements() const = 0;
125 
127  virtual size_t element_size() const = 0;
128 
130  virtual size_t size_of() const {
131  return size_of(n_elements());
132  }
133 
136  virtual size_t size_of(size_t _n_elem) const {
137  return (element_size() != UnknownSize) ? (_n_elem * element_size())
138  : UnknownSize;
139  }
140 
141  const OpenVolumeMeshHandle& handle() const { return handle_; }
142 
143  void set_handle(const OpenVolumeMeshHandle& _handle) { handle_.idx(_handle.idx()); }
144 
145 protected:
146 
148  virtual void delete_multiple_entries(const std::vector<bool>&) = 0;
149 
150 private:
151 
152  std::string name_;
153  std::string internal_type_name_;
154 
155  bool persistent_;
156 
157  OpenVolumeMeshHandle handle_;
158 };
159 
160 } // Namespace OpenVolumeMesh
161 
162 #endif //OPENVOLUMEMESHBASEPROPERTY_HH
163 
const std::string & name() const
Return the name of the property.
virtual size_t size_of(size_t _n_elem) const
virtual size_t size_of() const
Return size of property in bytes.
static const size_t UnknownSize
Indicates an error when a size is returned by a member.