/************************************************************************************* * Copyright (C) 2007 by Aleix Pol * * * * 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. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #ifndef CONTAINER_H #define CONTAINER_H #include #include "object.h" #include "operator.h" #include "analitzaexport.h" namespace Analitza { class Ci; /** * This class is the one that will correspond to MathML container. * e.g. apply, mathml, bvar, uplimit... * @author Aleix Pol */ class ANALITZA_EXPORT Container : public Object { public: /** Is used to describe Container objects in reference to the MathML standard*/ enum ContainerType { none=0, /**< No container type, usually means an error */ math, /**< Describes a container as a %lt;math> tag */ apply, /**< Describes a container as a %lt;apply> tag */ declare, /**< Describes a container as a %lt;declare> tag */ lambda, /**< Describes a container as a %lt;lambda> tag */ bvar, /**< Describes a container as a %lt;bvar> tag */ uplimit, /**< Describes a container as a %lt;uplimit> tag */ downlimit, /**< Describes a container as a %lt;downlimit> tag */ piece, /**< Describes a container as a %lt;piece> tag */ piecewise, /**< Describes a container as a %lt;piecewise> tag */ otherwise, /**< Describes a container as a %lt;otherwise> tag */ domainofapplication /**< Describes a container as a %lt;domainofapplication> tag */ }; typedef QList::const_iterator const_iterator; typedef QList::iterator iterator; /** Construtor. Creates an empty container with @p c type. */ Container(enum ContainerType c) : Object(container), m_cont_type(c) { } /** Copy constructor, copies all of the branches derivated on it.*/ Container(const Container& c); virtual Container* copy() const; /** Destructor. Deletes all the references. */ virtual ~Container() { qDeleteAll(m_params); } /** Sets the container type to @p c. */ void setContainerType(enum ContainerType c) { m_cont_type = c; } /** Returns the type of the container. */ ContainerType containerType() const { Q_ASSERT(m_type==Object::container && m_cont_type!=none); return m_cont_type; } /** Returns whether @p c is equal or not. */ bool operator==(const Container& c) const; /** Converts a @p tag to a containerType. */ static ContainerType toContainerType(const QString& tag); /** Adds a @p o branch at the end of the Container. */ void appendBranch(Object* o); /** Adds a @p o branch right after @p before of the Container. */ void insertBranch(Container::iterator before, Object* o) { m_params.insert(before, o); } /** Returns a QStringList where we have all of the bvar in the container */ QStringList bvarStrings() const; /** Returns a QStringList where we have all of the bvar in the container */ QList bvarCi() const; /** Returns the first operator found in the container */ Operator firstOperator() const; /** Returns an iterator pointing to the first value of the container */ Container::iterator firstValue(); /** Returns a constant iterator pointing to the first value of the container */ Container::const_iterator firstValue() const; /** Returns the container's uplimit. */ Object* ulimit() const; /** Returns the container's downlimit. */ Object* dlimit() const; /** Returns the domain of application definition. */ Object* domain() const; /** Returns whether it is an unary container. This means that there is only one value inside. */ bool isUnary() const; /** Returns whether it is an empty container. */ bool isEmpty() const { return firstValue()==m_params.end(); } /** Returns whether it is correct container. */ bool isCorrect() const; /** @return Returns whether it provides a numerical result instead of information. */ bool isNumber() const; /** @return Returns the string associated to the container type. */ QString tagName() const; int countValues() const; virtual QString visit(ExpressionWriter*) const; virtual void negate(); virtual bool isZero() const; virtual bool matches(const Object* pattern, QMap< QString, const Object* >* found) const; Container* extractType(Container::ContainerType t) const; virtual bool decorate(const ScopeInformation& scope); // protected: QList m_params; private: ContainerType m_cont_type; static char m_typeStr[][20]; static QMap m_nameToType; }; } #endif