OpenVolumeMesh
 All Classes Functions Variables Typedefs Pages
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: 198 $ *
38  * $Date: 2012-05-16 12:52:10 +0200 (Wed, 16 May 2012) $ *
39  * $LastChangedBy: kremer $ *
40  * *
41 \*===========================================================================*/
42 
43 
44 #ifndef OPENVOLUMEMESHBASEPROPERTY_HH
45 #define OPENVOLUMEMESHBASEPROPERTY_HH
46 
47 #include <limits>
48 #include <string>
49 #include <iostream>
50 #include <vector>
51 
52 #include "OpenVolumeMeshHandle.hh"
53 
54 //== CLASS DEFINITION =========================================================
55 
62 namespace OpenVolumeMesh {
63 
65 public:
66 
67  friend class ResourceManager;
68  template <class PropT, class HandleT> friend class PropertyPtr;
69 
71  static const size_t UnknownSize;
72 
73 public:
74 
75  OpenVolumeMeshBaseProperty(const std::string& _name = "<unknown>") :
76  name_(_name), persistent_(false), handle_(-1) {
77  }
78 
80  name_(_rhs.name_), persistent_(_rhs.persistent_), handle_(_rhs.handle_.idx()) {
81  }
82 
83  virtual ~OpenVolumeMeshBaseProperty() {}
84 
85 public:
86 
88  virtual void reserve(size_t _n) = 0;
89 
91  virtual void resize(size_t _n) = 0;
92 
94  virtual void clear() = 0;
95 
97  virtual void push_back() = 0;
98 
100  virtual void swap(size_t _i0, size_t _i1) = 0;
101 
103  virtual void delete_element(size_t _idx) = 0;
104 
106  virtual OpenVolumeMeshBaseProperty* clone() const = 0;
107 
109  const std::string& name() const {
110  return name_;
111  }
112 
113  // Function to serialize a property
114  virtual void serialize(std::ostream& _ostr) const {
115  _ostr << "\"" << name_ << "\"" << std::endl;
116  }
117 
118  // Function to deserialize a property
119  virtual void deserialize(std::istream& /*_istr*/) {}
120  // I/O support
121 
122  void set_persistent(bool _persistent) { persistent_ = _persistent; }
123 
124  bool persistent() const { return persistent_; }
125 
127  virtual size_t n_elements() const = 0;
128 
130  virtual size_t element_size() const = 0;
131 
133  virtual size_t size_of() const {
134  return size_of(n_elements());
135  }
136 
139  virtual size_t size_of(size_t _n_elem) const {
140  return (element_size() != UnknownSize) ? (_n_elem * element_size())
141  : UnknownSize;
142  }
143 
144  const OpenVolumeMeshHandle& handle() const { return handle_; }
145 
146  void set_handle(const OpenVolumeMeshHandle& _handle) { handle_.idx(_handle.idx()); }
147 
148 protected:
149 
151  virtual void delete_multiple_entries(const std::vector<bool>&) = 0;
152 
153 private:
154 
155  std::string name_;
156 
157  bool persistent_;
158 
159  OpenVolumeMeshHandle handle_;
160 };
161 
162 } // Namespace OpenVolumeMesh
163 
164 #endif //OPENVOLUMEMESHBASEPROPERTY_HH
165