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 #ifndef OPENMESH_BASEPROPERTY_HH
00027 #define OPENMESH_BASEPROPERTY_HH
00028
00029 #include <string>
00030 #include <OpenMesh/Core/IO/StoreRestore.hh>
00031 #include <OpenMesh/Core/System/omstream.hh>
00032
00033 namespace OpenMesh {
00034
00035
00036
00042 class BaseProperty
00043 {
00044 public:
00045
00047 static const size_t UnknownSize = size_t(-1);
00048
00049 public:
00050
00065 BaseProperty(const std::string& _name = "<unknown>")
00066 : name_(_name), persistent_(false)
00067 {}
00068
00070 BaseProperty(const BaseProperty & _rhs)
00071 : name_( _rhs.name_ ), persistent_( _rhs.persistent_ ) {}
00072
00074 virtual ~BaseProperty() {}
00075
00076 public:
00077
00079 virtual void reserve(size_t _n) = 0;
00080
00082 virtual void resize(size_t _n) = 0;
00083
00085 virtual void push_back() = 0;
00086
00088 virtual void swap(size_t _i0, size_t _i1) = 0;
00089
00091 virtual BaseProperty* clone () const = 0;
00092
00093 public:
00094
00096 const std::string& name() const { return name_; }
00097
00098 virtual void stats(std::ostream& _ostr) const;
00099
00100 public:
00101
00103 bool persistent(void) const { return persistent_; }
00104
00107 virtual void set_persistent( bool _yn ) = 0;
00108
00110 virtual size_t n_elements() const = 0;
00111
00113 virtual size_t element_size() const = 0;
00114
00116 virtual size_t size_of() const
00117 {
00118 return size_of( n_elements() );
00119 }
00120
00123 virtual size_t size_of(size_t _n_elem) const
00124 {
00125 return (element_size()!=UnknownSize)
00126 ? (_n_elem*element_size())
00127 : UnknownSize;
00128 }
00129
00131 virtual size_t store( std::ostream& _ostr, bool _swap ) const = 0;
00132
00136 virtual size_t restore( std::istream& _istr, bool _swap ) = 0;
00137
00138 protected:
00139
00140
00141 template < typename T >
00142 void check_and_set_persistent( bool _yn )
00143 {
00144 if ( _yn && !IO::is_streamable<T>() )
00145 omerr() << "Warning! Type of property value is not binary storable!\n";
00146 persistent_ = IO::is_streamable<T>() && _yn;
00147 }
00148
00149 private:
00150
00151 std::string name_;
00152 bool persistent_;
00153 };
00154
00155 }
00156
00157 #endif //OPENMESH_BASEPROPERTY_HH
00158
00159