| OpenMesh

BaseProperty.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, 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>
49 #include <OpenMesh/Core/System/omstream.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
83 BaseProperty(const std::string& _name = "<unknown>", const std::string& _internal_type_name = "<unknown>" )
84 : name_(_name), internal_type_name_(_internal_type_name), persistent_(false)
85 {}
86
88 BaseProperty(const BaseProperty & _rhs)
89 : name_( _rhs.name_ ), internal_type_name_(_rhs.internal_type_name_), persistent_( _rhs.persistent_ ) {}
90
92 virtual ~BaseProperty() {}
93
94 public: // synchronized array interface
95
97 virtual void reserve(size_t _n) = 0;
98
100 virtual void resize(size_t _n) = 0;
101
103 virtual void clear() = 0;
104
106 virtual void push_back() = 0;
107
109 virtual void swap(size_t _i0, size_t _i1) = 0;
110
112 virtual void copy(size_t _io, size_t _i1) = 0;
113
115 virtual BaseProperty* clone () const = 0;
116
117 public: // named property interface
118
120 const std::string& name() const { return name_; }
121
123 const std::string& internal_type_name() const { return internal_type_name_; }
124
125 virtual void stats(std::ostream& _ostr) const;
126
127 public: // I/O support
128
130 bool persistent(void) const { return persistent_; }
131
134 virtual void set_persistent( bool _yn ) = 0;
135
137 virtual size_t n_elements() const = 0;
138
140 virtual size_t element_size() const = 0;
141
143 virtual size_t size_of() const
144 {
145 return size_of( n_elements() );
146 }
147
150 virtual size_t size_of(size_t _n_elem) const
151 {
152 return (element_size()!=UnknownSize)
153 ? (_n_elem*element_size())
154 : UnknownSize;
155 }
156
158 virtual size_t store( std::ostream& _ostr, bool _swap ) const = 0;
159
163 virtual size_t restore( std::istream& _istr, bool _swap ) = 0;
164
165 protected:
166
167 // To be used in a derived class, when overloading set_persistent()
168 template < typename T >
169 void check_and_set_persistent( bool _yn )
170 {
171 if ( _yn && !IO::is_streamable<T>() )
172 omerr() << "Warning! Type of property value is not binary storable!\n";
173 persistent_ = IO::is_streamable<T>() && _yn;
174 }
175
176 private:
177
178 std::string name_;
179 std::string internal_type_name_;
180 bool persistent_;
181 };
182
183 }//namespace OpenMesh
184
185 #endif //OPENMESH_BASEPROPERTY_HH
186
187
OpenMesh::BaseProperty
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:60
OpenMesh::BaseProperty::persistent
bool persistent(void) const
Returns true if the persistent flag is enabled else false.
Definition: BaseProperty.hh:130
OpenMesh::BaseProperty::BaseProperty
BaseProperty(const std::string &_name="<unknown>", const std::string &_internal_type_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:83
OpenMesh::BaseProperty::~BaseProperty
virtual ~BaseProperty()
Destructor.
Definition: BaseProperty.hh:92
OpenMesh::BaseProperty::internal_type_name
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:123
omstream.hh
This file provides the streams omlog, omout, and omerr.
OpenMesh::BaseProperty::name
const std::string & name() const
Return the name of the property.
Definition: BaseProperty.hh:120
OpenMesh::BaseProperty::size_of
virtual size_t size_of() const
Return size of property in bytes.
Definition: BaseProperty.hh:143
OpenMesh::BaseProperty::size_of
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: BaseProperty.hh:150
OpenMesh::BaseProperty::BaseProperty
BaseProperty(const BaseProperty &_rhs)
Copy constructor.
Definition: BaseProperty.hh:88
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59