aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/oo/ObjSelector.h
diff options
context:
space:
mode:
authorcathook <b01902109@csie.ntu.edu.tw>2014-06-24 04:01:53 +0800
committercathook <b01902109@csie.ntu.edu.tw>2014-06-24 04:01:53 +0800
commita9955a1a51df2b268da4d28f9ad10dbaf9815634 (patch)
tree077acbd8e8bf801f517d75b1d5960f883aee5032 /meowpp/oo/ObjSelector.h
parente6f0bcfb63b144da659f28f6f03c51a9b7ae992a (diff)
downloadmeow-a9955a1a51df2b268da4d28f9ad10dbaf9815634.tar
meow-a9955a1a51df2b268da4d28f9ad10dbaf9815634.tar.gz
meow-a9955a1a51df2b268da4d28f9ad10dbaf9815634.tar.bz2
meow-a9955a1a51df2b268da4d28f9ad10dbaf9815634.tar.lz
meow-a9955a1a51df2b268da4d28f9ad10dbaf9815634.tar.xz
meow-a9955a1a51df2b268da4d28f9ad10dbaf9815634.tar.zst
meow-a9955a1a51df2b268da4d28f9ad10dbaf9815634.zip
...
Diffstat (limited to 'meowpp/oo/ObjSelector.h')
-rw-r--r--meowpp/oo/ObjSelector.h43
1 files changed, 22 insertions, 21 deletions
diff --git a/meowpp/oo/ObjSelector.h b/meowpp/oo/ObjSelector.h
index 58d86a0..f08cfe4 100644
--- a/meowpp/oo/ObjSelector.h
+++ b/meowpp/oo/ObjSelector.h
@@ -25,7 +25,7 @@ private:
ObjSelector* parent_;
ObjBase const* pointer_;
bool autoDelete_;
- //
+
Info(ObjSelector* parent,
ObjBase const* ptr,
bool autoDelete) {
@@ -33,6 +33,7 @@ private:
pointer_ = ptr;
autoDelete_ = autoDelete;
}
+
~Info() {
if (autoDelete_) {
delete pointer_;
@@ -44,11 +45,11 @@ private:
};
friend struct Info;
- typedef typename std::map<std::string, Info*> Funcs;
- typedef typename std::map<std::string, Info*>::iterator FuncsIterator;
+ typedef typename std::map<std::string, Info*> Infos;
+ typedef typename std::map<std::string, Info*>::iterator InfosIterator;
- static Funcs& funcs() {
- static Funcs f;
+ static Infos& funcs() {
+ static Infos f;
return f;
}
static Info* add(std::string name,
@@ -69,14 +70,14 @@ public:
static void add(std::string name, ObjBase* obj, bool autoDelete) {
add(name, NULL, obj, autoDelete);
}
-
+
/*!
* @brief 新增(註冊) 一個Class (必須要繼承自 \c ObjBase) 並且默認type為name
*/
static void add(ObjBase* obj, bool autoDelete) {
add(obj->type(), NULL, obj, autoDelete);
}
-
+
/*!
* @brief 依照name刪除之前註冊過得Class
*/
@@ -86,7 +87,7 @@ public:
funcs().erase(name);
}
}
-
+
/*!
* @brief 取得之前註冊過得Class
*/
@@ -94,7 +95,7 @@ public:
if (funcs().find(name) == funcs().end()) return NULL;
return funcs()[name]->pointer_;
}
-
+
/*!
* @brief 回傳一個之前註冊過得Class new出來的實體
*/
@@ -103,12 +104,12 @@ public:
if(ptr == NULL) return NULL;
return ptr->create();
}
-
+
/*!
* @brief 利用type檢查是否有註冊過同種類的Class
*/
static bool exist(ObjBase* obj) {
- for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++) {
+ for (InfosIterator it = funcs().begin(); it != funcs().end(); it++) {
if (it->second->pointer_ == obj ||
(it->second->pointer_ != NULL &&
it->second->pointer_->type() == obj->type())) {
@@ -117,12 +118,12 @@ public:
}
return false;
}
-
+
/*!
* @brief 利用type尋找name
*/
static std::string name(ObjBase* obj) {
- for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++) {
+ for (InfosIterator it = funcs().begin(); it != funcs().end(); it++) {
if (it->second->pointer_ == obj ||
(it->second->pointer_ != NULL &&
it->second->pointer_->type() == obj->type())) {
@@ -131,17 +132,17 @@ public:
}
return std::string();
}
-
+
/*!
* @brief 回傳所有註冊過的name
*/
static std::vector<std::string> names() {
std::vector<std::string> ret;
- for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++)
+ for (InfosIterator it = funcs().begin(); it != funcs().end(); it++)
ret.push_back(it->first);
return ret;
}
-
+
/*!
* @brief 宣告一個ObjSelector實體, 並且註冊一個 ObjBase
*/
@@ -149,7 +150,7 @@ public:
me_.first = name;
me_.second = add(me_.first, this, obj, autoDelete);
}
-
+
/*!
* @brief 宣告一個ObjSelector實體, 並且註冊一個 ObjBase
*/
@@ -157,14 +158,14 @@ public:
me_.first = obj->type();
me_.second = add(me_.first, this, obj, autoDelete);
}
-
+
//! 解構子
~ObjSelector() {
if (me_.second != NULL) {
del(me_.first);
}
}
-
+
/*!
* @brief 將一個物件寫到檔案裡(該物件必須要有註冊過)
*/
@@ -181,7 +182,7 @@ public:
}
return obj->write(f, binary, fg);
}
-
+
/*!
* @brief 從檔案中讀取一個物件(該物件必須要有註冊過)
*/
@@ -208,6 +209,6 @@ public:
static const size_t kGlobalSeletorID = 0;
-}
+} // meow
#endif // oo_ObjSelector_H__