UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
langwrapper.h
Go to the documentation of this file.
1 
2 #ifndef UGDK_SCRIPT_LANGWRAPPER_H_
3 #define UGDK_SCRIPT_LANGWRAPPER_H_
4 
5 #include <string>
6 
7 #include <ugdk/script.h>
8 
9 #include <ugdk/script/defs.h>
10 #include <ugdk/script/type.h>
12 #include <ugdk/script/module.h>
13 
14 namespace ugdk {
15 namespace script {
16 
17 class LangWrapper {
18 
19  public:
20 
21  virtual ~LangWrapper() {}
22 
23  const std::string& file_extension() { return file_extension_; }
24 
25 
27 
30  virtual bool Initialize() = 0;
31 
33  virtual void Finalize() = 0;
34 
35  virtual VirtualData::Ptr NewData() = 0;
36 
37  virtual void ExecuteCode(const std::string& code) = 0;
38 
39  virtual VirtualObj LoadModule(const std::string& name) = 0;
40 
41  LangID lang_id () { return lang_id_; }
42  const std::string& lang_name() const { return lang_name_; }
43 
44  protected:
45 
46  private:
47 
48  template <class loader_t>
49  friend class InheritableLangWrapper;
50 
51  const std::string file_extension_;
52  const LangID lang_id_;
53  const std::string lang_name_;
54 
55  LangWrapper(const std::string& file_extension, const LangID id, const std::string& name) :
56  file_extension_(file_extension),
57  lang_id_(id),
58  lang_name_(name) {}
59 
60  LangWrapper& operator=(const LangWrapper& rhs);
61 
62 };
63 
65 
88 template <class loader_t>
89 class InheritableLangWrapper : public LangWrapper {
90 
91  public:
92 
93  /*bool RegisterModule(const std::string& module_name, loader_t init_func) {
94  return RegisterModule(Module<loader_t>(module_name, init_func));
95  }*/
96 
97  bool RegisterModule(const Module<loader_t>& module) {
98  if (module.name().empty())
99  return false;
100  // TODO: check if name is valid.
101  modules_.push_back(module);
102  return true;
103  }
104 
105  protected:
106 
107  std::vector< Module<loader_t> > modules_;
108 
109  InheritableLangWrapper(const std::string& file_extension, const LangID id, const std::string& name) :
110  LangWrapper(file_extension, id, name) {}
111 
112 };
113 
114 } /* namespace script */
115 } /* namespace ugdk */
116 
117 #endif /* UGDK_SCRIPT_LANGWRAPPER_H_ */
virtual VirtualData::Ptr NewData()=0
LangID lang_id()
Definition: langwrapper.h:41
Definition: animation.h:11
std::shared_ptr< VirtualData > Ptr
Definition: virtualdata.h:46
Definition: script.h:18
bool RegisterModule(const Module< loader_t > &module)
Definition: langwrapper.h:97
virtual VirtualObj LoadModule(const std::string &name)=0
const std::string & file_extension()
Definition: langwrapper.h:23
const std::string & name() const
Definition: module.h:15
std::vector< Module< loader_t > > modules_
Definition: langwrapper.h:107
virtual ~LangWrapper()
Definition: langwrapper.h:21
size_t LangID
Type used for script languages' IDs.
Definition: defs.h:26
virtual bool Initialize()=0
Initializes the LangWrapper.
const std::string & lang_name() const
Definition: langwrapper.h:42
Definition: langwrapper.h:17
A proxy class wich represents virtual objects from scripting languages.
Definition: virtualobj.h:30
virtual void Finalize()=0
Finalizes the LangWrapper, finalizing any language specific stuff.
InheritableLangWrapper(const std::string &file_extension, const LangID id, const std::string &name)
Definition: langwrapper.h:109
virtual void ExecuteCode(const std::string &code)=0
Wraps a scripting language.
Definition: script.h:15