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.

50 lines
1.3 KiB

25 years ago
  1. // Symbols.
  2. #ifndef _CL_SYMBOL_H
  3. #define _CL_SYMBOL_H
  4. #include "cl_string.h"
  5. // Symbols are just strings, uniquified through a global hash table.
  6. #if (defined(__alpha__) && !defined(__GNUC__))
  7. struct hashuniq;
  8. #endif
  9. struct cl_symbol : public cl_rcpointer {
  10. public:
  11. // Conversion to string.
  12. operator cl_string () const;
  13. // Constructors.
  14. cl_symbol (const cl_string&); // create or lookup a symbol from its name
  15. cl_symbol (const cl_symbol&);
  16. // Assignment operators.
  17. cl_symbol& operator= (const cl_symbol&);
  18. // Private pointer manipulations.
  19. cl_symbol (cl_private_thing p) : cl_rcpointer (p) {}
  20. public: /* ugh */
  21. // Create a new symbol given its name.
  22. cl_symbol (struct hashuniq * null, const cl_string& s);
  23. };
  24. CL_DEFINE_COPY_CONSTRUCTOR2(cl_symbol,cl_rcpointer)
  25. CL_DEFINE_ASSIGNMENT_OPERATOR(cl_symbol,cl_symbol)
  26. // A symbol points to a string, so to convert cl_symbol -> cl_string, we just
  27. // take the pointer and put it into a cl_string.
  28. inline cl_symbol::operator cl_string () const
  29. {
  30. return cl_string(_as_cl_private_thing());
  31. }
  32. // Comparison.
  33. inline bool equal (const cl_symbol& s1, const cl_symbol& s2)
  34. {
  35. return (s1.pointer == s2.pointer);
  36. }
  37. // Hash code.
  38. extern unsigned long hashcode (const cl_symbol& s);
  39. CL_REQUIRE(cl_symbol)
  40. #endif /* _CL_SYMBOL_H */