#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/IO/StreamOp21.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2002, 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_DPSTREAMOP21_HEADER #define RAVL_DPSTREAMOP21_HEADER 1 ///////////////////////////////////////////////////////////// //! rcsid="$Id: StreamOp21.hh,v 1.4 2002/08/08 16:03:11 craftit Exp $" //! date="16/7/2002" //! author="Charles Galambos" //! lib=RavlIO //! docentry="Ravl.Core.Data Processing.Internal" //! file="Ravl/Core/IO/StreamOp21.hh" #include "Ravl/DP/StreamProcess.hh" #include "Ravl/DP/Process21.hh" namespace RavlN { //////////////////////////////////////// //! userlevel=Develop //: Stream operation base class. template class DPIStreamOp21BodyC : public DPStreamOpBodyC, public DPIPortBodyC { public: DPIStreamOp21BodyC(const DPProcess21C &nproc,const DPIPortC &input1,const DPIPortC &input2) : DPIPortBodyC("Out1"), proc(nproc), in1(input1), in2(input2) {} //: Constructor. DPIStreamOp21BodyC(const DPProcess21C &nproc) : DPIPortBodyC("Out1"), proc(nproc) {} //: Constructor. virtual bool IsGetReady() const { if(!in1.IsValid() || !in2.IsValid()) return false; return in1.IsGetReady() && in2.IsGetReady(); } //: Is some data ready ? // true = yes. virtual bool IsGetEOS() const { if(!in1.IsValid() || !in2.IsValid()) return true; return in1.IsGetEOS() && in2.IsGetEOS(); } //: Has the End Of Stream been reached ? // true = yes. virtual DListC IPorts() const { DListC lst = DPStreamOpBodyC::IPorts(); lst.InsLast(DPIPortBaseC((DPIPortBaseBodyC &)*this)); return lst; } //: List input ports. virtual DListC IPlugs() const { DListC lst = DPStreamOpBodyC::IPlugs(); lst.InsLast(DPIPlugC(in1,"In1",DPEntityC((DPEntityBodyC &)*this))); lst.InsLast(DPIPlugC(in2,"In2",DPEntityC((DPEntityBodyC &)*this))); return lst; } //: List input plugs. virtual Out1T Get() { RavlAssert(in1.IsValid() && in2.IsValid()); return proc.Apply(in1.Get(),in2.Get()); } //: Process next piece of data. virtual bool Get(Out1T &outbuff) { RavlAssert(in1.IsValid() && in2.IsValid()); In2T buff2; if(!in2.Get(buff2)) return false; In1T buff1; if(!in1.Get(buff1)) return false; outbuff = proc.Apply(buff1,buff2); return true; } //: Process some data. inline DPIPortC &Input1() { return in1; } // Access input port 1. inline DPIPortC &Input2() { return in2; } // Access input port 1. protected: DPIPortC in1; DPIPortC in2; DPProcess21C proc; }; /////////////////////////////////// //! userlevel=Normal //: Stream operation handle class. template class DPIStreamOp21C : public DPStreamOpC, public DPIPortC { public: DPIStreamOp21C() : DPEntityC(true) {} //: Default Constructor. DPIStreamOp21C(const DPProcess21C &nproc) : DPEntityC(*new DPIStreamOp21BodyC(nproc)) {} //: Construct from a process. DPIStreamOp21C(const DPProcess21C &nproc,const DPIPortC &input1,const DPIPortC &input2) : DPEntityC(*new DPIStreamOp21BodyC(nproc,input1,input2)) {} //: Construct from a process. protected: DPIStreamOp21C(const DPIStreamOp21BodyC &bod) : DPEntityC((DPIPortBodyC &) bod) {} //: Body constructor. DPIStreamOp21BodyC &Body() { return dynamic_cast &>(DPEntityC::Body()); } //: Access body. const DPIStreamOp21BodyC &Body() const { return dynamic_cast &>(DPEntityC::Body()); } //: Access body. public: inline DPIPortC &Input1() { return Body().Input1(); } // Access input port 1. inline DPIPortC &Input2() { return Body().Input2(); } // Access input port 2. }; } #endif