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

FXObject.h
1 /********************************************************************************
2 * *
3 * T o p l e v e l O b j e c t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2024 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 FXCALLBACK_H
25 #include "FXCallback.h"
26 #endif
27 
28 #ifndef FXMETACLASS_H
29 #include "FXMetaClass.h"
30 #endif
31 
32 namespace FX {
33 
34 
35 class FXStream;
36 
37 
39 enum {
40  MINTYPE = 0,
41  MAXTYPE = 65535
42  };
43 
45 enum {
46  MINKEY = 0,
47  MAXKEY = 65535
48  };
49 
50 
52 #define FXDECLARE(classname) \
53  public: \
54  struct FXMapEntry { FX::FXSelector keylo; FX::FXSelector keyhi; long (classname::* func)(FX::FXObject*,FX::FXSelector,void*); }; \
55  static const FX::FXMetaClass metaClass; \
56  static FX::FXObject* manufacture(); \
57  virtual const FX::FXMetaClass* getMetaClass() const; \
58  virtual long handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr); \
59  private:
60 
61 
63 #define FXIMPLEMENT(classname,baseclassname,mapping,nmappings) \
64  FX::FXObject* classname::manufacture(){return new classname;} \
65  const FX::FXMetaClass classname::metaClass(#classname,classname::manufacture,&baseclassname::metaClass,mapping,nmappings,sizeof(classname::FXMapEntry)); \
66  const FX::FXMetaClass* classname::getMetaClass() const { return &classname::metaClass; } \
67  long classname::handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr){ \
68  const FXMapEntry* me=(const FXMapEntry*)metaClass.search(sel); \
69  return me ? (this->* me->func)(sender,sel,ptr) : baseclassname::handle(sender,sel,ptr); \
70  }
71 
72 
74 #define FXDECLARE_ABSTRACT(classname) \
75  public: \
76  struct FXMapEntry { FX::FXSelector keylo; FX::FXSelector keyhi; long (classname::* func)(FX::FXObject*,FX::FXSelector,void*); }; \
77  static const FX::FXMetaClass metaClass; \
78  virtual const FX::FXMetaClass* getMetaClass() const; \
79  virtual long handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr); \
80  private:
81 
82 
84 #define FXIMPLEMENT_ABSTRACT(classname,baseclassname,mapping,nmappings) \
85  const FX::FXMetaClass classname::metaClass(#classname,FX::FXMetaClass::nullObject,&baseclassname::metaClass,mapping,nmappings,sizeof(classname::FXMapEntry)); \
86  const FX::FXMetaClass* classname::getMetaClass() const { return &classname::metaClass; } \
87  long classname::handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr){ \
88  const FXMapEntry* me=(const FXMapEntry*)metaClass.search(sel); \
89  return me ? (this->* me->func)(sender,sel,ptr) : baseclassname::handle(sender,sel,ptr); \
90  }
91 
92 
94 #define FXMETACLASS(classname) (&classname::metaClass)
95 
96 
98 #define FXDEFMAP(classname) static const classname::FXMapEntry
99 
101 #define FXMAPTYPES(typelo,typehi,func) {FXSEL(typelo,FX::MINKEY),FXSEL(typehi,FX::MAXKEY),&func}
102 
104 #define FXMAPTYPE(type,func) {FXSEL(type,FX::MINKEY),FXSEL(type,FX::MAXKEY),&func}
105 
107 #define FXMAPFUNCS(type,keylo,keyhi,func) {FXSEL(type,keylo),FXSEL(type,keyhi),&func}
108 
110 #define FXMAPFUNC(type,key,func) {FXSEL(type,key),FXSEL(type,key),&func}
111 
112 
113 //#define NEWMAP 1
114 #if defined(NEWMAP)
115 
116 typedef FXCallback<long (FXObject*,FXSelector,FXptr)> FXMessageCallback;
117 
118 
119 typedef FXMessageCallback::Method FXMessageCallbackWrapper;
120 
121 struct NewMapEntry {
122  FX::FXSelector keylo;
123  FX::FXSelector keyhi;
124  FX::FXMessageCallbackWrapper method;
125  };
126 
127 #endif
128 
138 class FXAPI FXObject {
139  FXDECLARE(FXObject)
140 public:
141 
143  const FXchar* getClassName() const;
144 
146  FXbool isMemberOf(const FXMetaClass* metaclass) const;
147 
149  virtual long tryHandle(FXObject* sender,FXSelector sel,void* ptr);
150 
152  virtual long onDefault(FXObject*,FXSelector,void*);
153 
155  virtual void save(FXStream& store) const;
156 
158  virtual void load(FXStream& store);
159 
161  virtual ~FXObject();
162  };
163 
164 }
165 
166 #endif
Describes a FOX object.
Definition: FXMetaClass.h:34
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
Definition: FX4Splitter.h:28
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:138

Copyright © 1997-2022 Jeroen van der Zijp