OpenMesh
BaseProperty.hh
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2022, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 
43 
44 #ifndef OPENMESH_BASEPROPERTY_HH
45 #define OPENMESH_BASEPROPERTY_HH
46 
47 #include <string>
48 #include <OpenMesh/Core/IO/StoreRestore.hh>
50 
51 namespace OpenMesh {
52 
53 //== CLASS DEFINITION =========================================================
54 
60 class OPENMESHDLLEXPORT BaseProperty
61 {
62 public:
63 
65  static const size_t UnknownSize = size_t(-1);
66 
67 public:
68 
84  BaseProperty(const std::string& _name = "<unknown>", const std::string& _internal_type_name = "<unknown>" )
85  : name_(_name), internal_type_name_(_internal_type_name), persistent_(false)
86  {}
87 
89  BaseProperty(const BaseProperty & _rhs)
90  : name_( _rhs.name_ ), internal_type_name_(_rhs.internal_type_name_), persistent_( _rhs.persistent_ ) {}
91 
93  virtual ~BaseProperty() {}
94 
95 public: // synchronized array interface
96 
98  virtual void reserve(size_t _n) = 0;
99 
101  virtual void resize(size_t _n) = 0;
102 
104  virtual void clear() = 0;
105 
107  virtual void push_back() = 0;
108 
110  virtual void swap(size_t _i0, size_t _i1) = 0;
111 
113  virtual void copy(size_t _io, size_t _i1) = 0;
114 
116  virtual BaseProperty* clone () const = 0;
117 
118 public: // named property interface
119 
121  const std::string& name() const { return name_; }
122 
124  const std::string& internal_type_name() const { return internal_type_name_; }
125 
126  virtual void stats(std::ostream& _ostr) const;
127 
128 public: // I/O support
129 
131  bool persistent(void) const { return persistent_; }
132 
135  virtual void set_persistent( bool _yn ) = 0;
136 
138  virtual std::string get_storage_name() const = 0;
139 
141  virtual size_t n_elements() const = 0;
142 
144  virtual size_t element_size() const = 0;
145 
147  virtual size_t size_of() const
148  {
149  return size_of( n_elements() );
150  }
151 
154  virtual size_t size_of(size_t _n_elem) const
155  {
156  return (element_size()!=UnknownSize)
157  ? (_n_elem*element_size())
158  : UnknownSize;
159  }
160 
162  virtual size_t store( std::ostream& _ostr, bool _swap ) const = 0;
163 
167  virtual size_t restore( std::istream& _istr, bool _swap ) = 0;
168 
169 protected:
170 
171  // To be used in a derived class, when overloading set_persistent()
172  template < typename T >
173  void check_and_set_persistent( bool _yn )
174  {
175  if ( _yn && !IO::is_streamable<T>() )
176  omerr() << "Warning! Type of property value is not binary storable!\n";
177  persistent_ = IO::is_streamable<T>() && _yn;
178  }
179 
180 private:
181 
182  std::string name_;
183  std::string internal_type_name_;
184  bool persistent_;
185 };
186 
187 }//namespace OpenMesh
188 
189 #endif //OPENMESH_BASEPROPERTY_HH
190 
191 
This file provides the streams omlog, omout, and omerr.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:61
virtual size_t restore(std::istream &_istr, bool _swap)=0
Restore self from a binary block.
virtual void push_back()=0
Extend the number of elements by one.
BaseProperty(const std::string &_name="<unknown>", const std::string &_internal_type_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:84
virtual size_t size_of() const
Return size of property in bytes.
Definition: BaseProperty.hh:147
virtual void reserve(size_t _n)=0
Reserve memory for n elements.
const std::string & internal_type_name() const
Return internal type name of the property for type safe casting alternative to runtime information.
Definition: BaseProperty.hh:124
const std::string & name() const
Return the name of the property.
Definition: BaseProperty.hh:121
bool persistent(void) const
Returns true if the persistent flag is enabled else false.
Definition: BaseProperty.hh:131
virtual void resize(size_t _n)=0
Resize storage to hold n elements.
virtual void swap(size_t _i0, size_t _i1)=0
Let two elements swap their storage place.
virtual void clear()=0
Clear all elements and free memory.
virtual BaseProperty * clone() const =0
Return a deep copy of self.
BaseProperty(const BaseProperty &_rhs)
Copy constructor.
Definition: BaseProperty.hh:89
virtual size_t n_elements() const =0
Number of elements in property.
virtual ~BaseProperty()
Destructor.
Definition: BaseProperty.hh:93
virtual void copy(size_t _io, size_t _i1)=0
Copy one element to another.
virtual size_t store(std::ostream &_ostr, bool _swap) const =0
Store self as one binary block.
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: BaseProperty.hh:154
virtual std::string get_storage_name() const =0
returns a unique string for the type of the elements
virtual size_t element_size() const =0
Size of one element in bytes or UnknownSize if not known.
virtual void set_persistent(bool _yn)=0
Enable or disable persistency.

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .