aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/oo/ObjBase.h
blob: 974fdf11c62a93d7e0903c22bdaf4765a0f4904c (plain) (blame)
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
#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(){ }
  //
  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()); }
};

}

#endif // oo_ObjBase_H__