X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fvariant.h;h=515350de6ae5543158e20b6e2c20d4ef786163fb;hp=f2d2ee563f339bb8b64eb020b516c3792b1db08f;hb=c3e242c2629cbc9645258b30aaf07b7285d4372b;hpb=ab956fd92f2110197c8e035b12dafa30a18b8ae1 diff --git a/source/core/variant.h b/source/core/variant.h index f2d2ee5..515350d 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspcore -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_CORE_VARIANT_H_ #define MSP_CORE_VARIANT_H_ @@ -38,7 +31,7 @@ private: { T data; - Store(T d): data(d) { } + Store(const T &d): data(d) { } virtual const std::type_info &type_id() const { return typeid(T); } virtual StoreBase *clone() const { return new Store(data); } @@ -68,14 +61,28 @@ public: return *this; } +private: template - T &value() const + Store::Type> *get_typed_store() const { typedef typename RemoveConst::Type NCT; Store *s = dynamic_cast *>(store); if(!s) throw type_mismatch(typeid(T), (store ? store->type_id() : typeid(void))); - return s->data; + return s; + } + +public: + template + T &value() + { + return get_typed_store()->data; + } + + template + const T &value() const + { + return get_typed_store()->data; } template