libept  0.5.25
source.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 #include <ept/core/list.h>
4 
5 #ifndef EPT_CORE_SOURCE_H
6 #define EPT_CORE_SOURCE_H
7 
8 namespace ept {
9 namespace core {
10 
11 template< typename Self, typename Setup,
12  template< typename Setup::PropertyId > class PType >
13 struct Source {
14  typedef typename Setup::PropertyId PropertyId;
15  typedef typename Setup::Token Token;
16 
19 
20  Self &self() { return *static_cast< Self * >( this ); }
21 
22  template< PropertyId property >
23  typename PType< property >::T get( Token t ) {
24  if ( m_cachedToken != t ) {
25  m_cachedToken = t;
26  m_cached = self().lookupToken( t );
27  }
28  return self().template getInternal< property >( m_cached );
29  }
30 
31  void invalidate() {
32  m_cachedToken = ept::Token();
33  m_cached = typename Setup::Internal();
34  }
35 
36  template< PropertyId _property >
37  struct ComposedList : wibble::mixin::Comparable< ComposedList< _property > >
38  {
39  typedef Self Origin;
40  typedef typename Setup::Token Token;
41  typedef typename PType< _property >::T Property;
42  typedef ComposedList Type;
43 
44  Origin *origin;
45  typename Setup::InternalList internal;
46 
47  ComposedList tail() const {
48  return ComposedList< _property >( *origin, internal.tail() );
49  }
50 
51  bool empty() const { return internal.empty(); }
52 
53  bool operator<( const ComposedList &o ) const {
54  return token() < o.token();
55  }
56 
57  ComposedList &head() { return *this; }
58  const ComposedList &head() const { return *this; }
59 
60  Token token() const { return origin->getToken( internal.head() ); }
61 
62  Property property() const {
63  return origin->template getInternal< _property >(
64  internal.head() );
65  }
66 
67  template< PropertyId P >
68  typename PType< P >::T
69  get() const {
70  return origin->template getInternal< P >( internal.head() );
71  }
72 
73  ComposedList() : origin( 0 ) {}
74 
75  ComposedList( Origin &o, typename Setup::InternalList i )
76  : origin( &o ), internal( i ) {}
77  };
78 
79  template< PropertyId property >
80  ComposedList< property > list()
81  {
82  return ComposedList< property >( self(), self().listInternal() );
83  }
84 
85  template< PropertyId P, typename F >
86  struct Propertify {
87  F f;
88  Propertify( F _f = F() ) : f( _f ) {}
89  bool operator()( const ComposedList< P > &x ) const {
90  return f( x.token(), x.property() );
91  }
92  };
93 
94  template< PropertyId P, typename F >
95  struct PropertyFilter {
96  typedef typename list::Filtered<
98  };
99 
100  template< PropertyId P, typename F >
102  propertyFilter( F f ) {
103  return list::filter( list< P >(), Propertify< P, F >( f ) );
104  }
105 
107  {
108  }
109 };
110 
111 }
112 }
113 
114 #endif
PType< _property >::T Property
Definition: source.h:41
Token m_cachedToken
Definition: source.h:17
bool empty() const
Definition: source.h:51
Setup::Token Token
Definition: source.h:15
F f
Definition: source.h:87
Setup::InternalList internal
Definition: source.h:45
ComposedList tail() const
Definition: source.h:47
bool operator<(const ComposedList &o) const
Definition: source.h:53
Setup::Internal m_cached
Definition: source.h:18
pkgCache::VerIterator Internal
Definition: core/apt.h:362
ComposedList Type
Definition: source.h:42
PropertyFilter< P, F >::T propertyFilter(F f)
Definition: source.h:102
-*- C++ -*- (c) 2006, 2007 Petr Rockai me@mornfall.net
Definition: apt.cc:43
ComposedList()
Definition: source.h:73
Setup::PropertyId PropertyId
Definition: source.h:14
const ComposedList & head() const
Definition: source.h:58
Self Origin
Definition: source.h:39
PropertyId
Definition: core/apt.h:359
Definition: source.h:86
ComposedList & head()
Definition: source.h:57
Definition: token.h:10
Origin * origin
Definition: source.h:44
Property property() const
Definition: source.h:62
Propertify(F _f=F())
Definition: source.h:88
ComposedList(Origin &o, typename Setup::InternalList i)
Definition: source.h:75
Token token() const
Definition: source.h:60
Definition: source.h:37
Definition: source.h:95
AptInternalList< Internal > InternalList
Definition: core/apt.h:381
bool operator()(const ComposedList< P > &x) const
Definition: source.h:89
Definition: source.h:13
Setup::Token Token
Definition: source.h:40
ComposedList< property > list()
Definition: source.h:80
void invalidate()
Definition: source.h:31
list::Filtered< ComposedList< P >, Propertify< P, F > > T
Definition: source.h:97
Source()
Definition: source.h:106