X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftrunk%2FETL%2F_value.h;h=adf7816081f5bcb0614fed6a01fda0cd8ef47c14;hb=e0dedc46e8ab6b258be81887689b0c0fd60def0c;hp=a8369c66039d5c89a45e36f16e17152378003ef0;hpb=b3016b249333ac0ab0008d8c6c4d9029b2ff30c9;p=synfig.git diff --git a/ETL/trunk/ETL/_value.h b/ETL/trunk/ETL/_value.h index a8369c6..adf7816 100644 --- a/ETL/trunk/ETL/_value.h +++ b/ETL/trunk/ETL/_value.h @@ -1,7 +1,7 @@ /* ======================================================================== ** Extended Template and Library ** Abstraction for a Generic Value Type -** $Id: _value.h,v 1.1.1.1 2005/01/04 01:31:48 darco Exp $ +** $Id$ ** ** Copyright (c) 2002 Adrian Bentley ** @@ -24,8 +24,8 @@ /* === S T A R T =========================================================== */ -#ifndef __ETL_VALUE_H -#define __ETL_VALUE_H +#ifndef __ETL__VALUE_H +#define __ETL__VALUE_H /* === H E A D E R S ======================================================= */ #include @@ -70,20 +70,20 @@ class value virtual contentholder *clone() const = 0; virtual const std::type_info &type() const = 0; }; - - contentholder *content; - -public: //structor interface + + contentholder *content; + +public: //constructor interface value() - :content(0) + :content(0) { } - + value(const value &v) :content( v.content ? v.content->clone() : 0 ) { } - + /* Copies the object passed to it */ template < typename T > @@ -92,9 +92,9 @@ public: //structor interface (reinterpret_cast::value_type &>(v)) ) { } - + public: //modifier interface - + value & swap(value & rhs) { std::swap(content, rhs.content); @@ -113,34 +113,34 @@ public: //modifier interface value(rhs).swap(*this); return *this; } - + public: //query interface - + bool empty() const { return content == 0; } - + const std::type_info & type() const { return content ? content->type() : typeid(void); } - + private: //implementation interface - + template < typename T > class holder : public contentholder { public: //representation T obj; - public: //structor interface - + public: //constructor interface + holder(const T &o) :obj(o) { } - + holder(const holder &h) :obj(h.obj) { @@ -151,21 +151,21 @@ private: //implementation interface { return new holder(*this); } - + virtual const std::type_info &type() const { return typeid(T); } - + public: //allocation interface void *operator new(unsigned int size) { assert(size == sizeof(holder)); - + //use pool allocation at some point return malloc(size); } - + void operator delete(void *p) { assert(p); @@ -173,7 +173,7 @@ private: //implementation interface return free(p); } }; - + template < typename ValueType > friend ValueType *value_cast(value *v); }; @@ -199,8 +199,8 @@ template < typename ValueType > ValueType *value_cast(value *v) { assert(v); - - return ( typeid(typename value_store_type::value_type) == v->type() ) + + return ( typeid(typename value_store_type::value_type) == v->type() ) ? &static_cast *>(v->content)->obj : 0; } @@ -214,7 +214,7 @@ const ValueType * value_cast(const value *v) return value_cast(const_cast(v)); } -/*! Extract a copy of the internal object and will throw a bad_value_cast exception +/*! Extract a copy of the internal object and will throw a bad_value_cast exception if the types do not agree. \note I'm not sure why boost::any didn't use a reference here... there must be a reason...