1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#ifndef oo_ObjBase_H__
#define oo_ObjBase_H__
#include <cstdio>
#include <typeinfo>
#include <string>
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__
|