SymTab.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: SymTab.h /main/5 1996/08/21 15:50:57 drk $ */
  24. #ifndef _SymTab_h
  25. #define _SymTab_h
  26. #ifndef CDE_NEXT
  27. #else
  28. #include "dti_cc/CC_String.h"
  29. #include "dti_cc/cc_hdict.h"
  30. //#include "StyleSheet/cde_next.h"
  31. #include <iostream>
  32. using namespace std;
  33. #endif
  34. #include "Types.h"
  35. /* **************************************************************
  36. Creating a Symbol Table Class
  37. Symbol Table has one user function, intern, which returns a
  38. reference to a Symbol
  39. A Symbol can be compared to other symbols using the == operator.
  40. Symbols will only be == if they are the same symbol in the same
  41. SymbolTable
  42. * ************************************************************** */
  43. // forward declarations
  44. class Symbol;
  45. /* -------- class SymbolName -------- */
  46. // derived from CC_String to give a version of ==
  47. // should be privately inherited with a few promotions
  48. class SymbolName : public CC_String
  49. {
  50. public:
  51. SymbolName(const char *);
  52. unsigned int operator==(const SymbolName &);
  53. ostream &print(ostream &) const ;
  54. };
  55. /* **************************************************************
  56. SymbolTable derives privately from RWTPtrHashSet so only the
  57. SymbolTable has access to internal operations
  58. * ************************************************************** */
  59. class SymbolTable : private hashTable<SymbolName, unsigned int>
  60. {
  61. public:
  62. SymbolTable();
  63. ~SymbolTable();
  64. // intern creates symbol if necessary
  65. const Symbol intern(const char *name, unsigned int createId = false) ;
  66. ostream &print(ostream &) const ;
  67. unsigned int IdsAssigned() {
  68. return f_IDsAssigned;
  69. };
  70. unsigned int wildCardId() { return f_wildCardId; };
  71. unsigned int unlimitedWildCardId() { return f_unlimitedWildCardId; };
  72. private:
  73. static unsigned hashsym(const SymbolName &);
  74. unsigned int f_wildCardId;
  75. unsigned int f_unlimitedWildCardId;
  76. unsigned int f_IDsAssigned;
  77. };
  78. /* **************************************************************
  79. * class Symbol
  80. * ************************************************************** */
  81. class Symbol
  82. {
  83. public:
  84. // constructor
  85. Symbol(const Symbol &);
  86. // assignment
  87. Symbol operator=(const Symbol &other) ;
  88. const char *name() const;
  89. unsigned int operator==(const Symbol &) const; /* identity operator */
  90. // some methods need to be public
  91. ostream &print(ostream &) const ;
  92. // for path table
  93. unsigned int hash() const { return f_name->hash(); }
  94. unsigned int id() const { return f_id; }
  95. protected:
  96. // alternate constructor
  97. // only SymbolTable::intern can create these
  98. Symbol(const SymbolName *name, unsigned int);
  99. friend const Symbol SymbolTable::intern(const char *, unsigned int assignId);
  100. private:
  101. const SymbolName *f_name ; /* never delete this */
  102. unsigned int f_id;
  103. };
  104. /* **************************************************************
  105. * external declarations
  106. * ************************************************************** */
  107. ostream &operator<<(ostream &, const Symbol&);
  108. ostream &operator<<(ostream &, const SymbolTable&);
  109. #endif /* _SymTab_h */
  110. /* DO NOT ADD ANY LINES AFTER THIS #endif */