Loading...
Searching...
No Matches
BaseProperty.hh
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2022, 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. *
* *
* ========================================================================= */
#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>", const std::string& _internal_type_name = "<unknown>" )
: name_(_name), internal_type_name_(_internal_type_name), persistent_(false)
{}
BaseProperty(const BaseProperty & _rhs)
: name_( _rhs.name_ ), internal_type_name_(_rhs.internal_type_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_; }
const std::string& internal_type_name() const { return internal_type_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 std::string get_storage_name() const = 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_;
std::string internal_type_name_;
bool persistent_;
};
}//namespace OpenMesh
#endif //OPENMESH_BASEPROPERTY_HH
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:59
OpenMesh::BaseProperty
Abstract class defining the basic interface of a dynamic property.
Definition BaseProperty.hh:61
OpenMesh::BaseProperty::restore
virtual size_t restore(std::istream &_istr, bool _swap)=0
Restore self from a binary block.
OpenMesh::BaseProperty::push_back
virtual void push_back()=0
Extend the number of elements by one.
OpenMesh::BaseProperty::BaseProperty
BaseProperty(const std::string &_name="<unknown>", const std::string &_internal_type_name="<unknown>")
Default constructor.
Definition BaseProperty.hh:84
OpenMesh::BaseProperty::size_of
virtual size_t size_of() const
Return size of property in bytes.
Definition BaseProperty.hh:147
OpenMesh::BaseProperty::reserve
virtual void reserve(size_t _n)=0
Reserve memory for n elements.
OpenMesh::BaseProperty::persistent
bool persistent(void) const
Returns true if the persistent flag is enabled else false.
Definition BaseProperty.hh:131
OpenMesh::BaseProperty::resize
virtual void resize(size_t _n)=0
Resize storage to hold n elements.
OpenMesh::BaseProperty::swap
virtual void swap(size_t _i0, size_t _i1)=0
Let two elements swap their storage place.
OpenMesh::BaseProperty::clear
virtual void clear()=0
Clear all elements and free memory.
OpenMesh::BaseProperty::BaseProperty
BaseProperty(const BaseProperty &_rhs)
Copy constructor.
Definition BaseProperty.hh:89
OpenMesh::BaseProperty::n_elements
virtual size_t n_elements() const =0
Number of elements in property.
OpenMesh::BaseProperty::~BaseProperty
virtual ~BaseProperty()
Destructor.
Definition BaseProperty.hh:93
OpenMesh::BaseProperty::copy
virtual void copy(size_t _io, size_t _i1)=0
Copy one element to another.
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:124
OpenMesh::BaseProperty::store
virtual size_t store(std::ostream &_ostr, bool _swap) const =0
Store self as one binary block.
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:154
OpenMesh::BaseProperty::get_storage_name
virtual std::string get_storage_name() const =0
returns a unique string for the type of the elements
OpenMesh::BaseProperty::element_size
virtual size_t element_size() const =0
Size of one element in bytes or UnknownSize if not known.
OpenMesh::BaseProperty::set_persistent
virtual void set_persistent(bool _yn)=0
Enable or disable persistency.
OpenMesh::BaseProperty::clone
virtual BaseProperty * clone() const =0
Return a deep copy of self.
OpenMesh::BaseProperty::name
const std::string & name() const
Return the name of the property.
Definition BaseProperty.hh:121