paludis  Version 1.4.2
spec_tree.hh
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 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_SPEC_TREE_HH
21 #define PALUDIS_GUARD_PALUDIS_SPEC_TREE_HH 1
22 
23 #include <paludis/spec_tree-fwd.hh>
24 #include <paludis/util/wrapped_forward_iterator.hh>
25 #include <paludis/util/visitor.hh>
26 #include <paludis/util/sequence.hh>
27 #include <type_traits>
28 
29 namespace paludis
30 {
31  namespace spec_tree_internals
32  {
33  template <typename Tree_>
34  class PALUDIS_VISIBLE BasicNode :
35  public virtual DeclareAbstractAcceptMethods<BasicNode<Tree_>, typename Tree_::VisitableTypeList>
36  {
37  };
38 
39  template <typename Tree_, typename Item_>
40  class PALUDIS_VISIBLE LeafNode :
41  public BasicNode<Tree_>,
42  public ImplementAcceptMethods<BasicNode<Tree_>, LeafNode<Tree_, Item_> >
43  {
44  private:
45  const std::shared_ptr<const Item_> _spec;
46 
47  public:
48  explicit LeafNode(const std::shared_ptr<const Item_> & i);
49 
50  template <typename OtherTree_>
51  operator LeafNode<OtherTree_, Item_> () const;
52 
53  const std::shared_ptr<const Item_> spec() const;
54  };
55 
56  template <typename Tree_, typename Item_>
57  class InnerNode;
58 
59  template <typename Tree_>
60  class PALUDIS_VISIBLE BasicInnerNode :
61  public BasicNode<Tree_>
62  {
63  private:
64  typedef Sequence<std::shared_ptr<const BasicNode<Tree_> > > ChildList;
65  std::shared_ptr<ChildList> _child_list;
66 
67  public:
68  BasicInnerNode();
69 
70  typedef BasicInnerNodeConstIteratorTag<Tree_> ConstIteratorTag;
71  typedef WrappedForwardIterator<ConstIteratorTag,
72  const std::shared_ptr<const BasicNode<Tree_> > > ConstIterator;
73 
74  ConstIterator begin() const;
75 
76  ConstIterator end() const;
77 
78  void append_node(const std::shared_ptr<const BasicNode<Tree_> > & t);
79 
80  template <typename T_>
81  const std::shared_ptr<typename Tree_::template NodeType<T_>::Type>
82  append(const std::shared_ptr<const T_> & t);
83 
84  template <typename T_>
85  const std::shared_ptr<typename Tree_::template NodeType<T_>::Type>
86  append(const std::shared_ptr<T_> & t);
87  };
88 
89  template <typename Tree_, typename Item_>
90  class PALUDIS_VISIBLE InnerNode :
91  public BasicInnerNode<Tree_>,
92  public ImplementAcceptMethods<BasicNode<Tree_>, InnerNode<Tree_, Item_> >
93  {
94  private:
95  const std::shared_ptr<const Item_> _spec;
96 
97  public:
98  explicit InnerNode(const std::shared_ptr<const Item_> & i);
99 
100  template <typename OtherTree_>
101  operator InnerNode<OtherTree_, Item_> () const;
102 
103  const std::shared_ptr<const Item_> spec() const;
104  };
105 
106  template <typename Tree_>
108  {
109  typedef TypeListTail Type;
110  };
111 
112  template <typename Tree_, typename Item_, typename Tail_>
114  {
117  };
118 
119  template <typename Tree_, typename Item_, typename Tail_>
121  {
124  };
125 
126  template <typename Tree_, typename NodeList_>
127  struct MakeVisitableTypeList
128  {
130  };
131  }
132 
133  template <typename NodeList_, typename RootNode_>
134  class PALUDIS_VISIBLE SpecTree
135  {
136  public:
137  typedef typename spec_tree_internals::MakeVisitableTypeList<SpecTree, NodeList_>::Type VisitableTypeList;
138 
139  typedef spec_tree_internals::BasicNode<SpecTree> BasicNode;
140  typedef spec_tree_internals::BasicInnerNode<SpecTree> BasicInnerNode;
141 
142  template <typename Node_>
144  {
146  };
147 
148  template <typename Node_>
150  {
152  };
153 
154  template <typename Node_>
155  struct NodeType
156  {
157  typedef typename std::conditional<
159  typename SpecTree::template LeafNodeType<Node_>::Type,
160  typename std::conditional<
164  >::type
165  >::type Type;
166  };
167 
168  explicit SpecTree(const std::shared_ptr<RootNode_> & spec);
169 
170  explicit SpecTree(const std::shared_ptr<const RootNode_> & spec);
171 
172  const std::shared_ptr<typename InnerNodeType<RootNode_>::Type> top();
173 
174  const std::shared_ptr<const typename InnerNodeType<RootNode_>::Type> top() const;
175 
176  private:
177  const std::shared_ptr<typename InnerNodeType<RootNode_>::Type> _top;
178  };
179 
180  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
196  >::Type, AllDepSpec>;
197 
198  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
203  >::Type, AllDepSpec>;
204 
205  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
210  >::Type, AllDepSpec>;
211 
212  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
216  >::Type, AllDepSpec>;
217 
218  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
222  >::Type, AllDepSpec>;
223 
224  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
229  >::Type, AllDepSpec>;
230 
231  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
238  >::Type, AllDepSpec>;
239 
240  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
248  >::Type, AllDepSpec>;
249 
250  extern template class PALUDIS_VISIBLE SpecTree<MakeTypeList<
254  >::Type, AllDepSpec>;
255 
257  const std::shared_ptr<const spec_tree_internals::BasicNode<GenericSpecTree> > >;
259  const std::shared_ptr<const spec_tree_internals::BasicNode<DependencySpecTree> > >;
261  const std::shared_ptr<const spec_tree_internals::BasicNode<SetSpecTree> > >;
263  const std::shared_ptr<const spec_tree_internals::BasicNode<PlainTextSpecTree> > >;
265  const std::shared_ptr<const spec_tree_internals::BasicNode<RequiredUseSpecTree> > >;
267  const std::shared_ptr<const spec_tree_internals::BasicNode<SimpleURISpecTree> > >;
269  const std::shared_ptr<const spec_tree_internals::BasicNode<FetchableURISpecTree> > >;
271  const std::shared_ptr<const spec_tree_internals::BasicNode<LicenseSpecTree> > >;
272 }
273 
274 #endif
Definition: spec_tree-fwd.hh:71
Definition: type_list.hh:27
Definition: spec_tree-fwd.hh:40
Definition: spec_tree-fwd.hh:32
Definition: spec_tree.hh:149
Definition: type_list-fwd.hh:28
Definition: spec_tree-fwd.hh:43
Definition: spec_tree-fwd.hh:29
Definition: type_list-fwd.hh:31
Definition: wrapped_forward_iterator-fwd.hh:26
Definition: type_list-fwd.hh:46
Definition: spec_tree.hh:143
Definition: spec_tree.hh:155
#define PALUDIS_VISIBLE
Definition: attributes.hh:71
Definition: dep_spec.hh:137