File indexing completed on 2024-04-28 03:40:40

0001 /*************************************************************************************
0002  *  Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org>                               *
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 #ifndef CONTAINER_H
0020 #define CONTAINER_H
0021 
0022 #include "object.h"
0023 #include "operator.h"
0024 #include "analitzaexport.h"
0025 
0026 namespace Analitza
0027 {
0028 
0029 class Ci;
0030 
0031 /**
0032  * \class Container
0033  * 
0034  * \ingroup AnalitzaModule
0035  *
0036  * \brief Container represents special tags of MathML called containers.
0037  *
0038  * This class is the one that will correspond to MathML container.
0039  * e.g. apply, mathml, bvar, uplimit...
0040  */
0041 
0042 class ANALITZA_EXPORT Container : public Object
0043 {
0044 public:
0045     
0046     /** Is used to describe Container objects in reference to the MathML standard*/
0047     enum ContainerType {
0048         none=0,     /**< No container type, usually means an error */
0049         math,        /**< Describes a container as a %lt;math&gt; tag */
0050         declare,    /**< Describes a container as a %lt;declare&gt; tag */
0051         lambda,        /**< Describes a container as a %lt;lambda&gt; tag */
0052         bvar,        /**< Describes a container as a %lt;bvar&gt; tag */
0053         uplimit,    /**< Describes a container as a %lt;uplimit&gt; tag */
0054         downlimit,    /**< Describes a container as a %lt;downlimit&gt; tag */
0055         piece,        /**< Describes a container as a %lt;piece&gt; tag */
0056         piecewise,    /**< Describes a container as a %lt;piecewise&gt; tag */
0057         otherwise,    /**< Describes a container as a %lt;otherwise&gt; tag */
0058         domainofapplication        /**< Describes a container as a %lt;domainofapplication&gt; tag */ 
0059     };
0060     
0061     typedef QList<Object*>::const_iterator const_iterator;
0062     typedef QList<Object*>::iterator iterator;
0063     
0064     /** Construtor. Creates an empty container with @p c type. */
0065     Container(enum ContainerType c) : Object(container), m_cont_type(c) { }
0066     
0067     /** Copy constructor, copies all of the branches derivated on it.*/
0068     Container(const Container& c);
0069     
0070     virtual Container* copy() const override;
0071     
0072     /** Destructor. Deletes all the references. */
0073     ~Container() override { qDeleteAll(m_params); }
0074     
0075     /** Sets the container type to @p c. */
0076     void setContainerType(enum ContainerType c) { m_cont_type = c; }
0077     
0078     /** Returns the type of the container. */
0079     ContainerType containerType() const { Q_ASSERT(m_type==Object::container && m_cont_type!=none); return m_cont_type; }
0080     
0081     /** Returns whether @p c is equal or not. */
0082     bool operator==(const Container& c) const;
0083     
0084     /** Converts a @p tag to a containerType. */
0085     static ContainerType toContainerType(const QString& tag);
0086     
0087     /** Adds a @p o branch at the end of the Container. */
0088     void appendBranch(Object* o);
0089     
0090     /** Adds a @p o branch right after @p before of the Container. */
0091     void insertBranch(const Container::iterator &before, Object* o) { m_params.insert(before, o); }
0092     
0093     /** Returns a QStringList where we have all of the bvar in the container */
0094     QStringList bvarStrings() const;
0095     
0096     /** Returns a QStringList where we have all of the bvar in the container */
0097     QList<Ci*> bvarCi() const;
0098     
0099     /** Returns the begin iterator on the contained object list */
0100     Container::iterator begin() { return m_params.begin(); }
0101     
0102     /** Returns the begin iterator on the contained object list */
0103     Container::const_iterator constBegin() const { return m_params.constBegin(); }
0104     
0105     /** Returns the end iterator on the contained object list */
0106     Container::const_iterator constEnd() const { return m_params.constEnd(); }
0107     
0108     /** Returns the end iterator on the contained object list */
0109     Container::iterator end() { return m_params.end(); }
0110     
0111     /** Returns whether it is an empty container. */
0112     bool isEmpty() const { return m_params.isEmpty(); }
0113     
0114     /** @return Returns whether it provides a numerical result instead of information. */
0115     bool isNumber() const;
0116     
0117     /** @return Returns the string associated to the container type. */
0118     QString tagName() const;
0119     
0120     virtual QVariant accept(AbstractExpressionVisitor*) const override;
0121     
0122     virtual bool isZero() const override;
0123     
0124     virtual bool matches(const Object* pattern, QMap< QString, const Object* >* found) const override;
0125     
0126     const Container* extractType(Container::ContainerType t) const;
0127     
0128     /** @returns how many bvars are there in the container */
0129     int bvarCount() const;
0130 
0131 // protected:
0132     QList<Object*> m_params;
0133 private:
0134     ContainerType m_cont_type;
0135     static char m_typeStr[][20];
0136     static QMap<QString, ContainerType> m_nameToType;
0137 };
0138 
0139 }
0140 
0141 #endif