You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

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