]> www.ginac.de Git - cln.git/blob - include/cl_proplist.h
- configure.in, autoconf/aclocal.m4 (CL_GMP_H_VERSION, CL_GMP_CHECK):
[cln.git] / include / cl_proplist.h
1 // Property lists.
2
3 #ifndef _CL_PROPLIST_H
4 #define _CL_PROPLIST_H
5
6 #include "cl_symbol.h"
7 #include "cl_malloc.h"
8
9 // The only extensible way to extend objects at runtime in an extensible
10 // and decentralized way (without having to modify the object's class)
11 // is to add a property table to every object.
12 // For the moment, only very few properties are planned, so lists should be
13 // enough. Since properties represent additional information about the object,
14 // there is no need for removing properties, so singly linked lists will be
15 // enough.
16
17 // This is the base class for all properties.
18 struct cl_property {
19 private:
20         cl_property* next;
21 public:
22         cl_symbol key;
23         // Constructor.
24         cl_property (const cl_symbol& k) : next (NULL), key (k) {}
25         // Destructor.
26         virtual ~cl_property () {}
27         // Allocation and deallocation.
28         void* operator new (size_t size) { return cl_malloc_hook(size); }
29         void operator delete (void* ptr) { cl_free_hook(ptr); }
30 private:
31         virtual void dummy ();
32 // Friend declarations. They are for the compiler. Just ignore them.
33         friend class cl_property_list;
34 };
35 #define SUBCLASS_cl_property() \
36         void* operator new (size_t size) { return cl_malloc_hook(size); } \
37         void operator delete (void* ptr) { cl_free_hook(ptr); }
38
39 struct cl_property_list {
40 private:
41         cl_property* list;
42 public:
43         cl_property* get_property (const cl_symbol& key);
44         void add_property (cl_property* new_property);
45         // Constructor.
46         cl_property_list () : list (NULL) {}
47         // Destructor.
48         ~cl_property_list ();
49 };
50
51 #endif /* _CL_PROPLIST_H */