#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/IO/SplitO.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_DPSPLITO_HEADER #define RAVL_DPSPLITO_HEADER 1 ///////////////////////////////////////////////// //! docentry="Ravl.Core.Data Processing.Split" //! lib=RavlIO //! example=exDPSplit.cc //! rcsid="$Id: SplitO.hh,v 1.4 2002/06/25 15:53:02 craftit Exp $" //! file="Ravl/Core/IO/SplitO.hh" //! author="Charles Galambos" //! date="21/07/98" #include "Ravl/DP/Port.hh" #include "Ravl/BlkQueue.hh" #include "Ravl/DList.hh" #include "Ravl/DLIter.hh" #include "Ravl/CDLIter.hh" namespace RavlN { template class DPSplitOC; template class DPSplitOBodyC; /////////////////////////// //! userlevel=Develop //: Output port splitter body template class DPSplitOBodyC : public DPOPortBodyC { public: DPSplitOBodyC() {} //: Constructor. DPSplitOBodyC(const DPOPortC &aport) { ports.InsLast(aport); } //: Construct with an OPortC. virtual void PutEOS(); //: Put End Of Stream marker. virtual bool Put(const DataT &); //: Put data. virtual IntT PutArray(const SArray1dC &data); //: Put an array of data to stream. // returns the number of elements processed. virtual bool IsPutReady() const; //: Is port ready for data ? protected: bool Remove(const DPOPortC &port); //: Remove output port. // This function removes ONE port which is // equal to 'port' // Returns true if port was found and removed. // otherwise it returns false. bool Add(const DPOPortC &port) { ports.InsLast(port); return true; } //: Add output port. // Note no checks are made on how many times a // port is added. private: DListC > ports; // List of ports. friend class DPSplitOC; }; //////////////////////// //! userlevel=Normal //: Output port Splitter handle. // This will split output and put it to all outputs that // have been added by calling Add(...), or using the // >> operator. template class DPSplitOC : public DPOPortC { public: DPSplitOC(const DPSplitOC &oth); //: Copy constructor. DPSplitOC(bool makeBod) : DPEntityC(*new DPSplitOBodyC()) {} //: Constructor. // Creates a new splitter. DPSplitOC() : DPEntityC(true) {} //: Default constructor. // Creates an invalid handle. protected: DPSplitOBodyC &Body() { return dynamic_cast &>(DPEntityC::Body()); } const DPSplitOBodyC &Body() const { return dynamic_cast &>(DPEntityC::Body()); } public: inline bool Remove(const DPOPortC &port) { return Body().Remove(port); } //: Remove output port. // This function removes ONE port which is // equal to 'port' inline bool Add(const DPOPortC &port) { return Body().Add(port); } //: Add output port. // Note no checks are made on how many times a // port is added. }; /////////////////////// // Composition. template DPOPortC operator>>(DPSplitOC &in,const DPOPortC &out) { in.Add(out); return in; } template DPOPortC operator>>(DPOPortC &out,DPSplitOC &in) { out = in; return out; // Is this right ? } template void DPSplitOBodyC::PutEOS() { for(DLIterC > it(ports);it.IsElm();it.Next()) { it.Data().PutEOS(); it.Del(); // Remove from list. } } template bool DPSplitOBodyC::Put(const DataT &dat) { bool oneWorked = false; for(DLIterC > it(ports);it.IsElm();it.Next()) { if(it.Data().Put(dat)) oneWorked = true; } return oneWorked; // Is this really the right thing or should it be all Worked ?? } template IntT DPSplitOBodyC::PutArray(const SArray1dC &data) { int max = 0; for(DLIterC > it(ports);it.IsElm();it.Next()) { IntT x = it.Data().PutArray(data); if(x > max) max = x; } return max; // Is this right ? } template bool DPSplitOBodyC::IsPutReady() const { for(ConstDLIterC > it(ports);it.IsElm();it.Next()) { if(it.Data().IsPutReady()) return true; } return false; } template bool DPSplitOBodyC::Remove(const DPOPortC &port) { for(DLIterC > it(ports);it.IsElm();it.Next()) { if(it.Data() == port) { it.Del(); return true; } } return false; } } #endif