1 /********************************************************************************
2 *                                                                               *
3 *                         M e t a C l a s s   O b j e c t                       *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,2020 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 FXMETACLASS_H
22 #define FXMETACLASS_H
23 
24 namespace FX {
25 
26 
27 class FXObject;
28 
29 
30 /// Minimum and maximum message type
31 enum {
32   MINTYPE = 0,
33   MAXTYPE = 65535
34   };
35 
36 
37 /// Minimum and maximum message id
38 enum {
39   MINKEY = 0,
40   MAXKEY = 65535
41   };
42 
43 
44 /// Association key
45 typedef FXuint FXSelector;
46 
47 
48 /// Describes a FOX object
49 class FXAPI FXMetaClass {
50 private:
51   const FXchar       *className;        // Class name
52   FXObject*         (*manufacture)();   // Factory function
53   const FXMetaClass  *baseClass;        // Base classes' metaclass
54   const void         *assoc;            // Associated handlers
55   FXuint              nassocs;          // Count of handlers
56   FXuint              assocsz;          // Size of association
57 private:
58   static const FXMetaClass **metaClassTable;    // Class table
59   static FXuint              metaClassSlots;    // Number of slots
60   static FXuint              metaClassCount;    // Number items
61 private:
62   static void resize(FXuint slots);
63 public:
64 
65   /// Create one metaclass for each class
66   FXMetaClass(const FXchar* name,FXObject *(fac)(),const FXMetaClass* base,const void* ass,FXuint nass,FXuint assz);
67 
68   /// Make instance of some object
69   FXObject* makeInstance() const;
70 
71   /// Search message map
72   const void* search(FXSelector key) const;
73 
74   /// Ask class name
getClassName()75   const FXchar* getClassName() const { return className; }
76 
77   /// Ask base class
getBaseClass()78   const FXMetaClass* getBaseClass() const { return baseClass; }
79 
80   /// Check if metaclass is subclass of some other metaclass
81   FXbool isSubClassOf(const FXMetaClass* metaclass) const;
82 
83   /// Find metaclass object
84   static const FXMetaClass* getMetaClassFromName(const FXchar* name);
85 
86   /// Make NULL object
87   static FXObject* nullObject();
88 
89   /// Destroy metaclass
90  ~FXMetaClass();
91   };
92 
93 }
94 
95 #endif
96