paludis  Version 2.6.0
contents.hh
Go to the documentation of this file.
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh
5  *
6  * This file is part of the Paludis package manager. Paludis is free software;
7  * you can redistribute it and/or modify it under the terms of the GNU General
8  * Public License version 2, as published by the Free Software Foundation.
9  *
10  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17  * Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef PALUDIS_GUARD_PALUDIS_CONTENTS_HH
21 #define PALUDIS_GUARD_PALUDIS_CONTENTS_HH 1
22 
23 #include <paludis/contents-fwd.hh>
24 #include <paludis/util/visitor.hh>
25 #include <paludis/util/pimp.hh>
26 #include <paludis/util/type_list.hh>
27 #include <paludis/util/wrapped_forward_iterator.hh>
28 #include <paludis/util/fs_path-fwd.hh>
29 #include <paludis/metadata_key_holder.hh>
30 #include <memory>
31 #include <string>
32 
33 /** \file
34  * Declarations for the Contents classes.
35  *
36  * \ingroup g_contents
37  *
38  * \section Examples
39  *
40  * - \ref example_contents.cc "example_contents.cc"
41  */
42 
43 namespace paludis
44 {
45  /**
46  * Base class for a contents entry.
47  *
48  * \since 0.36 for MetadataKeyHolder methods.
49  *
50  * \ingroup g_contents
51  * \nosubgrouping
52  */
54  public MetadataKeyHolder,
55  public virtual DeclareAbstractAcceptMethods<ContentsEntry, MakeTypeList<
56  ContentsFileEntry, ContentsDirEntry, ContentsSymEntry, ContentsOtherEntry>::Type>
57  {
58  private:
60 
61  protected:
62  virtual void need_keys_added() const;
63 
64  public:
65  ///\name Basic operations
66  ///\{
67 
68  ContentsEntry(const FSPath & path);
69  virtual ~ContentsEntry() = 0;
70 
71  ///\}
72 
73  ///\name Metadata key operations
74  ///\{
75 
76  /**
77  * Must be called straight after construction.
78  *
79  * \since 0.36
80  */
82 
83  ///\}
84 
85  ///\name Specific metadata keys
86  ///\{
87 
88  /**
89  * Our path on disk. Must not be zero. Not modified for root.
90  *
91  * \since 0.36
92  */
93  const std::shared_ptr<const MetadataValueKey<FSPath> > location_key() const;
94 
95  ///\}
96 
97  ///\}
98  };
99 
100  /**
101  * A file contents entry.
102  *
103  * \ingroup g_contents
104  * \nosubgrouping
105  */
107  public ContentsEntry,
108  public ImplementAcceptMethods<ContentsEntry, ContentsFileEntry>
109  {
110  private:
112 
113  public:
114  ///\name Basic operations
115  ///\{
116 
117  ContentsFileEntry(const FSPath &, const std::string &);
119 
120  ///\}
121 
122  ///\name Specific metadata keys
123  ///\{
124 
125  const std::shared_ptr<const MetadataValueKey<std::string> >
126  part_key() const;
127 
128  ///\}
129  };
130 
131  /**
132  * A directory contents entry.
133  *
134  * \ingroup g_contents
135  * \nosubgrouping
136  */
138  public ContentsEntry,
139  public ImplementAcceptMethods<ContentsEntry, ContentsDirEntry>
140  {
141  public:
142  ///\name Basic operations
143  ///\{
144 
145  ContentsDirEntry(const FSPath &);
146 
147  ///\}
148  };
149 
150  /**
151  * An 'other' contents entry, which we can't handle.
152  *
153  * \since 0.36
154  * \ingroup g_contents
155  * \nosubgrouping
156  */
158  public ContentsEntry,
159  public ImplementAcceptMethods<ContentsEntry, ContentsOtherEntry>
160  {
161  public:
162  ///\name Basic operations
163  ///\{
164 
165  ContentsOtherEntry(const FSPath &);
166 
167  ///\}
168  };
169 
170  /**
171  * A sym contents entry.
172  *
173  * \ingroup g_contents
174  * \nosubgrouping
175  */
177  public ContentsEntry,
178  public ImplementAcceptMethods<ContentsEntry, ContentsSymEntry>
179  {
180  private:
182 
183  public:
184  ///\name Basic operations
185  ///\{
186 
187  ContentsSymEntry(const FSPath &, const std::string &,
188  const std::string &);
189  ~ContentsSymEntry();
190 
191  ///\}
192 
193  ///\name Specific metadata keys
194  ///\{
195 
196  /**
197  * Our target, as per readlink. Must not be zero.
198  *
199  * \since 0.36
200  */
201  const std::shared_ptr<const MetadataValueKey<std::string> > target_key() const;
202 
203  const std::shared_ptr<const MetadataValueKey<std::string> >
204  part_key() const;
205 
206  ///\}
207  };
208 
209  /**
210  * A package's contents, obtainable by PackageID::contents.
211  *
212  * \ingroup g_contents
213  * \nosubgrouping
214  */
216  {
217  private:
218  Pimp<Contents> _imp;
219 
220  public:
221  ///\name Basic operations
222  ///\{
223 
224  Contents();
225  ~Contents();
226 
227  Contents(const Contents &) = delete;
228  Contents & operator= (const Contents &) = delete;
229 
230  ///\}
231 
232  /// Add a new entry.
233  void add(const std::shared_ptr<const ContentsEntry> & c);
234 
235  ///\name Iterate over our entries
236  ///\{
237 
238  struct ConstIteratorTag;
240 
241  ConstIterator begin() const
242  PALUDIS_ATTRIBUTE((warn_unused_result));
243 
244  ConstIterator end() const
245  PALUDIS_ATTRIBUTE((warn_unused_result));
246 
247  ///\}
248  };
249 
250  extern template class Pimp<Contents>;
251  extern template class Pimp<ContentsEntry>;
252  extern template class Pimp<ContentsSymEntry>;
253  extern template class Pimp<ContentsFileEntry>;
254 
256 }
257 
258 #endif
Definition: pimp.hh:51
Definition: about_metadata-fwd.hh:23
Definition: contents.hh:157
virtual void add_metadata_key(const std::shared_ptr< const MetadataKey > &) const
Definition: visitor-fwd.hh:52
Definition: contents.hh:176
Definition: contents.hh:137
Definition: contents.hh:53
Definition: contents.hh:106
Definition: wrapped_forward_iterator-fwd.hh:26
Definition: visitor-fwd.hh:49
Definition: fs_path.hh:33
Definition: contents.hh:215
Definition: metadata_key_holder.hh:38
#define PALUDIS_ATTRIBUTE(x)
Definition: attributes.hh:53
#define PALUDIS_VISIBLE
Definition: attributes.hh:59