Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXObject.h
1 /********************************************************************************
2 * *
3 * T o p l e v el O b j e c t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXOBJECT_H
22 #define FXOBJECT_H
23 
24 #ifndef FXMETACLASS_H
25 #include "FXMetaClass.h"
26 #endif
27 
28 namespace FX {
29 
30 
32 #define FXDECLARE(classname) \
33  public: \
34  struct FXMapEntry { FX::FXSelector keylo; FX::FXSelector keyhi; long (classname::* func)(FX::FXObject*,FX::FXSelector,void*); }; \
35  static const FX::FXMetaClass metaClass; \
36  static FX::FXObject* manufacture(); \
37  virtual long handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr); \
38  virtual const FX::FXMetaClass* getMetaClass() const { return &metaClass; } \
39  friend FX::FXStream& operator<<(FX::FXStream& store,const classname* obj){return store.saveObject((const FX::FXObject*)(obj));} \
40  friend FX::FXStream& operator>>(FX::FXStream& store,classname*& obj){return store.loadObject((FX::FXObject*&)(obj));} \
41  private:
42 
43 
45 #define FXIMPLEMENT(classname,baseclassname,mapping,nmappings) \
46  FX::FXObject* classname::manufacture(){return new classname;} \
47  const FX::FXMetaClass classname::metaClass(#classname,classname::manufacture,&baseclassname::metaClass,mapping,nmappings,sizeof(classname::FXMapEntry)); \
48  long classname::handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr){ \
49  const FXMapEntry* me=(const FXMapEntry*)metaClass.search(sel); \
50  return me ? (this->* me->func)(sender,sel,ptr) : baseclassname::handle(sender,sel,ptr); \
51  }
52 
53 
55 #define FXDECLARE_ABSTRACT(classname) \
56  public: \
57  struct FXMapEntry { FX::FXSelector keylo; FX::FXSelector keyhi; long (classname::* func)(FX::FXObject*,FX::FXSelector,void*); }; \
58  static const FX::FXMetaClass metaClass; \
59  virtual long handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr); \
60  virtual const FX::FXMetaClass* getMetaClass() const { return &metaClass; } \
61  friend FX::FXStream& operator<<(FX::FXStream& store,const classname* obj){return store.saveObject((const FX::FXObject*)(obj));} \
62  friend FX::FXStream& operator>>(FX::FXStream& store,classname*& obj){return store.loadObject((FX::FXObject*&)(obj));} \
63  private:
64 
65 
67 #define FXIMPLEMENT_ABSTRACT(classname,baseclassname,mapping,nmappings) \
68  const FX::FXMetaClass classname::metaClass(#classname,FX::FXMetaClass::nullObject,&baseclassname::metaClass,mapping,nmappings,sizeof(classname::FXMapEntry)); \
69  long classname::handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr){ \
70  const FXMapEntry* me=(const FXMapEntry*)metaClass.search(sel); \
71  return me ? (this->* me->func)(sender,sel,ptr) : baseclassname::handle(sender,sel,ptr); \
72  }
73 
74 
76 #define FXMETACLASS(classname) (&classname::metaClass)
77 
78 
80 #define FXDEFMAP(classname) static const classname::FXMapEntry
81 
83 #define FXMAPTYPES(typelo,typehi,func) {FXSEL(typelo,FX::MINKEY),FXSEL(typehi,FX::MAXKEY),&func}
84 
86 #define FXMAPTYPE(type,func) {FXSEL(type,FX::MINKEY),FXSEL(type,FX::MAXKEY),&func}
87 
89 #define FXMAPFUNCS(type,keylo,keyhi,func) {FXSEL(type,keylo),FXSEL(type,keyhi),&func}
90 
92 #define FXMAPFUNC(type,key,func) {FXSEL(type,key),FXSEL(type,key),&func}
93 
94 
104 class FXAPI FXObject {
105  FXDECLARE(FXObject)
106 public:
107 
109  const FXchar* getClassName() const;
110 
112  FXbool isMemberOf(const FXMetaClass* metaclass) const;
113 
115  virtual long tryHandle(FXObject* sender,FXSelector sel,void* ptr);
116 
118  virtual long onDefault(FXObject*,FXSelector,void*);
119 
121  virtual void save(FXStream& store) const;
122 
124  virtual void load(FXStream& store);
125 
127  virtual ~FXObject();
128  };
129 
130 }
131 
132 #endif

Copyright © 1997-2016 Jeroen van der Zijp