#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/IO/IOPort.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_DPIOPORT_HEADER #define RAVL_DPIOPORT_HEADER 1 //! docentry="Ravl.Core.Data Processing.Ports" //! file="Ravl/Core/IO/IOPort.hh" //! rcsid="$Id: IOPort.hh,v 1.2 2002/07/31 15:47:01 craftit Exp $" //! lib=RavlIO //! author="Charles Galambos" //! date="16/06/1998" #include "Ravl/DP/Port.hh" #include "Ravl/DP/StreamOp.hh" namespace RavlN { //! userlevel=Develop //: Input/Output port body. template class DPIOPortBodyC : public DPIPortBodyC, public DPOPortBodyC, public DPStreamOpBodyC { public: DPIOPortBodyC() {} //: Default constructor. DPIOPortBodyC(const StringC &nportId) : DPIPortBodyC(nportId), DPOPortBodyC(nportId) {} //: Constructor with a port id. DPIOPortBodyC(istream &in) : DPIPortBodyC(in), DPOPortBodyC(in) {} //: Stream constructor. virtual bool Save(ostream &out) const { if(!DPIPortBodyC::Save(out)) return false; return DPOPortBodyC::Save(out); } //: Save to ostream. virtual DListC IPorts() const; //: Input ports. virtual DListC OPorts() const; //: Output ports }; ////////////////////////////// //! userlevel=Normal //: Input/Output port. template class DPIOPortC : public DPIPortC, public DPOPortC, public DPStreamOpC { public: DPIOPortC() : DPEntityC(true) {} // Default constructor. DPIOPortC(DPIOPortBodyC &bod) : DPEntityC(bod), DPIPortC(bod), DPOPortC(bod), DPStreamOpC(bod) {} //: Body constructor. DPIOPortC(istream &in) : DPEntityC(in) {} //: Stream constructor. inline DPIOPortC Copy() const { if(!IsValid()) return DPIOPortC(); // Nothing to copy. return DPIOPortC(dynamic_cast &>(Body().Copy())); } //: Make a copy of this process. DPIPortC &In() { return *this; } //: Use as input port. // (Get from.) DPOPortC &Out() { return *this; } //: Use as output port. // (Put to.) protected: DPIOPortBodyC &Body() { return dynamic_cast &>(DPEntityC::Body()); } //: Access body. const DPIOPortBodyC &Body() const { return dynamic_cast &>(DPEntityC::Body()); } //: Access body. }; template ostream & operator<<(ostream & s,const DPIOPortC &port) { port.Save(s); return s; } template istream & operator>>(istream & s, DPIOPortC &port) { DPIOPortC nport(s); port = nport; return s; } //: Input ports. template DListC DPIOPortBodyC::IPorts() const { DListC ret; ret.InsLast(DPIOPortC(const_cast &>(*this))); return ret; } //: Output ports. template DListC DPIOPortBodyC::OPorts() const { DListC ret; ret.InsLast(DPIOPortC(const_cast &>(*this))); return ret; } } #endif