]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/variant.h
Make sure all classes have sensible copy semantics
[libs/core.git] / source / core / variant.h
index f2d2ee563f339bb8b64eb020b516c3792b1db08f..515350de6ae5543158e20b6e2c20d4ef786163fb 100644 (file)
@@ -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(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<T>(data); }
@@ -68,14 +61,28 @@ public:
                return *this;
        }
 
+private:
        template<typename T>
-       T &value() const
+       Store<typename RemoveConst<T>::Type> *get_typed_store() const
        {
                typedef typename RemoveConst<T>::Type NCT;
                Store<NCT> *s = dynamic_cast<Store<NCT> *>(store);
                if(!s)
                        throw type_mismatch(typeid(T), (store ? store->type_id() : typeid(void)));
-               return s->data;
+               return s;
+       }
+
+public:
+       template<typename T>
+       T &value()
+       {
+               return get_typed_store<T>()->data;
+       }
+
+       template<typename T>
+       const T &value() const
+       {
+               return get_typed_store<T>()->data;
        }
 
        template<typename T>