2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 // $XConsortium: SymTab.cc /main/4 1996/06/11 17:09:34 cde-hal $
25 SymbolName::SymbolName(const char *name)
30 unsigned int SymbolName::operator==(const SymbolName &string)
32 return !compareTo(string, exact);
36 SymbolTable::hashsym(const SymbolName &string)
43 SymbolTable::SymbolTable()
44 : hashTable<SymbolName, unsigned int>(hashsym),
47 f_wildCardId = intern("?", true).id();
48 f_unlimitedWildCardId = intern("*", true).id();
51 SymbolTable::~SymbolTable()
54 // cleanup after ourselves
60 SymbolTable::intern(const char *name, unsigned int assignId)
62 //cerr << "intern(): name =<" << name << "> " << "this=" << (void*)this << "\n";
64 SymbolName sym_name(name);
68 const SymbolName *strptr = findKeyAndValue(&sym_name, id);
69 //cerr << "strptr =" << (void*)strptr << "\n";
72 SymbolName *newname = new SymbolName(name);
73 id = new unsigned int((assignId) ? ++f_IDsAssigned : 0);
75 insertKeyAndValue(newname, id);
82 hashTableIterator<SymbolName,unsigned int> next(*this);
84 cout << "intern(" << name << ")" << endl;
86 cout << "\tKey: " << *next.key() << "\tValue: " << *next.value() << endl;
90 //cerr << "Final strptr used =" << (void*)strptr << "\n";
92 return Symbol(strptr, *id);
95 // /////////////////////////////////////////////////////////////////////////
97 // /////////////////////////////////////////////////////////////////////////
99 Symbol::Symbol(const SymbolName *name, unsigned int x)
100 : f_name(name), f_id(x)
104 Symbol::Symbol(const Symbol &sym)
105 : f_name(sym.f_name), f_id(sym.f_id)
111 Symbol::operator=(const Symbol &other)
113 f_name = other.f_name; return *this ;
123 Symbol::operator==(const Symbol &sym) const
125 return sym.f_name == f_name ;
128 // /////////////////////////////////////////////////////////////////////////
130 // /////////////////////////////////////////////////////////////////////////
134 ostream &operator<<(ostream &o, const Symbol &s)
138 ostream &operator<<(ostream &o, const SymbolTable &st)
144 SymbolTable::print(ostream &o) const
146 hashTableIterator<SymbolName, unsigned int>
147 next(*(hashTable<SymbolName, unsigned int>*)this);
152 o << next.key() << endl;
161 Symbol::print(ostream &o) const
165 return o << '(' << id() << ')';
167 return f_name -> print(o);
172 SymbolName::print(ostream &o) const