• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

source.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #include <ept/core/list.h>
00004 
00005 #ifndef EPT_CORE_SOURCE_H
00006 #define EPT_CORE_SOURCE_H
00007 
00008 namespace ept {
00009 namespace core {
00010 
00011 template< typename Self, typename Setup,
00012           template< typename Setup::PropertyId > class PType >
00013 struct Source {
00014     typedef typename Setup::PropertyId PropertyId;
00015     typedef typename Setup::Token Token;
00016 
00017     Token m_cachedToken;
00018     typename Setup::Internal m_cached;
00019 
00020     Self &self() { return *static_cast< Self * >( this ); }
00021 
00022     template< PropertyId property >
00023     typename PType< property >::T get( Token t ) {
00024         if ( m_cachedToken != t ) {
00025             m_cachedToken = t;
00026             m_cached = self().lookupToken( t );
00027         }
00028         return self().template getInternal< property >( m_cached );
00029     }
00030 
00031     void invalidate() {
00032         m_cachedToken = ept::Token();
00033         m_cached = typename Setup::Internal();
00034     }
00035 
00036     template< PropertyId _property >
00037     struct ComposedList : wibble::mixin::Comparable< ComposedList< _property > >
00038     {
00039         typedef Self Origin;
00040         typedef typename Setup::Token Token;
00041         typedef typename PType< _property >::T Property;
00042         typedef ComposedList Type;
00043 
00044         Origin *origin;
00045         typename Setup::InternalList internal;
00046 
00047         ComposedList tail() const {
00048             return ComposedList< _property >( *origin, internal.tail() );
00049         }
00050 
00051         bool empty() const { return internal.empty(); }
00052 
00053         bool operator<( const ComposedList &o ) const {
00054             return token() < o.token();
00055         }
00056 
00057         ComposedList &head() { return *this; }
00058         const ComposedList &head() const { return *this; }
00059 
00060         Token token() const { return origin->getToken( internal.head() ); }
00061 
00062         Property property() const {
00063             return origin->template getInternal< _property >(
00064                 internal.head() );
00065         }
00066 
00067         template< PropertyId P >
00068         typename PType< P >::T
00069         get() const {
00070             return origin->template getInternal< P >( internal.head() );
00071         }
00072 
00073         ComposedList() : origin( 0 ) {}
00074 
00075         ComposedList( Origin &o, typename Setup::InternalList i )
00076             : origin( &o ), internal( i ) {}
00077     };
00078 
00079     template< PropertyId property >
00080     ComposedList< property > list()
00081     {
00082         return ComposedList< property >( self(), self().listInternal() );
00083     }
00084 
00085     template< PropertyId P, typename F >
00086     struct Propertify {
00087         F f;
00088         Propertify( F _f = F() ) : f( _f ) {}
00089         bool operator()( const ComposedList< P > &x ) const {
00090             return f( x.token(), x.property() );
00091         }
00092     };
00093 
00094     template< PropertyId P, typename F >
00095     struct PropertyFilter {
00096         typedef typename list::Filtered<
00097             ComposedList< P >, Propertify< P, F > > T;
00098     };
00099 
00100     template< PropertyId P, typename F >
00101     typename PropertyFilter< P, F >::T
00102     propertyFilter( F f ) {
00103         return list::filter( list< P >(), Propertify< P, F >( f ) );
00104     }
00105 
00106     Source()
00107     {
00108     }
00109 };
00110 
00111 }
00112 }
00113 
00114 #endif

Generated on Thu Aug 18 2016 17:48:34 for libept by  doxygen 1.7.1