#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/IO/ContainerIO.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_CONTAINERIO_HEADER #define RAVL_CONTAINERIO_HEADER 1 /////////////////////////////////////////////////////// //! rcsid="$Id: ContainerIO.hh,v 1.4 2002/08/08 16:03:11 craftit Exp $" //! lib=RavlIO //! author="Charles Galambos" //! date="07/07/1998" //! docentry="Ravl.Core.Data Processing.IO" //! file="Ravl/Core/IO/ContainerIO.hh" #include "Ravl/DP/Port.hh" #include "Ravl/DList.hh" #include "Ravl/DLIter.hh" namespace RavlN { ////////////////////////////// //! userlevel=Develop //: Input list body. template class DPIContainerBodyC : public DPIPortBodyC { public: DPIContainerBodyC(const ContainerT &dat); //: Constructor. virtual bool IsGetReady() const { return iter; } //: Is some data ready ? virtual bool IsGetEOS() const { return iter; } //: Has the End Of Stream been reached ? // true = yes. virtual typename ContainerT::ElementT Get(); //: Get next piece of data. virtual IntT GetArray(SArray1dC &data); //: Get an array of data from stream. // returns the number of elements processed. virtual bool Get(typename ContainerT::ElementT &buff); //: Try and get next piece of data. protected: ContainerT container; typename ContainerT::IteratorT iter; }; /////////////////////////////////////////////////////////////////////////////// //! userlevel=Develop //: Output list body. // Append useing the '+=' operator. template class DPOContainerBodyC : public DPOPortBodyC { public: DPOContainerBodyC(ContainerT &dat); //: Default constructor. virtual bool Put(const typename ContainerT::ElementT &); //: Put data. virtual IntT PutArray(const SArray1dC &data); //: Put data into container. ContainerT &Container() { return container; } //: Access list. protected: ContainerT container; }; /////////////////////////////////////////////////////////////////////////////// //! userlevel=Develop //: Output list body. // Append useing the '+=' operator. template class DPOContainerOverwriteBodyC : public DPOPortBodyC { public: DPOContainerOverwriteBodyC(ContainerT &dat); //: Default constructor. virtual bool Put(const typename ContainerT::ElementT &); //: Put data. virtual IntT PutArray(const SArray1dC &data); //: Put data into container. ContainerT &Container() { return container; } //: Access list. virtual bool IsPutReady() const { return iter; } //: Is port ready for data ? protected: ContainerT container; typename ContainerT::IteratorT iter; }; ///////////////////////////////// //! userlevel=Normal //: Input from list. template class DPIContainerC : public DPIPortC { public: DPIContainerC(const ContainerT &dat) : DPEntityC(*new DPIContainerBodyC(dat)) {} //: Constructor. }; //////////////////////////////////// //! userlevel=Normal //: Output to a container. // This class with use the '+=' operator to append items to the // container.

// The container must define 'ElementT' template class DPOContainerC : public DPOPortC { public: DPOContainerC(ContainerT &dat) : DPEntityC(*new DPOContainerBodyC(dat)) {} //: Constructor. inline ContainerT &Container() { return dynamic_cast &>(DPEntityC::Body()).Container(); } //: Access list. }; //////////////////////////////////// //! userlevel=Normal //: Output to a container. // This class with use the '+=' operator to append items to the // container.

// The container must define 'ElementT' template class DPOContainerOverwriteC : public DPOPortC { public: DPOContainerOverwriteC(ContainerT &dat) : DPEntityC(*new DPOContainerOverwriteBodyC(dat)) {} //: Constructor. inline ContainerT &Container() { return dynamic_cast &>(DPEntityC::Body()).Container(); } //: Access list. }; //////////////////////////////////////// //: Some helper functions. template DPOPortC DPOContainer(ContainerT &dat) { return DPOContainerC(dat); } //: Write out stream to container, appending to contents. template DPOPortC DPOContainerOverwrite(ContainerT &dat) { return DPOContainerOverwriteC(dat); } //: Write out stream to container, overwriting existing contents. template DPIPortC DPIContainer(const ContainerT &dat) { return DPIContainerC(dat); } //: Use container as source for stream. template DPOContainerC > DPOList(DListC &dat) { return DPOContainerC >(dat); } template DPIContainerC > DPIList(const DListC &dat) { return DPIContainerC >(dat); } //////////////////////////////////////////////////////// template DPIContainerBodyC::DPIContainerBodyC(const ContainerT &dat) : container(dat), iter(const_cast(dat)) {} template typename ContainerT::ElementT DPIContainerBodyC::Get() { const typename ContainerT::ElementT &dat = iter; iter++; return dat; } template bool DPIContainerBodyC::Get(typename ContainerT::ElementT &buff) { if(!iter) return false; buff = *iter; iter++; return true; } template IntT DPIContainerBodyC::GetArray(SArray1dC &data) { for(SArray1dIterC it(data);it;it++) { if(!iter) return it.Index().V(); *it = *iter; iter++; } return data.Size(); } ///////////////////////////////////////// template DPOContainerBodyC::DPOContainerBodyC(ContainerT &dat) : container(dat) {} template bool DPOContainerBodyC::Put(const typename ContainerT::ElementT &dat) { container += dat; return true; } template IntT DPOContainerBodyC::PutArray(const SArray1dC &data) { for(SArray1dIterC it(data);it;it++) container += *it; return data.Size(); } ///////////////////////////////////////// template DPOContainerOverwriteBodyC::DPOContainerOverwriteBodyC(ContainerT &dat) : container(dat), iter(dat) {} template bool DPOContainerOverwriteBodyC::Put(const typename ContainerT::ElementT &dat) { if(!iter) return false; *iter = dat; iter++; return true; } template IntT DPOContainerOverwriteBodyC::PutArray(const SArray1dC &data) { for(SArray1dIterC it(data);it;it++) { if(!iter) return it.Index().V(); *iter = *it; iter++; } return data.Size(); } } #endif