~ubuntu-branches/ubuntu/precise/kalgebra/precise-updates

« back to all changes in this revision

Viewing changes to analitza/container.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 16:41:53 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20111216164153-ym1s7jhbqwn2ndz6
Tags: 4:4.7.90-0ubuntu2
PPA rebuild, no changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************************************************
2
 
 *  Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org>                               *
3
 
 *                                                                                   *
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.                           *
8
 
 *                                                                                   *
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.                                     *
13
 
 *                                                                                   *
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
 
 *************************************************************************************/
18
 
 
19
 
#ifndef CONTAINER_H
20
 
#define CONTAINER_H
21
 
 
22
 
#include <QDomNode>
23
 
 
24
 
#include "object.h"
25
 
#include "operator.h"
26
 
#include "analitzaexport.h"
27
 
 
28
 
namespace Analitza
29
 
{
30
 
 
31
 
class Ci;
32
 
 
33
 
/**
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>  
37
 
 */
38
 
 
39
 
class ANALITZA_EXPORT Container : public Object
40
 
{
41
 
public:
42
 
        
43
 
        /** Is used to describe Container objects in reference to the MathML standard*/
44
 
        enum ContainerType {
45
 
                none=0,         /**< No container type, usually means an error */
46
 
                math,           /**< Describes a container as a %lt;math&gt; tag */
47
 
                declare,        /**< Describes a container as a %lt;declare&gt; tag */
48
 
                lambda,         /**< Describes a container as a %lt;lambda&gt; tag */
49
 
                bvar,           /**< Describes a container as a %lt;bvar&gt; tag */
50
 
                uplimit,        /**< Describes a container as a %lt;uplimit&gt; tag */
51
 
                downlimit,      /**< Describes a container as a %lt;downlimit&gt; tag */
52
 
                piece,          /**< Describes a container as a %lt;piece&gt; tag */
53
 
                piecewise,      /**< Describes a container as a %lt;piecewise&gt; tag */
54
 
                otherwise,      /**< Describes a container as a %lt;otherwise&gt; tag */
55
 
                domainofapplication             /**< Describes a container as a %lt;domainofapplication&gt; tag */ 
56
 
        };
57
 
        
58
 
        typedef QList<Object*>::const_iterator const_iterator;
59
 
        typedef QList<Object*>::iterator iterator;
60
 
        
61
 
        /** Construtor. Creates an empty container with @p c type. */
62
 
        Container(enum ContainerType c) : Object(container), m_cont_type(c) { }
63
 
        
64
 
        /** Copy constructor, copies all of the branches derivated on it.*/
65
 
        Container(const Container& c);
66
 
        
67
 
        virtual Container* copy() const;
68
 
        
69
 
        /** Destructor. Deletes all the references. */
70
 
        virtual ~Container() { qDeleteAll(m_params); }
71
 
        
72
 
        /** Sets the container type to @p c. */
73
 
        void setContainerType(enum ContainerType c) { m_cont_type = c; }
74
 
        
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; }
77
 
        
78
 
        /** Returns whether @p c is equal or not. */
79
 
        bool operator==(const Container& c) const;
80
 
        
81
 
        /** Converts a @p tag to a containerType. */
82
 
        static ContainerType toContainerType(const QString& tag);
83
 
        
84
 
        /** Adds a @p o branch at the end of the Container. */
85
 
        void appendBranch(Object* o);
86
 
        
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); }
89
 
        
90
 
        /** Returns a QStringList where we have all of the bvar in the container */
91
 
        QStringList bvarStrings() const;
92
 
        
93
 
        /** Returns a QStringList where we have all of the bvar in the container */
94
 
        QList<Ci*> bvarCi() const;
95
 
        
96
 
        /** Returns the begin iterator on the contained object list */
97
 
        Container::iterator begin() { return m_params.begin(); }
98
 
        
99
 
        /** Returns the begin iterator on the contained object list */
100
 
        Container::const_iterator constBegin() const { return m_params.constBegin(); }
101
 
        
102
 
        /** Returns the end iterator on the contained object list */
103
 
        Container::const_iterator constEnd() const { return m_params.constEnd(); }
104
 
        
105
 
        /** Returns the end iterator on the contained object list */
106
 
        Container::iterator end() { return m_params.end(); }
107
 
        
108
 
        /** Returns whether it is an empty container. */
109
 
        bool isEmpty() const { return m_params.isEmpty(); }
110
 
        
111
 
        /** @return Returns whether it provides a numerical result instead of information. */
112
 
        bool isNumber() const;
113
 
        
114
 
        /** @return Returns the string associated to the container type. */
115
 
        QString tagName() const;
116
 
        
117
 
        virtual QString visit(ExpressionWriter*) const;
118
 
        
119
 
        virtual bool isZero() const;
120
 
        
121
 
        virtual bool matches(const Object* pattern, QMap< QString, const Object* >* found) const;
122
 
        
123
 
        Container* extractType(Container::ContainerType t) const;
124
 
        
125
 
        /** @returns how many bvars are there in the container */
126
 
        int bvarCount() const;
127
 
 
128
 
// protected:
129
 
        QList<Object*> m_params;
130
 
private:
131
 
        ContainerType m_cont_type;
132
 
        static char m_typeStr[][20];
133
 
        static QMap<QString, ContainerType> m_nameToType;
134
 
};
135
 
 
136
 
}
137
 
 
138
 
#endif