F:/KPlato/koffice/libs/kofficecore/KoGenericRegistry.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002  *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
00003  *  Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef _KO_GENERIC_REGISTRY_H_
00022 #define _KO_GENERIC_REGISTRY_H_
00023 
00024 #include "KoID.h"
00025 #include <QList>
00026 #include <map>
00027 
00036 template<typename T>
00037 class KoGenericRegistry {
00038 protected:
00039     typedef std::map<KoID, T> storageMap;
00040 public:
00041     KoGenericRegistry() { }
00042     virtual ~KoGenericRegistry() { }
00043 
00044 public:
00049     void add(T item)
00050     {
00051         m_storage.insert( typename storageMap::value_type( item->id(), item) );
00052     }
00058     void add(KoID id, T item)
00059     {
00060         m_storage.insert(typename storageMap::value_type(id, item));
00061     }
00066     T remove(const KoID& name)
00067     {
00068         T p = 0;
00069         typename storageMap::iterator it = m_storage.find(name);
00070         if (it != m_storage.end()) {
00071             m_storage.erase(it);
00072             p = it->second;
00073         }
00074         return p;
00075     }
00081     T remove(const QString& id)
00082     {
00083         return remove(KoID(id,""));
00084     }
00090     T get(const KoID& name) const
00091     {
00092         T p = T(0);
00093         typename storageMap::const_iterator it = m_storage.find(name);
00094         if (it != m_storage.end()) {
00095             p = it->second;
00096         }
00097         return p;
00098     }
00099 
00104     T get(const QString& id) const
00105     {
00106         return get(KoID(id, ""));
00107     }
00108 
00113     bool exists(const KoID& id) const
00114     {
00115         typename storageMap::const_iterator it = m_storage.find(id);
00116         return (it != m_storage.end());
00117     }
00118 
00119     bool exists(const QString& id) const
00120     {
00121         return exists(KoID(id, ""));
00122     }
00129     bool search(const QString& t, KoID& result) const
00130     {
00131         for(typename storageMap::const_iterator it = m_storage.begin();
00132             it != m_storage.end(); ++it)
00133         {
00134             if(it->first.name() == t)
00135             {
00136                 result = it->first;
00137                 return true;
00138             }
00139         }
00140         return false;
00141     }
00142 
00145     QList<KoID> listKeys() const
00146     {
00147         QList<KoID> list;
00148         typename storageMap::const_iterator it = m_storage.begin();
00149         typename storageMap::const_iterator endit = m_storage.end();
00150         while( it != endit )
00151         {
00152             list.append(it->first);
00153             ++it;
00154         }
00155         return list;
00156     }
00157 
00162     QList<QString> keys() const {
00163         QList<QString> answer;
00164         typename storageMap::const_iterator it = m_storage.begin();
00165         typename storageMap::const_iterator endit = m_storage.end();
00166         while( it != endit )
00167         {
00168             answer.append(it->first.id());
00169             ++it;
00170         }
00171         return answer;
00172     }
00173 
00174 protected:
00175     KoGenericRegistry(const KoGenericRegistry&) { }
00176     KoGenericRegistry operator=(const KoGenericRegistry&) { }
00177     storageMap m_storage;
00178 };
00179 
00180 #endif

Généré le Wed Nov 22 23:41:03 2006 pour KPlato par  doxygen 1.5.1-p1