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  explicit OpenVolumeMeshBaseProperty(const std::string& _name = "<unknown>") :
75  name_(_name), persistent_(false), handle_(-1) {
76  }
77 
79 
80  virtual ~OpenVolumeMeshBaseProperty() {}
81 
82 public:
83 
85  virtual void reserve(size_t _n) = 0;
86 
88  virtual void resize(size_t _n) = 0;
89 
91  virtual void clear() = 0;
92 
94  virtual void push_back() = 0;
95 
97  virtual void swap(size_t _i0, size_t _i1) = 0;
98 
100  virtual void delete_element(size_t _idx) = 0;
101 
103  virtual OpenVolumeMeshBaseProperty* clone() const = 0;
104 
106  const std::string& name() const {
107  return name_;
108  }
109 
110  // Function to serialize a property
111  virtual void serialize(std::ostream& /*_ostr*/) const {}
112 
113  // Function to deserialize a property
114  virtual void deserialize(std::istream& /*_istr*/) {}
115  // I/O support
116 
117  void set_persistent(bool _persistent) { persistent_ = _persistent; }
118 
119  bool persistent() const { return persistent_; }
120 
122  virtual size_t n_elements() const = 0;
123 
125  virtual size_t element_size() const = 0;
126 
128  virtual size_t size_of() const {
129  return size_of(n_elements());
130  }
131 
134  virtual size_t size_of(size_t _n_elem) const {
135  return (element_size() != UnknownSize) ? (_n_elem * element_size())
136  : UnknownSize;
137  }
138 
139  const OpenVolumeMeshHandle& handle() const { return handle_; }
140 
141  void set_handle(const OpenVolumeMeshHandle& _handle) { handle_.idx(_handle.idx()); }
142 
143 protected:
144 
146  virtual void delete_multiple_entries(const std::vector<bool>&) = 0;
147 
148 private:
149 
150  std::string name_;
151 
152  bool persistent_;
153 
154  OpenVolumeMeshHandle handle_;
155 };
156 
157 } // Namespace OpenVolumeMesh
158 
159 #endif //OPENVOLUMEMESHBASEPROPERTY_HH
160 
virtual size_t element_size() const =0
Size of one element in bytes or UnknownSize if not known.
virtual void clear()=0
Clear all elements and free memory.
virtual void push_back()=0
Extend the number of elements by one.
virtual size_t size_of(size_t _n_elem) const
virtual OpenVolumeMeshBaseProperty * clone() const =0
Return a deep copy of self.
virtual void reserve(size_t _n)=0
Reserve memory for n elements.
virtual size_t n_elements() const =0
Number of elements in property.
const std::string & name() const
Return the name of the property.
virtual void delete_element(size_t _idx)=0
Erase an element of the vector.
virtual void swap(size_t _i0, size_t _i1)=0
Let two elements swap their storage place.
virtual void resize(size_t _n)=0
Resize storage to hold n elements.
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
virtual size_t size_of() const
Return size of property in bytes.
virtual void delete_multiple_entries(const std::vector< bool > &)=0
Delete multiple entries in list.