Templates -- Meow  204.13.18
A C++ template contains kinds of interesting classes and functions
ObjBase.h
Go to the documentation of this file.
1 #ifndef oo_ObjBase_H__
2 #define oo_ObjBase_H__
3 
4 #include <cstdio>
5 #include <typeinfo>
6 #include <string>
7 
8 namespace meow {
9 
15 class ObjBase {
16 protected:
17 
21  ObjBase() { }
22 public:
23  virtual ~ObjBase() { }
24 
33  virtual bool write(FILE* f, bool bin, unsigned int fg) const {
34  return false;
35  }
36 
45  virtual bool read(FILE* f, bool bin, unsigned int fg) {
46  return false;
47  }
48 
52  virtual ObjBase* create() const {
53  return NULL;
54  }
55 
62  virtual ObjBase* copyFrom(ObjBase const* b) {
63  (*this) = (*b);
64  return this;
65  }
66 
70  virtual char const* ctype() const {
71  return typeid(*this).name();
72  }
73 
77  virtual std::string type() const {
78  return std::string(ctype());
79  }
80 
84  static char const* ctypeBase() {
85  return typeid(ObjBase).name();
86  }
87 
91  static std::string typeBase() {
92  static std::string s(ctypeBase());
93  return s;
94  }
95 };
96 
97 } // meow
98 
99 #endif // oo_ObjBase_H__
static char const * ctypeBase()
用C-style string回傳base的type name
Definition: ObjBase.h:84
virtual ObjBase * create() const
回傳一個new出來的物件, 預設implement為直接回傳 NULL
Definition: ObjBase.h:52
一切物件的Base, 並要求每個物件都要有read, write, create, ... 等功能
Definition: ObjBase.h:15
virtual ObjBase * copyFrom(ObjBase const *b)
複製, 預設使用operator=
Definition: ObjBase.h:62
virtual char const * ctype() const
用C-style string回傳這個class的type name
Definition: ObjBase.h:70
virtual ~ObjBase()
Definition: ObjBase.h:23
virtual bool read(FILE *f, bool bin, unsigned int fg)
將物件從檔案讀出, 預設implement為直接回傳 false
Definition: ObjBase.h:45
ObjBase()
Constructor with doing nothing.
Definition: ObjBase.h:21
static std::string typeBase()
用std::string回傳base的type name
Definition: ObjBase.h:91
virtual bool write(FILE *f, bool bin, unsigned int fg) const
將物件寫入檔案, 預設implement為直接回傳 false
Definition: ObjBase.h:33
virtual std::string type() const
用std::string回傳這個class的type name
Definition: ObjBase.h:77