1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 
14 
15 
16 #ifndef _AllocatorDictionary
17 #define _AllocatorDictionary
18 
19 
20 
21 #include "DefaultingDictionary.h"
22 
23 
24 //
25 // Class name definition:
26 //
27 #define ClassAllocatorDictionary	"AllocatorDictionary"
28 
29 
30 //
31 // Allocator class definition:
32 //
33 #ifndef NO_CC_TEMPLATES
34 template<class Instance, class Allocator>
35 class AllocatorDictionary : public DefaultingDictionary
36 {
37   private:
38     //
39     // Private member data:
40     //
41 
42   protected:
43     //
44     // Protected member data:
45     //
46 
47 
48   public:
49     //
50     // Constructor:
51     //
AllocatorDictionary()52     AllocatorDictionary(){}
53 
54     //
55     // Destructor:
56     //
~AllocatorDictionary()57     ~AllocatorDictionary(){}
58 
59     //
60     // Record a function to be used to do allocation for the 'Instance'
61     // associated with the given name.
62     //
addAllocator(const char * name,Allocator alloc)63     boolean addAllocator(const char *name, Allocator alloc)
64     	{  ASSERT(this); return this->addDefinition(name,(const void*)alloc); }
65 
66     //
67     // Push (intall) a default Allocator onto the stack.
68     //
pushDefaultAllocator(Allocator nda)69     boolean pushDefaultAllocator(Allocator nda)
70 	{ ASSERT(this); return this->pushDefaultDefinition((const void*)nda); }
71 
72     //
73     // Pop the default Allocator from the stack.
74     //
popDefaultAllocator()75     Allocator popDefaultAllocator()
76 	{ ASSERT(this); return (Allocator) this->popDefaultDefinition(); }
77 
findAllocator(const char * name)78     Allocator findAllocator(const char *name)
79 	{ ASSERT(this); return (Allocator) this->findDefinition(name); }
findAllocator(Symbol name)80     Allocator findAllocator(Symbol name)
81 	{ ASSERT(this); return (Allocator) this->findDefinition(name); }
82 
83     //
84     // The following function is to implemented by the subclass and should
85     // provide the following functionality
86     //
87     // Lookup up a function to do 'Instance' allocations for the give name.
88     // If the name has been registered look it up in this dictionary of
89     // allocators.
90     //
91     // Otherwise, use the default allocator (if one exists).
92     // Returns a node definition for the given name, otherwise NULL.
93     //
94     // An Example...
95     //
96     // Instance *allocate(const char *name, ......)
97     //	{    Allocator  a;
98     //       Instance *i = NUL(Instance*);
99     //       a = this->findAllocator(name);
100     //       if (a != NUL(Allocator)) i = a(......);
101     //       return i;
102     //  }
103 
104     //
105     // Returns a pointer to the class name.
106     // Making this virtual forces the subclass to create this
107     // and hopefully allocate().
108     //
109     virtual const char* getClassName() = 0;
110 };
111 #endif    // end NO_CC_TEMPLATES
112 ///////////////////////////////////////////////////////////////////////////////
113 
114 #endif // _AllocatorDictionary
115