UGDK
|
00001 00002 #ifndef UGDK_SCRIPT_LANGWRAPPER_H_ 00003 #define UGDK_SCRIPT_LANGWRAPPER_H_ 00004 00005 #include <string> 00006 00007 #include <ugdk/script/defs.h> 00008 #include <ugdk/script/type.h> 00009 #include <ugdk/script/virtualdata.h> 00010 #include <ugdk/script/module.h> 00011 00012 namespace ugdk { 00013 namespace script { 00014 00015 class VirtualObj; 00016 template <class loader_t> class InheritableLangWrapper; 00017 00018 class LangWrapper { 00019 00020 public: 00021 00022 virtual ~LangWrapper() {} 00023 00024 const std::string& file_extension() { return file_extension_; } 00025 00026 00028 00031 virtual bool Initialize() = 0; 00032 00034 virtual void Finalize() = 0; 00035 00036 virtual VirtualData::Ptr NewData() = 0; 00037 00038 virtual void ExecuteCode(const std::string& code) = 0; 00039 00040 virtual VirtualObj LoadModule(const std::string& name) = 0; 00041 00042 const LangID lang_id () { return lang_id_; } 00043 00044 protected: 00045 00046 private: 00047 00048 template <class loader_t> 00049 friend class InheritableLangWrapper; 00050 00051 const std::string file_extension_; 00052 const LangID lang_id_; 00053 00054 LangWrapper(const std::string& file_extension, const LangID id) : 00055 file_extension_(file_extension), 00056 lang_id_(id) {} 00057 00058 LangWrapper& operator=(const LangWrapper& rhs); 00059 00060 }; 00061 00063 00086 template <class loader_t> 00087 class InheritableLangWrapper : public LangWrapper { 00088 00089 public: 00090 00091 /*bool RegisterModule(const std::string& module_name, loader_t init_func) { 00092 return RegisterModule(Module<loader_t>(module_name, init_func)); 00093 }*/ 00094 00095 bool RegisterModule(const Module<loader_t>& module) { 00096 if (module.name().empty()) 00097 return false; 00098 // TODO: check if name is valid. 00099 modules_.push_back(module); 00100 return true; 00101 } 00102 00103 protected: 00104 00105 std::vector< Module<loader_t> > modules_; 00106 00107 InheritableLangWrapper(const std::string& file_extension, const LangID id) : 00108 LangWrapper(file_extension, id) {} 00109 00110 }; 00111 00112 } /* namespace script */ 00113 } /* namespace ugdk */ 00114 00115 #endif /* UGDK_SCRIPT_LANGWRAPPER_H_ */