/** \file Declarataion of Iterators to TabulatedFunction \author Stefano Argiro \version $Id: TabulatedFunctionIterators.h 19812 2011-11-22 12:41:29Z mabl $ \date 09 Oct 2003 */ #ifndef _utl_TabulatedFunctionIterators_h_ #define _utl_TabulatedFunctionIterators_h_ #include #include #include #include static const char CVSId_utl_TabulatedFunctionIterators[] = "$Id: TabulatedFunctionIterators.h 19812 2011-11-22 12:41:29Z mabl $"; namespace utl { // Custom Iterators class TabulatedFunctionIterator : public std::iterator { private: typedef std::vector::iterator InternalIterator; public: TabulatedFunctionIterator() { } TabulatedFunctionIterator(const InternalIterator xIt, const InternalIterator yIt) : fXIterator(xIt), fYIterator(yIt) { } Pair operator*() const { return Pair(*fXIterator, *fYIterator); } Pair* operator->() const { fPair = Pair(*fXIterator, *fYIterator); return &fPair; } TabulatedFunctionIterator& operator++() { ++fXIterator; ++fYIterator; return *this; } TabulatedFunctionIterator operator++(int) { const TabulatedFunctionIterator tmp = *this; ++fXIterator; ++fYIterator; return tmp; } bool operator==(const TabulatedFunctionIterator& it) const { return fXIterator == it.fXIterator && fYIterator == it.fYIterator; } bool operator!=(const TabulatedFunctionIterator& it) const { return fXIterator != it.fXIterator || fYIterator != it.fYIterator; } private: mutable Pair fPair; InternalIterator fXIterator; InternalIterator fYIterator; friend class ConstTabulatedFunctionIterator; }; class ConstTabulatedFunctionIterator : public std::iterator { private: typedef std::vector::const_iterator InternalIterator; public: ConstTabulatedFunctionIterator() { } ConstTabulatedFunctionIterator(const TabulatedFunctionIterator it) : fXIterator(it.fXIterator), fYIterator(it.fYIterator) { } ConstTabulatedFunctionIterator(const InternalIterator xIt, const InternalIterator yIt) : fXIterator(xIt), fYIterator(yIt) { } Pair operator*() const { return Pair(*fXIterator, *fYIterator); } const Pair* operator->() const { fPair = Pair(*fXIterator, *fYIterator); return &fPair; } ConstTabulatedFunctionIterator& operator++() { ++fXIterator; ++fYIterator; return *this; } ConstTabulatedFunctionIterator operator++(int) { const ConstTabulatedFunctionIterator tmp = *this; ++fXIterator; ++fYIterator; return tmp; } bool operator==(const ConstTabulatedFunctionIterator& it) const { return fXIterator == it.fXIterator && fYIterator == it.fYIterator; } bool operator!=(const ConstTabulatedFunctionIterator& it) const { return fXIterator != it.fXIterator || fYIterator != it.fYIterator; } private: mutable Pair fPair; InternalIterator fXIterator; InternalIterator fYIterator; }; // Forward declaration to allow TabulatedFunctionErrors friend access to // the InternalIterators of the TabulatedFunctionErrIterator class TabulatedFunctionErrors; class TabulatedFunctionErrIterator : public std::iterator { private: typedef std::vector::iterator InternalIterator; public: TabulatedFunctionErrIterator() { } TabulatedFunctionErrIterator(const InternalIterator xIt, const InternalIterator xErrIt, const InternalIterator yIt, const InternalIterator yErrIt) : fXIterator(xIt), fXErrIterator(xErrIt), fYIterator(yIt), fYErrIterator(yErrIt) { } PairErr operator*() const { return PairErr(*fXIterator, *fXErrIterator, *fYIterator, *fYErrIterator); } PairErr* operator->() const { fPair = PairErr(*fXIterator, *fXErrIterator, *fYIterator, *fYErrIterator); return &fPair; } TabulatedFunctionErrIterator& operator++() { ++fXIterator; ++fXErrIterator; ++fYIterator; ++fYErrIterator; return *this; } TabulatedFunctionErrIterator operator++(int) { const TabulatedFunctionErrIterator tmp = *this; ++fXIterator; ++fXErrIterator; ++fYIterator; ++fYErrIterator; return tmp; } bool operator==(const TabulatedFunctionErrIterator& it) const { return fXIterator == it.fXIterator && fXErrIterator == it.fXErrIterator && fYIterator == it.fYIterator && fYErrIterator == it.fYErrIterator; } bool operator!=(const TabulatedFunctionErrIterator& it) const { return fXIterator != it.fXIterator || fXErrIterator != it.fXErrIterator || fYIterator != it.fYIterator || fYErrIterator != it.fYErrIterator; } private: mutable PairErr fPair; InternalIterator fXIterator; InternalIterator fXErrIterator; InternalIterator fYIterator; InternalIterator fYErrIterator; friend class TabulatedFunctionErrors; }; class ConstTabulatedFunctionErrIterator : public std::iterator { private: typedef std::vector::const_iterator InternalIterator; public: ConstTabulatedFunctionErrIterator() { } ConstTabulatedFunctionErrIterator(const InternalIterator xIt, const InternalIterator xErrIt, const InternalIterator yIt, const InternalIterator yErrIt) : fXIterator(xIt), fXErrIterator(xErrIt), fYIterator(yIt), fYErrIterator(yErrIt) { } PairErr operator*() const { return PairErr(*fXIterator, *fXErrIterator, *fYIterator, *fYErrIterator); } const PairErr* operator->() const { fPair = PairErr(*fXIterator, *fXErrIterator, *fYIterator, *fYErrIterator); return &fPair; } ConstTabulatedFunctionErrIterator& operator++() { ++fXIterator; ++fXErrIterator; ++fYIterator; ++fYErrIterator; return *this; } ConstTabulatedFunctionErrIterator operator++(int) { const ConstTabulatedFunctionErrIterator tmp = *this; ++fXIterator; ++fXErrIterator; ++fYIterator; ++fYErrIterator; return tmp; } bool operator==(const ConstTabulatedFunctionErrIterator& it) const { return fXIterator == it.fXIterator && fXErrIterator == it.fXErrIterator && fYIterator == it.fYIterator && fYErrIterator == it.fYErrIterator; } bool operator!=(const ConstTabulatedFunctionErrIterator& it) const { return fXIterator != it.fXIterator || fXErrIterator != it.fXErrIterator || fYIterator != it.fYIterator || fYErrIterator != it.fYErrIterator; } private: mutable PairErr fPair; InternalIterator fXIterator; InternalIterator fXErrIterator; InternalIterator fYIterator; InternalIterator fYErrIterator; friend class TabulatedFunctionErrors; }; } // utl #endif // _utl_TabulatedFunctionIterators_h_ // Configure (x)emacs for this file ... // Local Variables: // mode: c++ // compile-command: "make -C .. -k" // End: