BaseProperty.hh
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* *
\*===========================================================================*/
#ifndef OPENMESH_BASEPROPERTY_HH
#define OPENMESH_BASEPROPERTY_HH
#include <string>
#include <OpenMesh/Core/IO/StoreRestore.hh>
#include <OpenMesh/Core/System/omstream.hh>
namespace OpenMesh {
//== CLASS DEFINITION =========================================================
class OPENMESHDLLEXPORT BaseProperty
{
public:
static const size_t UnknownSize = size_t(-1);
public:
BaseProperty(const std::string& _name = "<unknown>")
: name_(_name), persistent_(false)
{}
BaseProperty(const BaseProperty & _rhs)
: name_( _rhs.name_ ), persistent_( _rhs.persistent_ ) {}
virtual ~BaseProperty() {}
public: // synchronized array interface
virtual void reserve(size_t _n) = 0;
virtual void resize(size_t _n) = 0;
virtual void clear() = 0;
virtual void push_back() = 0;
virtual void swap(size_t _i0, size_t _i1) = 0;
virtual void copy(size_t _io, size_t _i1) = 0;
virtual BaseProperty* clone () const = 0;
public: // named property interface
const std::string& name() const { return name_; }
virtual void stats(std::ostream& _ostr) const;
public: // I/O support
bool persistent(void) const { return persistent_; }
virtual void set_persistent( bool _yn ) = 0;
virtual size_t n_elements() const = 0;
virtual size_t element_size() const = 0;
virtual size_t size_of() const
{
return size_of( n_elements() );
}
virtual size_t size_of(size_t _n_elem) const
{
return (element_size()!=UnknownSize)
? (_n_elem*element_size())
: UnknownSize;
}
virtual size_t store( std::ostream& _ostr, bool _swap ) const = 0;
virtual size_t restore( std::istream& _istr, bool _swap ) = 0;
protected:
// To be used in a derived class, when overloading set_persistent()
template < typename T >
void check_and_set_persistent( bool _yn )
{
if ( _yn && !IO::is_streamable<T>() )
omerr() << "Warning! Type of property value is not binary storable!\n";
persistent_ = IO::is_streamable<T>() && _yn;
}
private:
std::string name_;
bool persistent_;
};
}//namespace OpenMesh
#endif //OPENMESH_BASEPROPERTY_HH
OpenMesh::BaseProperty::name
const std::string & name() const
Return the name of the property.
Definition: BaseProperty.hh:125
OpenMesh::BaseProperty::~BaseProperty
virtual ~BaseProperty()
Destructor.
Definition: BaseProperty.hh:97
omstream.hh
This file provides the streams omlog, omout, and omerr.
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
OpenMesh::BaseProperty::persistent
bool persistent(void) const
Returns true if the persistent flag is enabled else false.
Definition: BaseProperty.hh:132
OpenMesh::BaseProperty::BaseProperty
BaseProperty(const BaseProperty &_rhs)
Copy constructor.
Definition: BaseProperty.hh:93
OpenMesh::BaseProperty
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:65
OpenMesh::BaseProperty::BaseProperty
BaseProperty(const std::string &_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:88
OpenMesh::BaseProperty::size_of
virtual size_t size_of() const
Return size of property in bytes.
Definition: BaseProperty.hh:145
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:152