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: NamedResourceTable.h /main/1 1996/07/29 16:58:33 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef NamedResourceTable_INCLUDED
28 #define NamedResourceTable_INCLUDED 1
30 #include "NamedResource.h"
31 #include "PointerTable.h"
37 namespace SP_NAMESPACE {
40 struct NamedResourceKeyFunction {
42 const StringC &key(const NamedResource &p) {
47 template<class T> class NamedResourceTableIter;
48 template<class T> class ConstNamedResourceTableIter;
51 class NamedResourceTable {
54 Ptr<T> _X; // work around lcc bug
58 NamedResourceTable() { }
59 Ptr<T> insert(const Ptr<T> &p, Boolean replace = 0) {
60 return (T *)table_.insert((NamedResource *)p.pointer(), replace).pointer();
62 Ptr<T> lookup(const StringC &str) const {
63 return (T *)table_.lookup(str).pointer();
65 ConstPtr<T> lookupConst(const StringC &str) const {
66 return (T *)table_.lookup(str).pointer();
68 const T *lookupTemp(const StringC &str) const {
69 return (const T *)table_.lookup(str).pointer();
71 Ptr<T> remove(const StringC &str) {
72 return (T *)table_.remove(str).pointer();
74 size_t count() const { return table_.count(); }
75 void clear() { table_.clear(); }
76 void swap(NamedResourceTable<T> &to) { table_.swap(to.table_); }
78 PointerTable<Ptr<NamedResource>, StringC, Hash,
79 NamedResourceKeyFunction> table_;
80 friend class NamedResourceTableIter<T>;
81 friend class ConstNamedResourceTableIter<T>;
85 class NamedResourceTableIter {
87 NamedResourceTableIter(const NamedResourceTable<T> &table)
88 : iter_(table.table_) { }
90 return (T *)iter_.next().pointer();
93 PointerTableIter<Ptr<NamedResource>, StringC, Hash,
94 NamedResourceKeyFunction> iter_;
98 class ConstNamedResourceTableIter {
100 ConstNamedResourceTableIter(const NamedResourceTable<T> &table)
101 : iter_(table.table_) { }
103 return (T *)iter_.next().pointer();
105 const T *nextTemp() {
106 return (const T *)iter_.next().pointer();
109 PointerTableIter<Ptr<NamedResource>, StringC, Hash,
110 NamedResourceKeyFunction> iter_;
117 #endif /* not NamedResourceTable_INCLUDED */