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 <QDomDocument>
51#include <QFile>
54#include <parser/type.hh>
55
56#include "element.hh"
57
58//== NAMESPACES ===============================================================
59namespace VSI {
60
61//== FORWARDDECLARATIONS ======================================================
62class Input;
63class Output;
64class InOut;
65class Type;
66
67//== CLASS DEFINITION =========================================================
68
71class Context {
72
73 public:
75 explicit Context (LoggingInterface *_loggingInterface, PythonInterface *_pythonInterface);
76
78 ~Context ();
79
81 void parse (QFile& _xml);
82
84 const QVector<Element *>& elements () const { return elements_; };
85
87 QVector<Element *> elements (const QString& _category);
88
90 Element *element (const QString& _name);
91
93 QStringList categories ();
94
96 void registerType (Type *_type);
97
99 bool typeSupported (const QString& _type);
100
102 Type *getType (const QString& _type);
103
105 bool canConvert (const QString& _type1, const QString& _type2);
106
108 static bool strToBool (const QString& _str);
109
111 static QString getXmlString (QDomElement &_element, const QString& _tag, QString _default = "");
112
114 static QString removeCommonTrailingSpaces(const QString& in);
115
116 // execute script
117 void executeScript(const QString& _script);
118
119 // open script
120 void openScriptInEditor(const QString& _script);
121
122private:
123
124 // parse element from xml
125 void parseElement (QDomElement &_element);
126
127 // parse element input from xml
128 Input *parseInput (QDomElement &_domElement, Element *_e);
129
130 // parse element output from xml
131 Output *parseOutput (QDomElement& _domElement, Element *_e);
132
133 // parse element function from xml
134 Function *parseFunction (QDomElement& _domElement, Element *_e);
135
136 // parse common input and output parts from xml
137 bool parseInOutBase (QDomElement &_domElement, InOut *_io);
138
139 private:
140 QVector <Element *> elements_;
141
142 QMap <QString, Type*> supportedTypes_;
143
144 QList <Type *> types_;
145
146 LoggingInterface *loggingInterface_;
147 PythonInterface *pythonInterface_;
148};
149
150//=============================================================================
151}
152//=============================================================================
153
154#endif
Interface for all Plugins which do logging to the logging window of the framework.
Interface class for exporting functions to python.
Context(LoggingInterface *_loggingInterface, PythonInterface *_pythonInterface)
Constructor.
Definition: context.cc:76
static bool strToBool(const QString &_str)
Converts the given string to bool.
Definition: context.cc:530
void registerType(Type *_type)
Registers a supported datatype.
Definition: context.cc:541
bool typeSupported(const QString &_type)
Is the given type supported.
Definition: context.cc:552
void parseElement(QDomElement &_element)
parse element from xml
Definition: context.cc:204
static QString getXmlString(QDomElement &_element, const QString &_tag, QString _default="")
Gets the string of a xml query.
Definition: context.cc:514
Type * getType(const QString &_type)
Get type object for given type name.
Definition: context.cc:571
bool canConvert(const QString &_type1, const QString &_type2)
Can the given types be converted to each other.
Definition: context.cc:560
const QVector< Element * > & elements() const
Returns all available elements.
Definition: context.hh:84
~Context()
Destructor.
Definition: context.cc:132
static QString removeCommonTrailingSpaces(const QString &in)
Removes trailing spaces from string which are present in each line - relative trailing spaces are not...
Definition: context.cc:588
Element * element(const QString &_name)
Returns the element with a given name.
Definition: context.cc:155
void parse(QFile &_xml)
Parse xml content.
Definition: context.cc:180
QStringList categories()
List of categories.
Definition: context.cc:166