Main Page | Namespace List | Class Hierarchy | Class List | File List | Related Pages

Connector.h

Go to the documentation of this file.
00001 
00047 #ifndef H_CONNECTOR
00048 #define H_CONNECTOR
00049 
00050 #ifndef NO_DEPENDENCY_INCLUDES
00051 
00052 #include "ProtocolRole.h"
00053 
00054 #endif
00055 
00057 namespace Connector 
00058 { 
00059     
00060     //
00061     // Basic Policies
00062     //
00063     
00064     // Just store the payload as payload_ protected member. 
00065     template< typename P > class SimplePayload
00066     { 
00067     protected: 
00068         P payload_; 
00069     public:
00070         typedef P PayloadType;
00071         virtual ~SimplePayload< P >( ) 
00072         { }
00073     };
00074     
00075     
00076     // upstream side functions as output location for previous operator
00077     template< typename P, typename B > 
00078     class MakesPayloadAvailableForOutput: 
00079         public B, public OutputPort< P > 
00080     {       
00081     public:
00082         // implementation of OutputPort<P>
00083         virtual operator P &()
00084         { return payload_; }
00085     };
00086     
00087     
00090     template< typename P, typename B > 
00091     class MakesPayloadAvailableForInput: 
00092         public B, public InputPort< P > 
00093     {
00094     public:
00095         // implementation of InputPort<U>
00096         virtual operator const P &()
00097         { return payload_; }
00098     };
00099 
00100 
00101     //
00102     // Slightly more complex payload_ policies
00103     //
00104 
00110     template< class U, class B > 
00111     class AdaptsPayloadForOutput: 
00112         public B, public OutputPort< typename U::PayloadType > 
00113     {
00114         U payloadAsU_;
00115     public:
00116         
00117         AdaptsPayloadForOutput<U,B>() : payloadAsU_( payload_ )
00118         { }
00119                 
00120         // implementation of InputPort<U>
00121         virtual operator typename U::PayloadType &()
00122         { return payloadAsU_; }
00123     };
00124     
00125     
00131     template< class D, class B > 
00132     class AdaptsPayloadForInput: 
00133         public B, public InputPort< typename D::PayloadType > 
00134     {
00135         D payloadAsD_;
00136     public:
00137         
00138         AdaptsPayloadForInput<D,B>() : payloadAsD_( payload_ )
00139         { }
00140         
00141         // implementation of InputPort<U>
00142         virtual operator const typename D::PayloadType &()
00143         { return payloadAsD_; }
00144     };
00145     
00150     template< class D, class B > 
00151     class CopiesPayloadForInput: 
00152         public B, public InputPort< D > 
00153     {
00154         // secondary payload area which contains the translated/reordered data
00155         // example would be converting from C indexing to Fortran indexing
00156         // or changing from double to float..
00157         D payloadCopiedAsD_;
00158     public:
00159         
00160         CopiesPayloadForInput<D,B>() : payloadCopiedAsD_( payload_.size() )
00161         { }
00162         
00163         virtual ~CopiesPayloadForInput<D,B>() 
00164         { }
00165         
00166         // implementation of InputPort<U>
00167         
00168         // upon request for input buffer, operator receives a copy of the 
00169         // payload, with any attendant modifications or restructuring
00170         virtual operator const D &()
00171         { 
00172             // resize payloadCopiedAsD_ to be same size as payload_
00173             
00174             // copy content, changing double to float for instance
00175             // may need a functor template parameter if we want 
00176             // to do something like complex to real
00177             std::copy( payload_.begin(), payload_.end(), payloadCopiedAsD_.begin() );
00178             return payloadAsD_; 
00179         }
00180     };
00181     
00182     
00183     //
00184     // Connector Templates
00185     // 
00186 
00191     template<
00192         typename PayloadType
00193         >
00194     class SimpleConnector: 
00195         public MakesPayloadAvailableForInput < PayloadType, 
00196                     MakesPayloadAvailableForOutput < PayloadType,
00197                         SimplePayload< PayloadType > > >
00198     {
00199     };
00200     
00207     template< 
00208         typename UpstreamType,
00209         typename PayloadType,
00210         typename DownstreamType,
00211         template< class, class > class UpstreamPolicy 
00212             = AdaptsPayloadForOutput,
00213         template< class, class > class DownstreamPolicy 
00214             = AdaptsPayloadForInput,
00215         template< class > class PayloadPolicy 
00216             = SimplePayload
00217         > 
00218     class PoliciedConnector: 
00219         public UpstreamPolicy< UpstreamType,  
00220                  DownstreamPolicy< DownstreamType,
00221                     PayloadPolicy< PayloadType > > >
00222     {
00223     };
00224     
00225     
00229     template< class A, class B >
00230         class BlitzArrayFromMemoryBuffer : public A
00231     {
00232 public:
00233         // we need to provide a clean constructor in order to be able to adapt
00234         BlitzArrayFromMemoryBuffer<A,B> ( B &it ):
00235         A( &it[0], blitz::shape( it.size() ), blitz::neverDeleteData )
00236     { }
00237         
00238         typedef A PayloadType;
00239     }; // class BlitzArrayFromMemoryBuffer
00240     
00241     
00242     
00245     template< class Payload >
00246         class ConstantInputPort: public InputPort< Payload >
00247     {
00248         Payload payload_;
00249 public:
00250         ConstantInputPort<Payload>( const Payload &payload ): 
00251         payload_(payload) 
00252     { };
00253         virtual ~ConstantInputPort<Payload>() { };
00254         
00255         virtual operator const Payload & ( ) { return payload_; }; 
00256     }; // class ConstantInputPort
00257     
00258     
00259     
00260     
00263     template< class Key, class Payload >
00264         class ConstantLookupInputPort: public LookupInputPort< Key, Payload >
00265     {
00266         Payload payload_;
00267 public:
00268         ConstantLookupInputPort<Key,Payload>( const Payload &payload ): 
00269         payload_(payload) 
00270     { }
00271         virtual ~ConstantLookupInputPort<Key,Payload>() { }
00272         
00273         // implementation of LookupInputPort<K,P>
00274         virtual const Payload &operator() ( const Key & ) { return payload_; } 
00275     }; // class TrivialLookupInputPort
00276 
00277     
00278     
00279     
00280     
00281 }; // namespace
00282 
00283 #endif // ifndef H_CONNECTOR
00284 
00285 
00286 
00287 
00288 
00289 
00290 
00291 

Generated on Fri Oct 8 12:18:33 2004 for Calibrate.Connector by doxygen 1.3.4