~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to Externals/MathMLSolver/include/MathMLSymbolTable.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
Copyright (c) 2007 netAllied GmbH, Tettnang
 
3
 
 
4
Permission is hereby granted, free of charge, to any person
 
5
obtaining a copy of this software and associated documentation
 
6
files (the "Software"), to deal in the Software without
 
7
restriction, including without limitation the rights to use,
 
8
copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
copies of the Software, and to permit persons to whom the
 
10
Software is furnished to do so, subject to the following
 
11
conditions:
 
12
 
 
13
The above copyright notice and this permission notice shall be
 
14
included in all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
18
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
20
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
21
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
23
OTHER DEALINGS IN THE SOFTWARE.
 
24
******************************************************************************/
 
25
 
 
26
#ifndef __MATHML_SYMBOL_TABLE_H___
 
27
#define __MATHML_SYMBOL_TABLE_H___
 
28
 
 
29
#include "MathMLSolverPrerequisites.h"
 
30
#include "MathMLString.h"
 
31
#include "MathMLASTNode.h"
 
32
#include "MathMLASTConstantExpression.h"
 
33
 
 
34
#include <map>
 
35
 
 
36
namespace MathML
 
37
{
 
38
    /** Forward Declaration. */
 
39
    class ErrorHandler;
 
40
 
 
41
    /** ScalarList type definition. */
 
42
    typedef std::vector< AST::ConstantExpression > ScalarList;
 
43
 
 
44
    /** Contains a mapping of variables and functions that may appear in an AST. */
 
45
 
 
46
    class _MATHML_SOLVER_EXPORT SymbolTable
 
47
    {
 
48
 
 
49
    public:
 
50
        /** Function pointer type definition. @todo more explaination */
 
51
        typedef void ( *FunctionPtr ) ( AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler );
 
52
 
 
53
        /** Struct FunctionInfo.
 
54
        @par Holds the count of arguments and the function pointer.
 
55
        */
 
56
 
 
57
        struct FunctionInfo
 
58
        {
 
59
            /** Count of arguments. */
 
60
            int argc;
 
61
 
 
62
            /** The function pointer. */
 
63
            FunctionPtr func;
 
64
 
 
65
            /** C-tor.
 
66
            @param _arguments The count of arguments.
 
67
            @param _func The function pointer.
 
68
            */
 
69
            FunctionInfo( int _arguments = 0, FunctionPtr _func = 0 )
 
70
                    : argc( _arguments ), func( _func )
 
71
            {}
 
72
 
 
73
        }
 
74
 
 
75
        ;
 
76
 
 
77
        /** Map type definition holding function infos. */
 
78
        typedef std::map< String, FunctionInfo > FunctionMap;
 
79
        /** Map type definition holding INode(s). */
 
80
        typedef std::map< String, AST::INode* > VariableMap;
 
81
 
 
82
    private:
 
83
        /** Variables map holding INode as value for its name-key. */
 
84
        VariableMap mVariables;
 
85
        /** Functions map holding FunctionInfo as value for its name-key. */
 
86
        FunctionMap mFunctions;
 
87
 
 
88
        /** Error handler. */
 
89
        ErrorHandler* mErrorHandler;
 
90
 
 
91
    public:
 
92
        /** C-tor. */
 
93
        SymbolTable( ErrorHandler* errorHandler );
 
94
        /** D-tor. */
 
95
        virtual ~SymbolTable();
 
96
 
 
97
                SymbolTable(const SymbolTable& symbolTable);
 
98
                SymbolTable& operator=(const SymbolTable& symbolTable);
 
99
 
 
100
                /** Appends a SymbolTable to this SymbolTable. Variables or functions
 
101
                with the same name were overridden.
 
102
                @param symbolTable The SymbolTable to append.
 
103
                */
 
104
                virtual void appendSymbolTable(const SymbolTable& symbolTable);
 
105
 
 
106
        /** Method for erasing a variable from map for the given mapping name.
 
107
        @par Is the key is found the INode is returned, otherwise zero.
 
108
        @param name The name key to search for in variable map.
 
109
        @return The found INode of the variable or zero.
 
110
        */
 
111
        virtual AST::INode* removeVariable( const String& name );
 
112
 
 
113
        /** Method for retrieving a variable from map for the given mapping name.
 
114
        @param name The name key to search for in variable map.
 
115
        @return The found INode of the variable or zero.
 
116
        */
 
117
        virtual AST::INode* getVariable( const String& name ) const;
 
118
 
 
119
        /** Getter of the variables map.
 
120
        @return The mapping of variables.
 
121
        */
 
122
        virtual const VariableMap& getVariables() const;
 
123
 
 
124
        /** Method for setting a variable in the map.
 
125
        @param name The name of the variable.
 
126
        @param value The INode representing its value (constant or any other expression).
 
127
        @todo: returning old mapping value if there is one
 
128
        */
 
129
        virtual void setVariable( const String& name, AST::INode* value );
 
130
                virtual void setVariable( const String& name, double value );
 
131
                virtual void setVariable( const String& name, long value );
 
132
                virtual void setVariable( const String& name, bool value );
 
133
 
 
134
        /** Method for retrieving the function info from map for the given mapping name.
 
135
        @param name The name key to search for in function map.
 
136
        @return The found FunctionInfo or 0.
 
137
                @throws InvalidParametersException if no function with the fiven name is found.
 
138
        */
 
139
        virtual const FunctionInfo* getFunction( const String& name ) const;
 
140
 
 
141
        /** Getter of the functions map.
 
142
        @return The mapping of functions.
 
143
        */
 
144
        virtual const FunctionMap& getFunctions() const;
 
145
 
 
146
        /** Method for adding a function in the map.
 
147
        @param name The name of the function.
 
148
        @param argc The count of arguments (for FunctionInfo).
 
149
        @param function The function pointer (for FunctionInfo).
 
150
        @todo: returning old mapping value if there is one
 
151
        */
 
152
        virtual void addFunction( const String& name, int argc, FunctionPtr function );
 
153
 
 
154
        /** Method for adding a function in the map.
 
155
        @param name The name of the function.
 
156
        @param function The function info to add to mapping.
 
157
        @todo: returning old mapping value if there is one
 
158
        */
 
159
        virtual void addFunction( const String& name, FunctionInfo function );
 
160
 
 
161
        /** Method for evaluating functions with given arguments.
 
162
        @param result The ConstantExpression reference for storing evaluation value.
 
163
        @param name The name of the function to evaluate.
 
164
        @param evaluatedArgs List of ConstantExpression values as arguments for the function.
 
165
        */
 
166
        virtual void evaluateFunction( AST::ConstantExpression& result, const String& name, const ScalarList& evaluatedArgs );
 
167
 
 
168
                /** Checks if a function exits in this symbol table.
 
169
                @param name The name of the function to evaluate.
 
170
                @return If a function with the given name exists in this symbol table.
 
171
                */
 
172
                virtual bool existsFunction( const String& name ) const;
 
173
 
 
174
                private:
 
175
                        VariableMap::const_iterator findVariable(const String& name) const;
 
176
                        FunctionMap::const_iterator findFunction(const String& name) const;
 
177
                        VariableMap::iterator findVariable(const String& name);
 
178
                        FunctionMap::iterator findFunction(const String& name);
 
179
        };
 
180
}
 
181
 
 
182
#endif //__MATHML_SYMBOL_TABLE_H___