00001
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 Self &self() { return *static_cast< Self * >( this ); }
00018
00019 template< PropertyId property >
00020 typename PType< property >::T get( Token t ) {
00021 return self().template getInternal< property >( self().lookupToken( t ) );
00022 }
00023
00024 template< PropertyId _property >
00025 struct ComposedList : wibble::mixin::Comparable< ComposedList< _property > >
00026 {
00027 typedef Self Origin;
00028 typedef typename Setup::Token Token;
00029 typedef typename PType< _property >::T Property;
00030 typedef ComposedList Type;
00031
00032 Origin *origin;
00033 typename Setup::InternalList internal;
00034
00035 ComposedList tail() const {
00036 return ComposedList< _property >( *origin, internal.tail() );
00037 }
00038
00039 bool empty() const { return internal.empty(); }
00040
00041 bool operator<( const ComposedList &o ) const {
00042 return token() < o.token();
00043 }
00044
00045 ComposedList &head() { return *this; }
00046 const ComposedList &head() const { return *this; }
00047
00048 Token token() const { return origin->getToken( internal.head() ); }
00049
00050 Property property() const {
00051 return origin->template getInternal< _property >(
00052 internal.head() );
00053 }
00054
00055 template< PropertyId P >
00056 typename PType< P >::T
00057 get() const {
00058 return origin->template getInternal< P >( internal.head() );
00059 }
00060
00061 ComposedList() : origin( 0 ) {}
00062
00063 ComposedList( Origin &o, typename Setup::InternalList i )
00064 : origin( &o ), internal( i ) {}
00065 };
00066
00067 template< PropertyId property >
00068 ComposedList< property > list()
00069 {
00070 return ComposedList< property >( self(), self().listInternal() );
00071 }
00072
00073 template< PropertyId P, typename F >
00074 struct Propertify {
00075 F f;
00076 Propertify( F _f = F() ) : f( _f ) {}
00077 bool operator()( const ComposedList< P > &x ) const {
00078 return f( x.token(), x.property() );
00079 }
00080 };
00081
00082 template< PropertyId P, typename F >
00083 struct PropertyFilter {
00084 typedef typename list::Filtered<
00085 ComposedList< P >, Propertify< P, F > > T;
00086 };
00087
00088 template< PropertyId P, typename F >
00089 typename PropertyFilter< P, F >::T
00090 propertyFilter( F f ) {
00091 return list::filter( list< P >(), Propertify< P, F >( f ) );
00092 }
00093
00094 Source()
00095 {
00096 }
00097 };
00098
00099 }
00100 }
00101
00102 #endif