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