xoreos  0.0.5
functionman.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef AURORA_NWSCRIPT_FUNCTIONMAN_H
26 #define AURORA_NWSCRIPT_FUNCTIONMAN_H
27 
28 #include <vector>
29 #include <map>
30 
31 #include "src/common/ustring.h"
32 #include "src/common/singleton.h"
33 
36 
37 namespace Aurora {
38 
39 namespace NWScript {
40 
41 class FunctionManager : public Common::Singleton<FunctionManager> {
42 public:
43 
46 
47  void clear();
48 
49  void registerFunction(const Common::UString &name, uint32 id, const Function &func,
50  const Signature &signature);
51  void registerFunction(const Common::UString &name, uint32 id, const Function &func,
52  const Signature &signature, const Parameters &defaults);
53 
54  FunctionContext createContext(const Common::UString &function) const;
55  void call(const Common::UString &function, FunctionContext &ctx) const;
56 
57  FunctionContext createContext(uint32 function) const;
58  void call(uint32 function, FunctionContext &ctx) const;
59 
60 private:
61  struct FunctionEntry {
62  bool empty;
63 
66 
67  FunctionEntry(const Common::UString &name = "");
68  };
69 
70  typedef std::map<Common::UString, FunctionEntry> FunctionMap;
71  typedef std::vector<FunctionEntry> FunctionArray;
72 
75 
76  const FunctionEntry &find(const Common::UString &function) const;
77  const FunctionEntry &find(uint32 function) const;
78 };
79 
80 } // End of namespace NWScript
81 
82 } // End of namespace Aurora
83 
84 #define FunctionMan Aurora::NWScript::FunctionManager::instance()
85 
86 #endif // AURORA_NWSCRIPT_FUNCTIONMAN_H
Class and macro for implementing singletons.
std::vector< class Variable > Parameters
Definition: types.h:54
A class holding an UTF-8 string.
Definition: ustring.h:48
Context of an NWScript function.
void call(const Common::UString &function, FunctionContext &ctx) const
Definition: functionman.cpp:87
FunctionContext createContext(const Common::UString &function) const
Definition: functionman.cpp:83
Generic template base class for implementing the singleton design pattern.
Definition: singleton.h:61
FunctionEntry(const Common::UString &name="")
Definition: functionman.cpp:37
std::vector< Type > Signature
Definition: types.h:52
std::map< Common::UString, FunctionEntry > FunctionMap
Definition: functionman.h:70
std::vector< FunctionEntry > FunctionArray
Definition: functionman.h:71
Unicode string handling.
void registerFunction(const Common::UString &name, uint32 id, const Function &func, const Signature &signature)
Definition: functionman.cpp:53
const FunctionEntry & find(const Common::UString &function) const
uint32_t uint32
Definition: types.h:204
NWScript types.
boost::function< void(class FunctionContext &ctx)> Function
Definition: types.h:56