// 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 */