OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
BaseProperty.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh 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  * OpenMesh 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 OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 736 $ *
38  * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 2012) $ *
39  * *
40 \*===========================================================================*/
41 
42 #ifndef OPENMESH_BASEPROPERTY_HH
43 #define OPENMESH_BASEPROPERTY_HH
44 
45 #include <string>
46 #include <OpenMesh/Core/IO/StoreRestore.hh>
48 
49 namespace OpenMesh {
50 
51 //== CLASS DEFINITION =========================================================
52 
58 class OPENMESHDLLEXPORT BaseProperty
59 {
60 public:
61 
63  static const size_t UnknownSize = size_t(-1);
64 
65 public:
66 
81  BaseProperty(const std::string& _name = "<unknown>")
82  : name_(_name), persistent_(false)
83  {}
84 
86  BaseProperty(const BaseProperty & _rhs)
87  : name_( _rhs.name_ ), persistent_( _rhs.persistent_ ) {}
88 
90  virtual ~BaseProperty() {}
91 
92 public: // synchronized array interface
93 
95  virtual void reserve(size_t _n) = 0;
96 
98  virtual void resize(size_t _n) = 0;
99 
101  virtual void clear() = 0;
102 
104  virtual void push_back() = 0;
105 
107  virtual void swap(size_t _i0, size_t _i1) = 0;
108 
110  virtual void copy(size_t _io, size_t _i1) = 0;
111 
113  virtual BaseProperty* clone () const = 0;
114 
115 public: // named property interface
116 
118  const std::string& name() const { return name_; }
119 
120  virtual void stats(std::ostream& _ostr) const;
121 
122 public: // I/O support
123 
125  bool persistent(void) const { return persistent_; }
126 
129  virtual void set_persistent( bool _yn ) = 0;
130 
132  virtual size_t n_elements() const = 0;
133 
135  virtual size_t element_size() const = 0;
136 
138  virtual size_t size_of() const
139  {
140  return size_of( n_elements() );
141  }
142 
145  virtual size_t size_of(size_t _n_elem) const
146  {
147  return (element_size()!=UnknownSize)
148  ? (_n_elem*element_size())
149  : UnknownSize;
150  }
151 
153  virtual size_t store( std::ostream& _ostr, bool _swap ) const = 0;
154 
158  virtual size_t restore( std::istream& _istr, bool _swap ) = 0;
159 
160 protected:
161 
162  // To be used in a derived class, when overloading set_persistent()
163  template < typename T >
164  void check_and_set_persistent( bool _yn )
165  {
166  if ( _yn && !IO::is_streamable<T>() )
167  omerr() << "Warning! Type of property value is not binary storable!\n";
168  persistent_ = IO::is_streamable<T>() && _yn;
169  }
170 
171 private:
172 
173  std::string name_;
174  bool persistent_;
175 };
176 
177 }//namespace OpenMesh
178 
179 #endif //OPENMESH_BASEPROPERTY_HH
180 
181 

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .