// Copyright (C) 2000-2007, Luca Padovani . // // This file is part of GtkMathView, a flexible, high-quality rendering // engine for MathML documents. // // GtkMathView is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License as published // by the Free Software Foundation; either version 3 of the License, or // (at your option) any later version. // // GtkMathView is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . #ifndef __Variant_hh__ #define __Variant_hh__ #include #include "SmartPtr.hh" #include "Value.hh" template class GMV_MathView_EXPORT Variant : public Value { protected: Variant(const T& v) : value(v) { } virtual ~Variant() { } public: static SmartPtr create(const T& v) { return new Variant(v); } T getValue(void) const { return value; } private: T value; }; template <> class GMV_MathView_EXPORT Variant : public Value { protected: Variant(void) { } virtual ~Variant() { } public: static SmartPtr< Variant > create(void) { return new Variant(); } }; // The following full specialization is for sequences of Values // There are more accessor methods and getValue returns a // const reference instead of a copy fo the object template <> class GMV_MathView_EXPORT Variant< std::vector< SmartPtr > > : public Value { protected: Variant(const std::vector< SmartPtr >& v) : content(v) { } virtual ~Variant() { } public: static SmartPtr< Variant< std::vector< SmartPtr > > > create(const std::vector< SmartPtr >& v) { return new Variant(v); } const std::vector< SmartPtr >& getValue(void) const { return content; } unsigned getSize(void) const { return content.size(); } SmartPtr getValue(unsigned i) const { return content[i]; } private: std::vector< SmartPtr > content; }; typedef Variant< std::vector< SmartPtr > > ValueSequence; template /* GMV_MathView_EXPORT */ T as(const Value* v) { if (const Variant* obj = dynamic_cast*>(v)) return obj->getValue(); else throw Value::TypeError(); } #endif // __Variant_hh__