]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/variant.h
Improve GetOpt help generation
[libs/core.git] / source / core / variant.h
index 6425fbfcbf7e4046d58105b445563f5e4d221acd..f78851f8582710849db54b3b7259042918897a75 100644 (file)
@@ -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<typename T>
@@ -27,6 +28,7 @@ private:
                T data;
 
                Store(T d): data(d) { }
+               virtual StoreBase *clone() const { return new Store<T>(data); }
        };
 
        StoreBase *store;
@@ -35,6 +37,7 @@ public:
        Variant(): store(0) { }
        template<typename T>
        Variant(const T &v): store(new Store<typename RemoveConst<T>::Type>(v)) { }
+       Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { }
        ~Variant() { delete store; }
 
        template<typename T>
@@ -45,6 +48,13 @@ public:
                return *this;
        }
 
+       Variant &operator=(const Variant &v)
+       {
+               delete store;
+               store=(v.store ? v.store->clone() : 0);
+               return *this;
+       }
+
        template<typename T>
        T &value() const
        {