#ifndef DPIOTAP_HEADER #define DPIOTAP_HEADER 1 /////////////////////////////////////////////////// //! docentry="Data Processing" //! rcsid="$Id: IOTap.hh,v 1.8 1999/09/16 13:30:19 ees1cg Exp $" //! file="amma/StdType/DataProc/IOTap.hh" //! lib=DataProc //! author="Charles Galambos" //! date="20/07/98" #include "amma/DP/Port.hh" #include "amma/Tuple2.hh" #include //////////////////////////////////// //! userlevel=Develop //: Tap body template class DPIOTapBodyC : public DPIOPortBodyC { public: DPIOTapBodyC(const DPIOPortC &target,const DPOPortC > &ntap); //: Constructor. DPIOTapBodyC(const DPIOTapBodyC &oth); //: Copy Constructor. DPIOTapBodyC(); //: Default Constructor. DPIOTapBodyC(istream &in); //: Stream constructor. virtual void PutEOS(); //: Put End Of Stream marker. virtual BooleanT Put(const OutT &); //: Put data. virtual BooleanT IsPutReady() const; //: Is port ready for data ? virtual InT Get(); //: Get next piece of data. // May block if not ready, or it will return a constructed // with the default constructor. virtual BooleanT Get(InT &buff); //: Try and get next piece of data. // This will NOT block, if no data is ready // it will return FALSE, and not set buff. virtual BooleanT IsGetReady() const; //: Is some data ready ? // TRUE = yes. virtual BooleanT Save(ostream &out) const; //: Save to ostream. inline DPOPortC > &Tap(); //: Access to tap. inline DPIOPortC &Target(); //: Access the object being tapped. protected: DPOPortC > tap; DPIOPortC target; Tuple2C tapout; BooleanT donePut; }; /////////////////////////////////////// //! userlevel=Normal //: Tap handle. template class DPIOTapC : public DPIOPortC { public: DPIOTapC(const DPIOPortC &target, const DPOPortC > &ntap); //: Constructor. //= DPOPortC > () DPIOTapC(const DPIOTapC &oth); //: Copy Constructor. DPIOTapC(); //: Default Constructor. DPIOTapC(istream &in); //: Stream constructor. inline DPOPortC > &Tap(); //: Access to tap. inline DPIOPortC &Target(); //: Access the object being tapped. inline DPIOPortC &IOPort() { return *this; } //: Simlified cast. protected: DPIOTapBodyC &Body() { return dynamic_cast &>(DPEntityC::Body()); } const DPIOTapBodyC &Body() const { return dynamic_cast &>(DPEntityC::Body()); } }; /////////////////////////////// template DPIOTapBodyC::DPIOTapBodyC(const DPIOPortC &ntarget, const DPOPortC > &ntap) : tap(ntap), target(ntarget) { assert(target.IsValid()); } template DPIOTapBodyC::DPIOTapBodyC() {} template DPIOTapBodyC::DPIOTapBodyC(const DPIOTapBodyC &oth) : tap(oth.tap), target(oth.target) {} template DPIOTapBodyC::DPIOTapBodyC(istream &in) : tap(in), target(in) {} template void DPIOTapBodyC::PutEOS() { target.PutEOS(); tap.PutEOS(); } template BooleanT DPIOTapBodyC::Put(const OutT &dat) { assert(target.IsValid()); if(donePut == TRUE) { tapout.Data2() = InT(); tap.Put(tapout); } tapout.Data1() = dat; donePut = TRUE; return target.Put(dat); } template BooleanT DPIOTapBodyC::IsPutReady() const { assert(target.IsValid()); return target.IsPutReady(); } template InT DPIOTapBodyC::Get() { assert(target.IsValid()); tapout.Data2() = target.Get(); if(!donePut) tapout.Data1() = OutT(); tap.Put(tapout); donePut=FALSE; return tapout.Data2(); } template BooleanT DPIOTapBodyC::Get(InT &buff) { assert(target.IsValid()); BooleanT ret = target.Get(buff); if(ret) { tapout.Data2() = buff; if(!donePut) tapout.Data1() = OutT(); tap.Put(tapout); donePut=FALSE; } return ret; } template BooleanT DPIOTapBodyC::IsGetReady() const { return target.IsGetReady(); } template BooleanT DPIOTapBodyC::Save(ostream &out) const { if(!DPIOPortBodyC::Save(out)) return FALSE; if(!tap.Save(out)) return FALSE; if(!target.Save(out)) return FALSE; return TRUE; } template inline DPOPortC > & DPIOTapBodyC::Tap() { return tap; } template inline DPIOPortC & DPIOTapBodyC::Target() { return target; } /////////////////////////////////////////////////////////// template DPIOTapC::DPIOTapC(const DPIOPortC &ntarget, const DPOPortC > &ntap) : DPEntityC(*new DPIOTapBodyC (ntarget,ntap)) {} template DPIOTapC::DPIOTapC() : DPEntityC(*new DPIOTapBodyC ()) {} template DPIOTapC::DPIOTapC(const DPIOTapC &oth) : DPEntityC(oth) {} template DPIOTapC::DPIOTapC(istream &in) : DPEntityC(in) {} template inline DPOPortC > & DPIOTapC::Tap() { return Body().Tap(); } template inline DPIOPortC & DPIOTapC::Target() { return Body().Target(); } #endif