Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / SymTab.h
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 librararies 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
27 #ifndef CDE_NEXT
28
29
30 #else
31 #include "dti_cc/CC_String.h"
32 #include "dti_cc/cc_hdict.h"
33 //#include "StyleSheet/cde_next.h"
34 #include <iostream.h>
35 #endif
36
37 #include "Types.h"
38
39 /* **************************************************************
40  Creating a Symbol Table Class
41  
42  Symbol Table has one user function, intern, which returns a
43  reference to a Symbol  
44
45
46  A Symbol can be compared to other symbols using the == operator.
47  Symbols will only be == if they are the same symbol in the same
48  SymbolTable
49
50  * ************************************************************** */
51
52
53 // forward declarations 
54 class Symbol;
55
56 /* -------- class SymbolName -------- */
57 // derived from CC_String to give a version of  ==
58
59 // should be privately inherited with a few promotions
60
61 class SymbolName : public CC_String
62 {
63 public:
64   SymbolName(const char *);
65   unsigned int operator==(const SymbolName &);
66   ostream &print(ostream &) const ;
67 };
68
69
70
71
72
73 /* **************************************************************
74  SymbolTable derives privately from RWTPtrHashSet so only the
75  SymbolTable has access to internal operations
76  * ************************************************************** */
77
78 class SymbolTable : private hashTable<SymbolName, unsigned int>
79 {
80 public:
81   SymbolTable();
82   ~SymbolTable();
83
84   // intern creates symbol if necessary
85   const Symbol intern(const char *name, unsigned int createId = false) ;
86
87   ostream &print(ostream &) const ;
88
89   unsigned int IdsAssigned() { 
90     return f_IDsAssigned;
91   };
92
93   unsigned int wildCardId() { return f_wildCardId; };
94   unsigned int unlimitedWildCardId() { return f_unlimitedWildCardId; };
95
96 private:
97   static unsigned hashsym(const SymbolName &);
98
99   unsigned int f_wildCardId;
100   unsigned int f_unlimitedWildCardId;
101
102   unsigned int f_IDsAssigned;
103
104 };
105
106
107 /* **************************************************************
108  * class Symbol
109  * ************************************************************** */
110
111 class Symbol  
112 {
113 public:
114   // constructor 
115   Symbol(const Symbol &);
116
117   // assignment 
118   Symbol operator=(const Symbol &other) ;
119
120   const char *name() const;
121   unsigned int operator==(const Symbol &) const; /* identity operator */
122
123   // some methods need to be public
124
125   ostream &print(ostream &) const ;
126
127   // for path table 
128   unsigned int hash() const     { return f_name->hash(); }
129   unsigned int id() const       { return f_id; }
130
131 protected:
132   // alternate constructor 
133   // only SymbolTable::intern can create these 
134   Symbol(const SymbolName *name, unsigned int);
135
136 friend const Symbol SymbolTable::intern(const char *, unsigned int assignId);
137
138 private:  
139   const SymbolName    *f_name ; /* never delete this */
140   unsigned int        f_id;
141 };
142
143
144 /* **************************************************************
145  * external declarations
146  * ************************************************************** */
147
148 ostream &operator<<(ostream &, const Symbol&);
149 ostream &operator<<(ostream &, const SymbolTable&);
150
151
152 #endif /* _SymTab_h */
153 /* DO NOT ADD ANY LINES AFTER THIS #endif */