Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

TMatRowsIterator_decl.h

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 1998 Pascal Vincent 00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // 00007 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 00038 00039 /* ******************************************************* 00040 * $Id: TMatRowsIterator_decl.h,v 1.1 2004/04/17 00:44:55 plearner Exp $ 00041 * AUTHORS: Pascal Vincent & Yoshua Bengio 00042 * This file is part of the PLearn library. 00043 ******************************************************* */ 00044 00045 00048 #ifndef TMatRowsIterator_decl_INC 00049 #define TMatRowsIterator_decl_INC 00050 00051 namespace PLearn { 00052 using namespace std; 00053 00057 template <class T> 00058 class TMatRowsIterator 00059 { 00060 public: 00062 typedef random_access_iterator_tag iterator_category; 00063 typedef TVec<T> value_type; 00064 typedef ptrdiff_t difference_type; 00065 typedef TVec<T>* pointer; 00066 typedef TVec<T>& reference; 00067 00068 private: 00069 T* ptr; 00070 int width; 00071 int mod; 00072 00073 public: 00074 TMatRowsIterator() 00075 : ptr(), width(), mod() {} 00076 00077 TMatRowsIterator(T* p, int w, int m) 00078 : ptr(p), width(w), mod(m) {} 00079 00080 // Implement trivial iterator functions 00081 bool operator==(const TMatRowsIterator& other) const { 00082 return ptr == other.ptr && width == other.width && mod == other.mod; 00083 } 00084 00085 bool operator!=(const TMatRowsIterator& y) 00086 { return !operator==(y); } 00087 00088 value_type operator*() { 00089 return TVec<T>(width, ptr); 00090 } 00091 00092 // cannot define operator-> here since we cannot return a pointer to a 00093 // temporary (e.g. stack-based) vector and expect this to work properly... 00094 00095 // Implement forward iterator functions 00096 TMatRowsIterator& operator++() { 00097 ptr += mod; 00098 return *this; 00099 } 00100 00101 TMatRowsIterator operator++(int) { 00102 TMatRowsIterator r(*this); 00103 ptr += mod; 00104 return r; 00105 } 00106 00107 // Implement bidirectional iterator functions 00108 TMatRowsIterator& operator--() { 00109 ptr -= mod; 00110 return *this; 00111 } 00112 00113 TMatRowsIterator operator--(int) { 00114 TMatRowsIterator r(*this); 00115 ptr -= mod; 00116 return r; 00117 } 00118 00119 // Implement random access iterator functions 00120 TMatRowsIterator& operator+=(difference_type n) { 00121 ptr += n*mod; 00122 return *this; 00123 } 00124 00125 TMatRowsIterator operator+(difference_type n) { 00126 TMatRowsIterator r(*this); 00127 r += n; 00128 return r; 00129 } 00130 00131 TMatRowsIterator& operator-=(difference_type n) { 00132 ptr -= n*mod; 00133 return *this; 00134 } 00135 00136 TMatRowsIterator operator-(difference_type n) { 00137 TMatRowsIterator r(*this); 00138 r -= n; 00139 return r; 00140 } 00141 00142 difference_type operator-(const TMatRowsIterator& y) { 00143 return (ptr - y.ptr) / mod; 00144 } 00145 00146 value_type operator[](difference_type n) { 00147 return TVec<T>(width, ptr + n*mod); 00148 } 00149 00150 bool operator<(const TMatRowsIterator& y) { 00151 return ptr < y.ptr; 00152 } 00153 00154 }; 00155 00156 } // end of namespace PLearn 00157 00158 #endif

Generated on Tue Aug 17 16:08:44 2004 for PLearn by doxygen 1.3.7