OpenMesh
|
00001 /*===========================================================================*\ 00002 * * 00003 * OpenMesh * 00004 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * 00005 * www.openmesh.org * 00006 * * 00007 *---------------------------------------------------------------------------* 00008 * This file is part of OpenMesh. * 00009 * * 00010 * OpenMesh is free software: you can redistribute it and/or modify * 00011 * it under the terms of the GNU Lesser General Public License as * 00012 * published by the Free Software Foundation, either version 3 of * 00013 * the License, or (at your option) any later version with the * 00014 * following exceptions: * 00015 * * 00016 * If other files instantiate templates or use macros * 00017 * or inline functions from this file, or you compile this file and * 00018 * link it with other files to produce an executable, this file does * 00019 * not by itself cause the resulting executable to be covered by the * 00020 * GNU Lesser General Public License. This exception does not however * 00021 * invalidate any other reasons why the executable file might be * 00022 * covered by the GNU Lesser General Public License. * 00023 * * 00024 * OpenMesh is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU Lesser General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU LesserGeneral Public * 00030 * License along with OpenMesh. If not, * 00031 * see <http://www.gnu.org/licenses/>. * 00032 * * 00033 \*===========================================================================*/ 00034 00035 /*===========================================================================*\ 00036 * * 00037 * $Revision: 362 $ * 00038 * $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $ * 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 //== CLASS DEFINITION ========================================================= 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: // synchronized array interface 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: // named property interface 00113 00115 const std::string& name() const { return name_; } 00116 00117 virtual void stats(std::ostream& _ostr) const; 00118 00119 public: // I/O support 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 // To be used in a derived class, when overloading set_persistent() 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 }//namespace OpenMesh 00175 00176 #endif //OPENMESH_BASEPROPERTY_HH 00177 00178