LTP GCOV extension - code coverage report
Current view: directory - ept/core - source.h
Test: lcov.info
Date: 2008-08-14 Instrumented lines: 34
Code covered: 100.0 % Executed lines: 34

       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              38 : struct Source {
      14                 :     typedef typename Setup::PropertyId PropertyId;
      15                 :     typedef typename Setup::Token Token;
      16                 : 
      17                 :     Token m_cachedToken;
      18                 :     typename Setup::Internal m_cached;
      19                 : 
      20              43 :     Self &self() { return *static_cast< Self * >( this ); }
      21                 : 
      22                 :     template< PropertyId property >
      23              13 :     typename PType< property >::T get( Token t ) {
      24              13 :         if ( m_cachedToken != t ) {
      25              10 :             m_cachedToken = t;
      26              10 :             m_cached = self().lookupToken( t );
      27                 :         }
      28              13 :         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            4009 :     {
      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           12056 :         ComposedList tail() const {
      48           12056 :             return ComposedList< _property >( *origin, internal.tail() );
      49                 :         }
      50                 : 
      51           12078 :         bool empty() const { return internal.empty(); }
      52                 : 
      53              13 :         bool operator<( const ComposedList &o ) const {
      54              13 :             return token() < o.token();
      55                 :         }
      56                 : 
      57              18 :         ComposedList &head() { return *this; }
      58               4 :         const ComposedList &head() const { return *this; }
      59                 : 
      60            6054 :         Token token() const { return origin->getToken( internal.head() ); }
      61                 : 
      62            7836 :         Property property() const {
      63                 :             return origin->template getInternal< _property >(
      64            7836 :                 internal.head() );
      65                 :         }
      66                 : 
      67                 :         template< PropertyId P >
      68                 :         typename PType< P >::T
      69              14 :         get() const {
      70              14 :             return origin->template getInternal< P >( internal.head() );
      71                 :         }
      72                 : 
      73               8 :         ComposedList() : origin( 0 ) {}
      74                 : 
      75           12066 :         ComposedList( Origin &o, typename Setup::InternalList i )
      76           12066 :             : origin( &o ), internal( i ) {}
      77                 :     };
      78                 : 
      79                 :     template< PropertyId property >
      80              10 :     ComposedList< property > list()
      81                 :     {
      82              10 :         return ComposedList< property >( self(), self().listInternal() );
      83                 :     }
      84                 : 
      85                 :     template< PropertyId P, typename F >
      86              50 :     struct Propertify {
      87                 :         F f;
      88               2 :         Propertify( F _f = F() ) : f( _f ) {}
      89               8 :         bool operator()( const ComposedList< P > &x ) const {
      90               8 :             return f( x.token(), x.property() );
      91                 :         }
      92                 :     };
      93                 : 
      94                 :     template< PropertyId P, typename F >
      95                 :     struct PropertyFilter {
      96                 :         typedef typename list::Filtered<
      97                 :             ComposedList< P >, Propertify< P, F > > T;
      98                 :     };
      99                 : 
     100                 :     template< PropertyId P, typename F >
     101                 :     typename PropertyFilter< P, F >::T
     102               1 :     propertyFilter( F f ) {
     103               1 :         return list::filter( list< P >(), Propertify< P, F >( f ) );
     104                 :     }
     105                 : 
     106              38 :     Source()
     107              38 :     {
     108              38 :     }
     109                 : };
     110                 : 
     111                 : }
     112                 : }
     113                 : 
     114                 : #endif

Generated by: LTP GCOV extension version 1.6