/src/ogre/OgreMain/include/OgreScriptTranslator.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | |
29 | | #ifndef __SCRIPTTRANSLATOR_H_ |
30 | | #define __SCRIPTTRANSLATOR_H_ |
31 | | |
32 | | #include "OgrePrerequisites.h" |
33 | | #include "OgreScriptCompiler.h" |
34 | | #include "OgreRenderSystem.h" |
35 | | #include "OgreHeaderPrefix.h" |
36 | | |
37 | | namespace Ogre{ |
38 | | /** \addtogroup Core |
39 | | * @{ |
40 | | */ |
41 | | /** \addtogroup Script |
42 | | * @{ |
43 | | */ |
44 | | /** This class translates script AST (abstract syntax tree) into |
45 | | * Ogre resources. It defines a common interface for subclasses |
46 | | * which perform the actual translation. |
47 | | */ |
48 | | |
49 | | class _OgreExport ScriptTranslator : public ScriptTranslatorAlloc |
50 | | { |
51 | | public: |
52 | | /** |
53 | | * This function translates the given node into Ogre resource(s). |
54 | | * @param compiler The compiler invoking this translator |
55 | | * @param node The current AST node to be translated |
56 | | */ |
57 | | virtual void translate(ScriptCompiler *compiler, const AbstractNodePtr &node) = 0; |
58 | | protected: |
59 | | // needs virtual destructor |
60 | 0 | virtual ~ScriptTranslator() {} |
61 | | /// Retrieves a new translator from the factories and uses it to process the give node |
62 | | static void processNode(ScriptCompiler *compiler, const AbstractNodePtr &node); |
63 | | |
64 | | /// Retrieves the node iterator at the given index |
65 | | static AbstractNodeList::const_iterator getNodeAt(const AbstractNodeList &nodes, size_t index); |
66 | | /// Converts the node to a boolean and returns true if successful |
67 | | static bool getBoolean(const AbstractNodePtr &node, bool *result); |
68 | | /// Converts the node to a string and returns true if successful |
69 | | static bool getString(const AbstractNodePtr &node, String *result); |
70 | | /// Converts the node to a Real and returns true if successful |
71 | | static bool getReal(const AbstractNodePtr& node, Real* result) |
72 | 0 | { |
73 | 0 | #if OGRE_DOUBLE_PRECISION == 0 |
74 | 0 | return getFloat(node, result); |
75 | | #else |
76 | | return getDouble(node, result); |
77 | | #endif |
78 | 0 | } |
79 | | /// Converts the node to a float and returns true if successful |
80 | | static bool getFloat(const AbstractNodePtr &node, float *result); |
81 | | /// Converts the node to a float and returns true if successful |
82 | | static bool getDouble(const AbstractNodePtr &node, double *result); |
83 | | /// Converts the node to an integer and returns true if successful |
84 | | static bool getInt(const AbstractNodePtr &node, int *result); |
85 | | /// Converts the node to an unsigned integer and returns true if successful |
86 | | static bool getUInt(const AbstractNodePtr &node, uint32 *result); |
87 | | /// Converts the range of nodes to a ColourValue and returns true if successful |
88 | | static bool getColour(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, ColourValue *result, int maxEntries = 4); |
89 | | /// Converts the node to a SceneBlendFactor enum and returns true if successful |
90 | | static bool getSceneBlendFactor(const AbstractNodePtr &node, SceneBlendFactor *sbf); |
91 | | /// Converts the node to a CompareFunction enum and returns true if successful |
92 | | static bool getCompareFunction(const AbstractNodePtr &node, CompareFunction *func); |
93 | | /// Converts the range of nodes to a Matrix4 and returns true if successful |
94 | | static bool getMatrix4(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, Matrix4 *m); |
95 | | /// @deprecated use getVector |
96 | | OGRE_DEPRECATED static bool getInts(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, int *vals, int count); |
97 | | /// @deprecated use getVector |
98 | | OGRE_DEPRECATED static bool getFloats(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, float *vals, int count); |
99 | | /// @deprecated |
100 | | OGRE_DEPRECATED static bool getDoubles(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, double *vals, int count); |
101 | | /// @deprecated |
102 | | OGRE_DEPRECATED static bool getUInts(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, uint *vals, int count); |
103 | | /// @deprecated |
104 | | OGRE_DEPRECATED static bool getBooleans(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, uint *vals, int count); |
105 | | /// read count values from the AbstractNodeList into vals. Fill with default value if AbstractNodeList is shorter then count |
106 | | static bool getVector(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, std::vector<int>& vals, size_t count); |
107 | | /// @overload |
108 | | static bool getVector(AbstractNodeList::const_iterator i, AbstractNodeList::const_iterator end, std::vector<float>& vals, size_t count); |
109 | | /// Converts the node to a StencilOperation enum and returns true if successful |
110 | | static bool getStencilOp(const AbstractNodePtr &node, StencilOperation *op); |
111 | | /// Converts the node to a GpuConstantType enum and returns true if successful |
112 | | static bool getConstantType(AbstractNodeList::const_iterator i, GpuConstantType *op); |
113 | | |
114 | | template<typename T> |
115 | | friend bool getValue(const AbstractNodePtr &node, T& result); |
116 | | }; |
117 | | |
118 | | /** The ScriptTranslatorManager manages the lifetime and access to |
119 | | * script translators. You register these managers with the |
120 | | * ScriptCompilerManager tied to specific object types. |
121 | | * Each manager may manage multiple types. |
122 | | */ |
123 | | class _OgreExport ScriptTranslatorManager : public ScriptTranslatorAlloc |
124 | | { |
125 | | public: |
126 | | // required - virtual destructor |
127 | 0 | virtual ~ScriptTranslatorManager() {} |
128 | | |
129 | | /// Returns a manager for the given object abstract node, or null if it is not supported |
130 | | virtual ScriptTranslator *getTranslator(const AbstractNodePtr&) = 0; |
131 | | }; |
132 | | /** @} */ |
133 | | /** @} */ |
134 | | } |
135 | | |
136 | | #include "OgreHeaderSuffix.h" |
137 | | |
138 | | #endif |
139 | | |