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.

51 lines
1.5 KiB

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