aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/oo
diff options
context:
space:
mode:
authorcathook <b01902109@csie.ntu.edu.tw>2014-04-19 16:21:17 +0800
committercathook <b01902109@csie.ntu.edu.tw>2014-04-19 16:21:17 +0800
commite9a16c4ef0ea782d7db8d788c455ea946eaab039 (patch)
tree5728aa2076a13079f0ff7f162cfd4cab95e1db91 /meowpp/oo
downloadmeow-e9a16c4ef0ea782d7db8d788c455ea946eaab039.tar
meow-e9a16c4ef0ea782d7db8d788c455ea946eaab039.tar.gz
meow-e9a16c4ef0ea782d7db8d788c455ea946eaab039.tar.bz2
meow-e9a16c4ef0ea782d7db8d788c455ea946eaab039.tar.lz
meow-e9a16c4ef0ea782d7db8d788c455ea946eaab039.tar.xz
meow-e9a16c4ef0ea782d7db8d788c455ea946eaab039.tar.zst
meow-e9a16c4ef0ea782d7db8d788c455ea946eaab039.zip
init
Diffstat (limited to 'meowpp/oo')
-rw-r--r--meowpp/oo/Register_Implement.h33
-rw-r--r--meowpp/oo/Register_Implement.hpp24
2 files changed, 57 insertions, 0 deletions
diff --git a/meowpp/oo/Register_Implement.h b/meowpp/oo/Register_Implement.h
new file mode 100644
index 0000000..e46f86c
--- /dev/null
+++ b/meowpp/oo/Register_Implement.h
@@ -0,0 +1,33 @@
+#ifndef REGISTER_IMPLEMENT_H_
+#define REGISTER_IMPLEMENT_H_
+
+#include <map>
+
+namespace meow{
+ template<class T>
+ class ImplementInterface{
+ private:
+ T identify_;
+ protected:
+ ImplementInterface(T const& id): identify_(id) { }
+ public:
+ T const& identify() const { return identify_; }
+ virtual ~ImplementInterface(){ }
+ };
+ //
+ template<class T>
+ class RegisterInterface{
+ private:
+ std::map<T, ImplementInterface<T>*> implements;
+ protected:
+ RegisterInterface();
+ public:
+ virtual bool regImplement(ImplementInterface<T>*imp);
+ virtual ImplementInterface<T>* getImplement(T const& identify);
+ virtual ~RegisterInterface(){ }
+ };
+}
+
+#include "Register_Implement.hpp"
+
+#endif // REGISTER_IMPLEMENT_H_
diff --git a/meowpp/oo/Register_Implement.hpp b/meowpp/oo/Register_Implement.hpp
new file mode 100644
index 0000000..523f266
--- /dev/null
+++ b/meowpp/oo/Register_Implement.hpp
@@ -0,0 +1,24 @@
+
+#include <map>
+
+namespace meow{
+ template<class T>
+ inline RegisterInterface<T>::RegisterInterface(){ }
+ template<class T>
+ inline bool RegisterInterface<T>::regImplement(ImplementInterface<T>* imp){
+ if(implements.find(imp->identify()) != implements.end()){
+ return false;
+ }
+ implements[imp->identify()] = imp;
+ return true;
+ }
+ template<class T>
+ inline ImplementInterface<T>* RegisterInterface<T>::getImplement(
+ T const& identify
+ ){
+ if(implements.find(identify) == implements.end()){
+ return NULL;
+ }
+ return implements[identify];
+ }
+}