#ifndef oo_ObjBase_H__ #define oo_ObjBase_H__ #include #include #include namespace meow { /*! * @brief 一切物件的Base, 並要求每個物件都要有read, write, create, ... 等功能 * * @author cathook */ class ObjBase { protected: ObjBase(){ } public: virtual ~ObjBase(){ } /*! * @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__