/* * CDE - Common Desktop Environment * * Copyright (c) 1993-2012, The Open Group. All rights reserved. * * These libraries and programs are free software; you can * redistribute them and/or modify them under the terms of the GNU * Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * These libraries and programs are distributed in the hope that * they will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public * License along with these librararies and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ /* $XConsortium: NamedResourceTable.h /main/1 1996/07/29 16:58:33 cde-hp $ */ // Copyright (c) 1994 James Clark // See the file COPYING for copying permission. #ifndef NamedResourceTable_INCLUDED #define NamedResourceTable_INCLUDED 1 #include "NamedResource.h" #include "PointerTable.h" #include "StringC.h" #include "Hash.h" #include "Ptr.h" #ifdef SP_NAMESPACE namespace SP_NAMESPACE { #endif struct NamedResourceKeyFunction { static inline const StringC &key(const NamedResource &p) { return p.name(); } }; template class NamedResourceTableIter; template class ConstNamedResourceTableIter; template class NamedResourceTable { #ifdef __lucid struct X { Ptr _X; // work around lcc bug }; #endif public: NamedResourceTable() { } Ptr insert(const Ptr &p, Boolean replace = 0) { return (T *)table_.insert((NamedResource *)p.pointer(), replace).pointer(); } Ptr lookup(const StringC &str) const { return (T *)table_.lookup(str).pointer(); } ConstPtr lookupConst(const StringC &str) const { return (T *)table_.lookup(str).pointer(); } const T *lookupTemp(const StringC &str) const { return (const T *)table_.lookup(str).pointer(); } Ptr remove(const StringC &str) { return (T *)table_.remove(str).pointer(); } size_t count() const { return table_.count(); } void clear() { table_.clear(); } void swap(NamedResourceTable &to) { table_.swap(to.table_); } private: PointerTable, StringC, Hash, NamedResourceKeyFunction> table_; friend class NamedResourceTableIter; friend class ConstNamedResourceTableIter; }; template class NamedResourceTableIter { public: NamedResourceTableIter(const NamedResourceTable &table) : iter_(table.table_) { } Ptr next() { return (T *)iter_.next().pointer(); } private: PointerTableIter, StringC, Hash, NamedResourceKeyFunction> iter_; }; template class ConstNamedResourceTableIter { public: ConstNamedResourceTableIter(const NamedResourceTable &table) : iter_(table.table_) { } ConstPtr next() { return (T *)iter_.next().pointer(); } const T *nextTemp() { return (const T *)iter_.next().pointer(); } private: PointerTableIter, StringC, Hash, NamedResourceKeyFunction> iter_; }; #ifdef SP_NAMESPACE } #endif #endif /* not NamedResourceTable_INCLUDED */