1
/*************************************************************************************
2
* Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org> *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License *
6
* as published by the Free Software Foundation; either version 2 *
7
* of the License, or (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the Free Software *
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17
*************************************************************************************/
26
#include "analitzaexport.h"
34
* This class is the one that will correspond to MathML container.
35
* e.g. apply, mathml, bvar, uplimit...
36
* @author Aleix Pol <aleixpol@kde.org>
39
class ANALITZA_EXPORT Container : public Object
43
/** Is used to describe Container objects in reference to the MathML standard*/
45
none=0, /**< No container type, usually means an error */
46
math, /**< Describes a container as a %lt;math> tag */
47
declare, /**< Describes a container as a %lt;declare> tag */
48
lambda, /**< Describes a container as a %lt;lambda> tag */
49
bvar, /**< Describes a container as a %lt;bvar> tag */
50
uplimit, /**< Describes a container as a %lt;uplimit> tag */
51
downlimit, /**< Describes a container as a %lt;downlimit> tag */
52
piece, /**< Describes a container as a %lt;piece> tag */
53
piecewise, /**< Describes a container as a %lt;piecewise> tag */
54
otherwise, /**< Describes a container as a %lt;otherwise> tag */
55
domainofapplication /**< Describes a container as a %lt;domainofapplication> tag */
58
typedef QList<Object*>::const_iterator const_iterator;
59
typedef QList<Object*>::iterator iterator;
61
/** Construtor. Creates an empty container with @p c type. */
62
Container(enum ContainerType c) : Object(container), m_cont_type(c) { }
64
/** Copy constructor, copies all of the branches derivated on it.*/
65
Container(const Container& c);
67
virtual Container* copy() const;
69
/** Destructor. Deletes all the references. */
70
virtual ~Container() { qDeleteAll(m_params); }
72
/** Sets the container type to @p c. */
73
void setContainerType(enum ContainerType c) { m_cont_type = c; }
75
/** Returns the type of the container. */
76
ContainerType containerType() const { Q_ASSERT(m_type==Object::container && m_cont_type!=none); return m_cont_type; }
78
/** Returns whether @p c is equal or not. */
79
bool operator==(const Container& c) const;
81
/** Converts a @p tag to a containerType. */
82
static ContainerType toContainerType(const QString& tag);
84
/** Adds a @p o branch at the end of the Container. */
85
void appendBranch(Object* o);
87
/** Adds a @p o branch right after @p before of the Container. */
88
void insertBranch(Container::iterator before, Object* o) { m_params.insert(before, o); }
90
/** Returns a QStringList where we have all of the bvar in the container */
91
QStringList bvarStrings() const;
93
/** Returns a QStringList where we have all of the bvar in the container */
94
QList<Ci*> bvarCi() const;
96
/** Returns the begin iterator on the contained object list */
97
Container::iterator begin() { return m_params.begin(); }
99
/** Returns the begin iterator on the contained object list */
100
Container::const_iterator constBegin() const { return m_params.constBegin(); }
102
/** Returns the end iterator on the contained object list */
103
Container::const_iterator constEnd() const { return m_params.constEnd(); }
105
/** Returns the end iterator on the contained object list */
106
Container::iterator end() { return m_params.end(); }
108
/** Returns whether it is an empty container. */
109
bool isEmpty() const { return m_params.isEmpty(); }
111
/** @return Returns whether it provides a numerical result instead of information. */
112
bool isNumber() const;
114
/** @return Returns the string associated to the container type. */
115
QString tagName() const;
117
virtual QString visit(ExpressionWriter*) const;
119
virtual bool isZero() const;
121
virtual bool matches(const Object* pattern, QMap< QString, const Object* >* found) const;
123
Container* extractType(Container::ContainerType t) const;
125
/** @returns how many bvars are there in the container */
126
int bvarCount() const;
129
QList<Object*> m_params;
131
ContainerType m_cont_type;
132
static char m_typeStr[][20];
133
static QMap<QString, ContainerType> m_nameToType;