00001 /* @HEADER@ */ 00002 // 00003 /* @HEADER@ */ 00004 00005 #ifndef PLAYA_BLOCKITERATORDECL_HPP 00006 #define PLAYA_BLOCKITERATORDECL_HPP 00007 00008 #include "PlayaDefs.hpp" 00009 #include "Teuchos_Array.hpp" 00010 #include <deque> 00011 00012 namespace Playa 00013 { 00014 00015 using Teuchos::RCP; 00016 using Teuchos::Array; 00017 00018 /* Forward declare VectorSpaceBase */ 00019 template <class Scalar> 00020 class VectorSpaceBase; 00021 00022 /* Forward declare VectorSpace */ 00023 template <class Scalar> 00024 class VectorSpace; 00025 00026 /* Forward declare Vector */ 00027 template <class Scalar> 00028 class Vector; 00029 00030 00031 /** 00032 * BlockIterator can locate a block within an arbitrarily nested block 00033 * vector space. 00034 */ 00035 template <class Scalar> 00036 class BlockIterator 00037 { 00038 public: 00039 00040 friend class VectorSpaceBase<Scalar>; 00041 friend class VectorSpace<Scalar>; 00042 friend class Vector<Scalar>; 00043 00044 /** Empty ctor */ 00045 BlockIterator() : space_(), 00046 index_(), 00047 atEnd_(true){} 00048 00049 /** Compare two iterators */ 00050 bool operator==(const BlockIterator<Scalar>& other) const ; 00051 00052 /** Compare two iterators */ 00053 bool operator!=(const BlockIterator<Scalar>& other) const 00054 { 00055 return !operator==(other); 00056 } 00057 00058 /** Compare two iterators */ 00059 bool operator<(const BlockIterator<Scalar>& other) const ; 00060 00061 /** Advance the block iterator */ 00062 BlockIterator<Scalar> operator++(int); 00063 00064 /** */ 00065 const VectorSpace<Scalar>& space() const ; 00066 00067 /** Print the iterator */ 00068 std::ostream& print(std::ostream& os) const ; 00069 00070 /** */ 00071 const std::deque<int>& blockIndex() const {return index_;} 00072 00073 /** */ 00074 bool atEnd() const {return atEnd_;} 00075 00076 /** Set to true (by doing BlockIterator<Scalar>::debug()=true) to 00077 * trace the iterator */ 00078 static bool& debug() 00079 {static bool rtn = false; return rtn;} 00080 00081 protected: 00082 00083 /** Build an index pointing to the leftmost entry in the 00084 * given block space */ 00085 void goToStart(const VectorSpace<Scalar>& space, 00086 std::deque<int>& pos) const ; 00087 00088 /** Constructor is private: the construction is always done inside 00089 * the begin and end methods of vector space. */ 00090 BlockIterator(const VectorSpace<Scalar>& space, 00091 bool atEnd); 00092 00093 /** Advance the index at the specified level. Return false if 00094 * no further advance is possible */ 00095 bool advance(int level); 00096 00097 private: 00098 /** Store the VC in an RCP so we can do forward declaration of VS */ 00099 RCP<const VectorSpace<Scalar> > space_; 00100 std::deque<int> index_; 00101 bool atEnd_; 00102 }; 00103 00104 } 00105 00106 namespace Playa 00107 { 00108 /** \relates BlockIterator */ 00109 template <class Scalar> inline 00110 std::ostream& operator<<(std::ostream& os, 00111 const Playa::BlockIterator<Scalar>& i) 00112 { 00113 return i.print(os); 00114 } 00115 } 00116 00117 00118 #endif