00001 # ifndef __pipestream_h
00002 # define __pipestream_h
00003
00004 # include "PipeModules.h"
00005 # include <iostream.h>
00006
00007
00008
00009 class OstreamWrapper {
00010 ostream * x ;
00011
00012 public:
00013 OstreamWrapper() : x(0) {}
00014 OstreamWrapper( ostream& outs ) : x(&outs) {}
00015 OstreamWrapper operator= (OstreamWrapper w) { x=w.x; return *this; }
00016 template<class T>
00017 OstreamWrapper operator <<(T t) { (*x)<<t ; return *this; }
00018 };
00019 typedef Pipe<OstreamWrapper> PipeOStream ;
00020
00021 Pipe<OstreamWrapper> liftP( ostream& outs ) {
00022 return Pipe<OstreamWrapper>(outs);
00023 }
00024
00025
00026
00027 template <class T>
00028 class IStreamModule : public PipeModule<T> {
00029 istream * ins ;
00030
00031 protected:
00032
00033 inline void check(void) { PipeModule<T>::check( ins ); }
00034
00035 public:
00036 IStreamModule( istream& ins ) : ins(&ins) {}
00037
00038 T compute_local_fn( int fc )
00039 {
00040 check() ;
00041 T t ;
00042 (*ins) >> t ;
00043 if( !(ins->good()) ) throw BrokenPipe() ;
00044 return t ;
00045 }
00046 };
00047
00048 template<class T>
00049 Pipe<T> liftP( istream& ins ) {
00050 return Pipe<T>(new IStreamModule<T>(ins));
00051 }
00052
00053
00054
00055 template <class T1, class T2>
00056 ostream &operator << (ostream &outs,Pair<T1,T2> v)
00057 {
00058 return outs << "(" << v.lval << ", " << v.rval << ")";
00059 }
00060
00061 # endif //__pipestream.h