// -*- c-basic-offset: 4 -*- /* Rosegarden A sequencer and musical notation editor. This program is Copyright 2000-2008 Guillaume Laurent , Chris Cannam , Richard Bown The moral right of the authors to claim authorship of this work has been asserted. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information. */ #ifndef _PROPERTY_H_ #define _PROPERTY_H_ #include #include "RealTime.h" namespace Rosegarden { enum PropertyType { Int, String, Bool, RealTimeT, UInt }; template class PropertyDefn { public: struct PropertyDefnNotDefined { PropertyDefnNotDefined() { throw(0); } }; typedef PropertyDefnNotDefined basic_type; static std::string typeName() { return "Undefined"; } static basic_type parse(std::string); static std::string unparse(basic_type); }; template typename PropertyDefn

::basic_type PropertyDefn

::parse(std::string) { throw(0); return ""; } template std::string PropertyDefn

::unparse(PropertyDefn

::basic_type) { throw(0); return ""; } template <> class PropertyDefn { public: typedef long basic_type; static std::string typeName(); static basic_type parse(std::string s); static std::string unparse(basic_type i); }; template <> class PropertyDefn { public: typedef std::string basic_type; static std::string typeName(); static basic_type parse(std::string s); static std::string unparse(basic_type i); }; template <> class PropertyDefn { public: typedef bool basic_type; static std::string typeName(); static basic_type parse(std::string s); static std::string unparse(basic_type i); }; template <> class PropertyDefn { public: typedef RealTime basic_type; static std::string typeName(); static basic_type parse(std::string s); static std::string unparse(basic_type i); }; template <> class PropertyDefn { public: typedef unsigned int basic_type; static std::string typeName(); static basic_type parse(std::string s); static std::string unparse(basic_type i); }; class PropertyStoreBase { public: virtual ~PropertyStoreBase(); virtual PropertyType getType() const = 0; virtual std::string getTypeName() const = 0; virtual PropertyStoreBase *clone() = 0; virtual std::string unparse() const = 0; virtual size_t getStorageSize() const = 0; // for debugging #ifndef NDEBUG virtual void dump(std::ostream&) const = 0; #else virtual void dump(std::ostream&) const { } #endif }; #ifndef NDEBUG inline std::ostream& operator<<(std::ostream &out, PropertyStoreBase &e) { e.dump(out); return out; } #endif template class PropertyStore : public PropertyStoreBase { public: PropertyStore(typename PropertyDefn

::basic_type d) : m_data(d) { } PropertyStore(const PropertyStore

&p) : PropertyStoreBase(p), m_data(p.m_data) { } PropertyStore &operator=(const PropertyStore

&p); virtual PropertyType getType() const; virtual std::string getTypeName() const; virtual PropertyStoreBase* clone(); virtual std::string unparse() const; typename PropertyDefn

::basic_type getData() { return m_data; } void setData(typename PropertyDefn

::basic_type data) { m_data = data; } virtual size_t getStorageSize() const; #ifndef NDEBUG void dump(std::ostream&) const; #endif private: typename PropertyDefn

::basic_type m_data; }; template PropertyStore

& PropertyStore

::operator=(const PropertyStore

&p) { if (this != &p) { m_data = p.m_data; } return *this; } template PropertyType PropertyStore

::getType() const { return P; } template std::string PropertyStore

::getTypeName() const { return PropertyDefn

::typeName(); } template PropertyStoreBase* PropertyStore

::clone() { return new PropertyStore

(*this); } template std::string PropertyStore

::unparse() const { return PropertyDefn

::unparse(m_data); } #ifndef NDEBUG template void PropertyStore

::dump(std::ostream &out) const { out << getTypeName() << " - " << unparse(); } #endif } #endif