OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
BaseProperty.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2011 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: 362 $ *
38  * $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $ *
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 
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 BaseProperty* clone () const = 0;
111 
112 public: // named property interface
113 
115  const std::string& name() const { return name_; }
116 
117  virtual void stats(std::ostream& _ostr) const;
118 
119 public: // I/O support
120 
122  bool persistent(void) const { return persistent_; }
123 
126  virtual void set_persistent( bool _yn ) = 0;
127 
129  virtual size_t n_elements() const = 0;
130 
132  virtual size_t element_size() const = 0;
133 
135  virtual size_t size_of() const
136  {
137  return size_of( n_elements() );
138  }
139 
142  virtual size_t size_of(size_t _n_elem) const
143  {
144  return (element_size()!=UnknownSize)
145  ? (_n_elem*element_size())
146  : UnknownSize;
147  }
148 
150  virtual size_t store( std::ostream& _ostr, bool _swap ) const = 0;
151 
155  virtual size_t restore( std::istream& _istr, bool _swap ) = 0;
156 
157 protected:
158 
159  // To be used in a derived class, when overloading set_persistent()
160  template < typename T >
161  void check_and_set_persistent( bool _yn )
162  {
163  if ( _yn && !IO::is_streamable<T>() )
164  omerr() << "Warning! Type of property value is not binary storable!\n";
165  persistent_ = IO::is_streamable<T>() && _yn;
166  }
167 
168 private:
169 
170  std::string name_;
171  bool persistent_;
172 };
173 
174 }//namespace OpenMesh
175 
176 #endif //OPENMESH_BASEPROPERTY_HH
177 
178 

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