00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */ 00002 00003 /* 00004 * Copyright (c) 2008 Ciaran McCreesh 00005 * 00006 * This file is part of the Paludis package manager. Paludis is free software; 00007 * you can redistribute it and/or modify it under the terms of the GNU General 00008 * Public License version 2, as published by the Free Software Foundation. 00009 * 00010 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY 00011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00013 * details. 00014 * 00015 * You should have received a copy of the GNU General Public License along with 00016 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00017 * Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 #ifndef PALUDIS_GUARD_PALUDIS_METADATA_KEY_HOLDER_HH 00021 #define PALUDIS_GUARD_PALUDIS_METADATA_KEY_HOLDER_HH 1 00022 00023 #include <paludis/metadata_key_holder-fwd.hh> 00024 #include <paludis/util/private_implementation_pattern.hh> 00025 #include <paludis/util/wrapped_forward_iterator-fwd.hh> 00026 #include <paludis/metadata_key-fwd.hh> 00027 #include <tr1/memory> 00028 00029 namespace paludis 00030 { 00031 /** 00032 * Generic interface for any class that holds a number of MetadataKey 00033 * instances. 00034 * 00035 * \since 0.26 00036 * \ingroup g_metadata_key 00037 */ 00038 class PALUDIS_VISIBLE MetadataKeyHolder : 00039 private PrivateImplementationPattern<MetadataKeyHolder> 00040 { 00041 protected: 00042 /** 00043 * Add a new MetadataKey, which must not use the same raw name as 00044 * any previous MetadataKey added to this ID. 00045 */ 00046 virtual void add_metadata_key(const std::tr1::shared_ptr<const MetadataKey> &) const; 00047 00048 /** 00049 * Clear all MetadataKey instances added using add_metadata_key. 00050 */ 00051 virtual void clear_metadata_keys() const; 00052 00053 /** 00054 * This method will be called before any of the metadata key 00055 * iteration methods does its work. It can be used by subclasses to 00056 * implement as-needed loading of keys. 00057 */ 00058 virtual void need_keys_added() const = 0; 00059 00060 public: 00061 MetadataKeyHolder(); 00062 virtual ~MetadataKeyHolder() = 0; 00063 00064 ///\name Finding and iterating over metadata keys 00065 ///\{ 00066 00067 struct MetadataConstIteratorTag; 00068 typedef WrappedForwardIterator<MetadataConstIteratorTag, std::tr1::shared_ptr<const MetadataKey> > MetadataConstIterator; 00069 00070 MetadataConstIterator begin_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result)); 00071 MetadataConstIterator end_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result)); 00072 MetadataConstIterator find_metadata(const std::string &) const PALUDIS_ATTRIBUTE((warn_unused_result)); 00073 00074 ///\} 00075 }; 00076 } 00077 00078 #endif