aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/oo/ObjBase.h
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp/oo/ObjBase.h')
-rw-r--r--meowpp/oo/ObjBase.h95
1 files changed, 74 insertions, 21 deletions
diff --git a/meowpp/oo/ObjBase.h b/meowpp/oo/ObjBase.h
index 974fdf1..0ae9427 100644
--- a/meowpp/oo/ObjBase.h
+++ b/meowpp/oo/ObjBase.h
@@ -2,11 +2,10 @@
#define oo_ObjBase_H__
#include <cstdio>
-
#include <typeinfo>
#include <string>
-namespace meow{
+namespace meow {
/*!
* @brief 一切物件的Base, 並要求每個物件都要有read, write, create, ... 等功能
@@ -18,26 +17,80 @@ protected:
ObjBase(){ }
public:
virtual ~ObjBase(){ }
- //
- virtual bool write(FILE* f,bool bin,unsigned int fg) const { return false; }
- virtual bool read(FILE* f,bool bin,unsigned int fg) { return false; }
- //
- virtual ObjBase* create() const { return NULL; }
- virtual ObjBase* copyFrom(ObjBase const* b) { (*this) = (*b); return this; }
- //
- virtual char const* ctype() const{
- static char const* ptr = typeid(*this).name();
- return ptr;
- }
- virtual std::string type() const{ return std::string(ctype()); }
- //
- static char const* ctypeBase(){
- static char const* ptr = typeid(ObjBase).name();
- return ptr;
- }
- static std::string typeBase(){ return std::string(ctypeBase()); }
+
+ /*!
+ * @brief 將物件寫入檔案, 預設implement為直接回傳 \c false
+ *
+ * @param [in] f 檔案
+ * @param [in] bin 是否為binary模式
+ * @param [in] fg 使用者自訂的argument
+ * @return 成功或失敗
+ */
+ virtual bool write(FILE* f, bool bin, unsigned int fg) const {
+ return false;
+ }
+
+ /*!
+ * @brief 將物件從檔案讀出, 預設implement為直接回傳 \c false
+ *
+ * @param [in] f 檔案
+ * @param [in] bin 是否為binary模式
+ * @param [in] fg 使用者自訂的argument
+ * @return 成功或失敗
+ */
+ virtual bool read(FILE* f, bool bin, unsigned int fg) {
+ return false;
+ }
+
+ /*!
+ * @brief 回傳一個new出來的物件, 預設implement為直接回傳 \c NULL
+ */
+ virtual ObjBase* create() const {
+ return NULL;
+ }
+
+ /*!
+ * @brief 複製, 預設使用operator=
+ *
+ * @param [in] b 資料來源
+ * @return \c this
+ */
+ virtual ObjBase* copyFrom(ObjBase const* b) {
+ (*this) = (*b);
+ return this;
+ }
+
+ /*!
+ * @brief 用C-style string回傳這個class的type name
+ */
+ virtual char const* ctype() const {
+ return typeid(*this).name();
+ }
+
+ /*!
+ * @brief 用std::string回傳這個class的type name
+ */
+ virtual std::string type() const {
+ static std::string s(ctype());
+ return s;
+ }
+
+ /*!
+ * @brief 用C-style string回傳base的type name
+ */
+ static char const* ctypeBase() {
+ return typeid(ObjBase).name();
+ }
+
+ /*!
+ * @brief 用std::string回傳base的type name
+ */
+ static std::string typeBase() {
+ static std::string s(ctypeBase());
+ return s;
+ }
};
-}
+} // meow
#endif // oo_ObjBase_H__