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 /*===========================================================================*\
36  * *
37  * $Revision$ *
38  * $Date$ *
39  * $LastChangedBy$ *
40  * *
41 \*===========================================================================*/
42 
43 
44 #ifndef OPENVOLUMEMESHBASEPROPERTY_HH
45 #define OPENVOLUMEMESHBASEPROPERTY_HH
46 
47 #include <iosfwd>
48 #include <string>
49 #include <vector>
50 
51 #include "OpenVolumeMeshHandle.hh"
52 
53 //== CLASS DEFINITION =========================================================
54 
61 namespace OpenVolumeMesh {
62 
64 public:
65 
66  friend class ResourceManager;
67  template <class PropT, class HandleT> friend class PropertyPtr;
68 
70  static const size_t UnknownSize;
71 
72 public:
73 
74  OpenVolumeMeshBaseProperty(const std::string& _name = "<unknown>") :
75  name_(_name), persistent_(false), handle_(-1) {
76  }
77 
79  name_(_rhs.name_), persistent_(_rhs.persistent_), handle_(_rhs.handle_.idx()) {
80  }
81 
82  virtual ~OpenVolumeMeshBaseProperty() {}
83 
84 public:
85 
87  virtual void reserve(size_t _n) = 0;
88 
90  virtual void resize(size_t _n) = 0;
91 
93  virtual void clear() = 0;
94 
96  virtual void push_back() = 0;
97 
99  virtual void swap(size_t _i0, size_t _i1) = 0;
100 
102  virtual void delete_element(size_t _idx) = 0;
103 
105  virtual OpenVolumeMeshBaseProperty* clone() const = 0;
106 
108  const std::string& name() const {
109  return 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 
154  bool persistent_;
155 
156  OpenVolumeMeshHandle handle_;
157 };
158 
159 } // Namespace OpenVolumeMesh
160 
161 #endif //OPENVOLUMEMESHBASEPROPERTY_HH
162 
virtual size_t n_elements() const =0
Number of elements in property.
virtual size_t size_of() const
Return size of property in bytes.
virtual void push_back()=0
Extend the number of elements by one.
virtual size_t size_of(size_t _n_elem) const
virtual void swap(size_t _i0, size_t _i1)=0
Let two elements swap their storage place.
const std::string & name() const
Return the name of the property.
virtual void delete_multiple_entries(const std::vector< bool > &)=0
Delete multiple entries in list.
virtual void clear()=0
Clear all elements and free memory.
virtual void resize(size_t _n)=0
Resize storage to hold n elements.
virtual OpenVolumeMeshBaseProperty * clone() const =0
Return a deep copy of self.
virtual void reserve(size_t _n)=0
Reserve memory for n elements.
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
virtual void delete_element(size_t _idx)=0
Erase an element of the vector.
virtual size_t element_size() const =0
Size of one element in bytes or UnknownSize if not known.