00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef OPENMESH_BASEPROPERTY_HH
00043 #define OPENMESH_BASEPROPERTY_HH
00044
00045 #include <string>
00046 #include <OpenMesh/Core/IO/StoreRestore.hh>
00047 #include <OpenMesh/Core/System/omstream.hh>
00048
00049 namespace OpenMesh {
00050
00051
00052
00058 class BaseProperty
00059 {
00060 public:
00061
00063 static const size_t UnknownSize = size_t(-1);
00064
00065 public:
00066
00081 BaseProperty(const std::string& _name = "<unknown>")
00082 : name_(_name), persistent_(false)
00083 {}
00084
00086 BaseProperty(const BaseProperty & _rhs)
00087 : name_( _rhs.name_ ), persistent_( _rhs.persistent_ ) {}
00088
00090 virtual ~BaseProperty() {}
00091
00092 public:
00093
00095 virtual void reserve(size_t _n) = 0;
00096
00098 virtual void resize(size_t _n) = 0;
00099
00101 virtual void clear() = 0;
00102
00104 virtual void push_back() = 0;
00105
00107 virtual void swap(size_t _i0, size_t _i1) = 0;
00108
00110 virtual BaseProperty* clone () const = 0;
00111
00112 public:
00113
00115 const std::string& name() const { return name_; }
00116
00117 virtual void stats(std::ostream& _ostr) const;
00118
00119 public:
00120
00122 bool persistent(void) const { return persistent_; }
00123
00126 virtual void set_persistent( bool _yn ) = 0;
00127
00129 virtual size_t n_elements() const = 0;
00130
00132 virtual size_t element_size() const = 0;
00133
00135 virtual size_t size_of() const
00136 {
00137 return size_of( n_elements() );
00138 }
00139
00142 virtual size_t size_of(size_t _n_elem) const
00143 {
00144 return (element_size()!=UnknownSize)
00145 ? (_n_elem*element_size())
00146 : UnknownSize;
00147 }
00148
00150 virtual size_t store( std::ostream& _ostr, bool _swap ) const = 0;
00151
00155 virtual size_t restore( std::istream& _istr, bool _swap ) = 0;
00156
00157 protected:
00158
00159
00160 template < typename T >
00161 void check_and_set_persistent( bool _yn )
00162 {
00163 if ( _yn && !IO::is_streamable<T>() )
00164 omerr() << "Warning! Type of property value is not binary storable!\n";
00165 persistent_ = IO::is_streamable<T>() && _yn;
00166 }
00167
00168 private:
00169
00170 std::string name_;
00171 bool persistent_;
00172 };
00173
00174 }
00175
00176 #endif //OPENMESH_BASEPROPERTY_HH
00177
00178