#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/IO/StreamOp.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVL_DPSTREAMOP_HEADER #define RAVL_DPSTREAMOP_HEADER 1 ///////////////////////////////////////////////////// //! rcsid="$Id: StreamOp.hh,v 1.9 2002/07/31 07:44:54 craftit Exp $" //! docentry="Ravl.Core.Data Processing.Internal" //! file="Ravl/Core/IO/StreamOp.hh" //! lib=RavlIO //! author="Charles Galambos" //! date="09/07/1998" //! userlevel=Normal #include "Ravl/DP/Port.hh" #include "Ravl/DP/Plug.hh" #include "Ravl/DList.hh" namespace RavlN { //! userlevel=Develop //: Abstract stream operation. class DPStreamOpBodyC : virtual public DPEntityBodyC { public: DPStreamOpBodyC() {} //: Default constructor. DPStreamOpBodyC(istream &in) : DPEntityBodyC(in) {} //: Stream constructor. DPStreamOpBodyC(BinIStreamC &in) : DPEntityBodyC(in) {} //: Binary stream constructor. virtual StringC OpName() const { return StringC("generic"); } //: Op type name. virtual DListC IPlugs() const; //: Input plugs. virtual DListC OPlugs() const; //: Output plugs virtual DListC IPorts() const; //: Input ports. virtual DListC OPorts() const; //: Output ports }; //! userlevel=Normal //: Abstract stream operation. class DPStreamOpC : virtual public DPEntityC { public: DPStreamOpC() : DPEntityC(true) {} //: Default constructor. // Creates an invalid handle. DPStreamOpC(DPEntityC &ent) : DPEntityC(ent) { if(dynamic_cast(&DPEntityC::Body()) == 0) Invalidate(); } //: Base class constructor. // If object is not a DPStreamOpC then an invalid handle will // be created. protected: DPStreamOpC(DPStreamOpBodyC &bod) : DPEntityC(bod) {} //: Body constructor. DPStreamOpBodyC &Body() { return dynamic_cast(DPEntityC::Body()); } //: Access body. const DPStreamOpBodyC &Body() const { return dynamic_cast(DPEntityC::Body()); } //: Access body. public: StringC OpName() const { return Body().OpName(); } //: Op type name. DListC IPlugs() const { return Body().IPlugs(); } //: Input plugs. DListC OPlugs() const { return Body().OPlugs(); } //: Output plugs DListC IPorts() const { return Body().IPorts(); } //: Input ports. DListC OPorts() const { return Body().OPorts(); } //: Output ports }; //////////////////////////////////////// //! userlevel=Develop //: Stream operation base class. template class DPIStreamOpBodyC : public DPIPortBodyC, public DPStreamOpBodyC { public: DPIStreamOpBodyC() : DPIPortBodyC("Out1") {} //: Default constructor. DPIStreamOpBodyC(const DPIPortC &nin) : DPIPortBodyC("Out1"), input(nin) {} //: Constructor. DPIStreamOpBodyC(istream &in) : DPEntityBodyC(in), DPIPortBodyC(in), DPStreamOpBodyC(in) {} //: Stream constructor. DPIStreamOpBodyC(BinIStreamC &in) : DPEntityBodyC(in), DPIPortBodyC(in), DPStreamOpBodyC(in) {} //: Binary stream constructor. virtual bool IsGetReady() const { if(!input.IsValid()) return false; return input.IsGetReady(); } //: Is some data ready ? // true = yes. virtual bool IsGetEOS() const { if(!input.IsValid()) return true; return input.IsGetEOS(); } //: Has the End Of Stream been reached ? // true = yes. virtual DPPortC ConnectedTo() const { return input; } //: What does this connect to ? virtual DListC IPorts() const { DListC lst = DPStreamOpBodyC::IPorts(); lst.InsLast(DPIPortBaseC((DPIPortBaseBodyC &)*this)); return lst; } //: Input ports. virtual DListC IPlugs() const { DListC lst = DPStreamOpBodyC::IPlugs(); lst.InsLast(DPIPlugC(input,"In1",DPEntityC((DPEntityBodyC &)*this))); return lst; } //: Input plugs. protected: DPIPortC input; // Where to get data from. public: inline DPIPortC &Input() { return input; } // Access input port. }; /////////////////////////////////// //! userlevel=Normal //: Stream operation handle class. template class DPIStreamOpC : public DPIPortC, public DPStreamOpC { public: DPIStreamOpC() : DPEntityC(true) {} //: Default Constructor. DPIStreamOpC(const DPIStreamOpC &oth) : DPEntityC(oth), DPIPortC(oth) {} //: Copy Constructor. protected: DPIStreamOpC(const DPIStreamOpBodyC &bod) : DPEntityC((DPIPortBodyC &) bod) {} //: Body constructor. public: inline DPIPortC &Input() { return dynamic_cast & >(DPEntityC::Body()).Input(); } // Access input port. }; //////////////////////////////////////// //! userlevel=Develop //: Stream operation base class. template class DPOStreamOpBodyC : public DPOPortBodyC, public DPStreamOpBodyC { public: DPOStreamOpBodyC() : DPOPortBodyC("In1") {} //: Default constructor. DPOStreamOpBodyC(const DPOPortC &nout) : DPOPortBodyC("In1"), output(nout) {} //: Constructor. virtual bool IsPutReady() const { RavlAssert(output.IsValid()); return output.IsPutReady(); } //: Is some data ready ? // true = yes. virtual void PutEOS() { if(output.IsValid()) output.PutEOS(); } //: Put End Of Stream marker. virtual DPPortC ConnectedTo() const { return output; } //: What does this connect to ? virtual DListC OPorts() const { DListC lst = DPStreamOpBodyC::OPorts(); lst.InsLast(DPOPortBaseC(const_cast &>(*this))); return lst; } //: Output ports. virtual DListC OPlugs() const { DListC lst = DPStreamOpBodyC::OPlugs(); lst.InsLast(DPOPlugC(output,"Out1",DPEntityC((DPEntityBodyC &)*this))); return lst; } //: Output plugs. protected: DPOPortC output; // Where to put data to. public: inline DPOPortC &Output() { return output; } // Access output port. }; /////////////////////////////////// //! userlevel=Normal //: Stream operation handle class. template class DPOStreamOpC : public DPOPortC, public DPStreamOpC { public: DPOStreamOpC() : DPEntityC(true) {} //: Default Constructor. DPOStreamOpC(const DPOStreamOpC &oth) : DPEntityC(oth), DPOPortC(oth) {} //: Copy Constructor. protected: DPOStreamOpC(const DPOStreamOpBodyC &bod) : DPEntityC((DPOPortBodyC &) bod) {} //: Body constructor. inline DPOPortC &Output() { return dynamic_cast & >(DPEntityC::Body()).Output(); } // Access input port. }; template DPIPortC operator>>(const DPIPortC &in,DPIStreamOpC dat) { dat.Input() = in; return dat; } } #endif