X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fvariant.h;h=f78851f8582710849db54b3b7259042918897a75;hb=c76bd823b81d723d8cd4531631a4b18544f1981a;hp=6425fbfcbf7e4046d58105b445563f5e4d221acd;hpb=3553d02ef9cf66ae5ff16dd0b129815f144857a1;p=libs%2Fcore.git diff --git a/source/core/variant.h b/source/core/variant.h index 6425fbf..f78851f 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspcore -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2008 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -19,6 +19,7 @@ private: struct StoreBase { virtual ~StoreBase() { } + virtual StoreBase *clone() const =0; }; template @@ -27,6 +28,7 @@ private: T data; Store(T d): data(d) { } + virtual StoreBase *clone() const { return new Store(data); } }; StoreBase *store; @@ -35,6 +37,7 @@ public: Variant(): store(0) { } template Variant(const T &v): store(new Store::Type>(v)) { } + Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } ~Variant() { delete store; } template @@ -45,6 +48,13 @@ public: return *this; } + Variant &operator=(const Variant &v) + { + delete store; + store=(v.store ? v.store->clone() : 0); + return *this; + } + template T &value() const {