#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/IO/Method2Proc.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_DPMETHOD2PROC_HEADER #define RAVL_DPMETHOD2PROC_HEADER 1 /////////////////////////////////////////////// //! docentry="Ravl.Core.Data Processing.Processes" //! lib=RavlIO //! file="Ravl/Core/IO/Method2Proc.hh" //! author="Charles Galambos" //! date="09/07/1998" //! rcsid="$Id: Method2Proc.hh,v 1.9 2002/07/25 17:35:07 craftit Exp $" #include "Ravl/DP/Process.hh" #include "Ravl/FunctionRegister.hh" namespace RavlN { //////////////////////////// //! userlevel=Develop //: Methodtion body. template class DPMethod2ProcBodyC : public DPProcessBodyC { public: typedef OutT (ObjT::*FuncT)(const InT &); DPMethod2ProcBodyC(const ObjT &nobj,FuncT nfunc,bool stateless = true) : obj(nobj), func(nfunc), stateless(true) {} //: Constructor. DPMethod2ProcBodyC(istream &in) : DPProcessBodyC(in) { LoadFunctionPointer(in,func); } //: Stream constructor. DPMethod2ProcBodyC(BinIStreamC &in) : DPProcessBodyC(in) { LoadFunctionPointer(in,func); } //: Binary stream constructor. virtual bool Save(ostream &out) const { if(!DPProcessBodyC::Save(out)) return false; return SaveFunctionPointer(out,func); } //: Save to ostream. virtual bool Save(BinOStreamC &out) const { if(!DPProcessBodyC::Save(out)) return false; return SaveFunctionPointer(out,func); } //: Save to binary stream. virtual OutT Apply(const InT &dat) { return (obj.*func)(dat); } //: Apply operation. virtual IntT ApplyArray(const SArray1dC &in,SArray1dC &out) { RavlAssert(out.Size() >= in.Size()); for(SArray1dIter2C it(in,out);it;it++) it.Data2() = (obj.*func)(it.Data1()); return in.Size(); } //: Apply operation to an array of elements. virtual bool IsStateless() const { return stateless; } //: Is operation stateless ? protected: ObjT obj; FuncT func; bool stateless; }; /////////////////////////////// //! userlevel=Advanced //: Methodtion handle. template class DPMethod2ProcC : public DPProcessC { public: DPMethod2ProcC(const ObjT &nobj,typename DPMethod2ProcBodyC::FuncT func,bool stateless = true) : DPProcessC(*new DPMethod2ProcBodyC(nobj,func,stateless)) {} //: Default constructor. }; //! userlevel=Normal template DPMethod2ProcC Process(const ObjT &nclass,OutT (ObjT::*nmethod)(const InT &)) { return DPMethod2ProcC(nclass,nmethod); } //: Turn a function into a process. } #endif