Developer Documentation
context.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 #ifndef VSI_CONTEXT_HH
45 #define VSI_CONTEXT_HH
46 
47 //== INCLUDES =================================================================
48 #include <QVector>
49 #include <QStringList>
50 #include <QXmlQuery>
51 
52 #include "element.hh"
53 
54 //== FORWARDDECLARATIONS ======================================================
55 class QScriptEngine;
56 
57 //== NAMESPACES ===============================================================
58 namespace VSI {
59 
60 //== FORWARDDECLARATIONS ======================================================
61 class Input;
62 class Output;
63 class InOut;
64 class Type;
65 
66 //== CLASS DEFINITION =========================================================
67 
70 class Context {
71 
72  public:
74  explicit Context (QScriptEngine *_engine);
75 
77  ~Context ();
78 
80  void parse (QByteArray _xml);
81 
83  const QVector<Element *>& elements () const { return elements_; };
84 
86  QVector<Element *> elements (QString _category);
87 
89  Element *element (QString _name);
90 
92  QStringList categories ();
93 
95  void registerType (Type *_type);
96 
98  bool typeSupported (QString _type);
99 
101  Type *getType (QString _type);
102 
104  bool canConvert (QString _type1, QString _type2);
105 
107  QScriptEngine *scriptEngine () { return scriptEngine_; };
108 
110  static bool strToBool (QString _str);
111 
113  static QString getXmlString (QXmlQuery &_xml, QString _expr, QString _default = "");
114 
115  private:
116 
117  // parse element from xml
118  void parseElement (QXmlQuery &_xml);
119 
120  // parse element input from xml
121  Input *parseInput (QXmlQuery &_xml, Element *_e);
122 
123  // parse element output from xml
124  Output *parseOutput (QXmlQuery &_xml, Element *_e);
125 
126  // parse element function from xml
127  Function *parseFunction (QXmlQuery &_xml, Element *_e);
128 
129  // parse common input and output parts from xml
130  bool parseInOutBase (QXmlQuery &_xml, InOut *_io);
131 
132  private:
133  QVector <Element *> elements_;
134 
135  QMap <QString, Type*> supportedTypes_;
136 
137  QList <Type *> types_;
138 
139  QScriptEngine *scriptEngine_;
140 };
141 
142 //=============================================================================
143 }
144 //=============================================================================
145 
146 #endif
void registerType(Type *_type)
Registers a supported datatype.
Definition: context.cc:560
static QString getXmlString(QXmlQuery &_xml, QString _expr, QString _default="")
Gets the string of a xml query.
Definition: context.cc:534
bool typeSupported(QString _type)
Is the given type supported.
Definition: context.cc:571
bool canConvert(QString _type1, QString _type2)
Can the given types be converted to each other.
Definition: context.cc:579
Type * getType(QString _type)
Get type object for given type name.
Definition: context.cc:590
static bool strToBool(QString _str)
Converts the given string to bool.
Definition: context.cc:549
const QVector< Element * > & elements() const
Returns all available elements.
Definition: context.hh:83
void parse(QByteArray _xml)
Parse xml content.
Definition: context.cc:182
Element * element(QString _name)
Returns the element with a given name.
Definition: context.cc:157
Context(QScriptEngine *_engine)
Constructor.
Definition: context.cc:78
~Context()
Destructor.
Definition: context.cc:134
QScriptEngine * scriptEngine()
Return script engine pointer.
Definition: context.hh:107
QStringList categories()
List of categories.
Definition: context.cc:168