# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

ps_iterator.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 
00027 #ifndef NL_PS_ITERATOR_H
00028 #define NL_PS_ITERATOR_H
00029 
00030 #include "nel/3d/animation_time.h"
00031 
00032 namespace NL3D 
00033 {
00034 
00035         #ifdef NL_OS_WINDOWS
00036                 #define GET_INLINE __forceinline
00037         #else
00038                 #define GET_INLINE
00039         #endif
00040 
00041         
00042 
00051         template <typename T, typename PT>
00052         struct CAdvance1Iterator
00053         {               
00054                 T It;
00055 
00056                 CAdvance1Iterator() {}
00058                 CAdvance1Iterator(T it, uint32 index = 0)
00059                 {                       
00060                         It = it + index;
00061                 }                                               
00062                 const PT &get() const { return *It; }
00063                 void advance() { ++It; }
00064                 void advance(uint numSteps) 
00065                 { 
00066                         It = It + numSteps; 
00067                 }
00068                 CAdvance1Iterator &operator++() { advance(); return *this; }
00069                 CAdvance1Iterator operator++(int) { CAdvance1Iterator tmp = this; advance(); return tmp; }              
00070                 const PT &operator * () const { return get(); }         
00073 
00074                 bool operator==(const CAdvance1Iterator &other) const { return other.It == It; }
00075                 bool operator!=(const CAdvance1Iterator &other) const { return !(*this == other); }
00076                 CAdvance1Iterator operator+(sint quantity) { return CAdvance1Iterator(It + quantity); }
00077                 CAdvance1Iterator &operator+=(sint quantity) { It = It + quantity; return *this; }
00078         };      
00079 
00080         
00081 
00089         template<typename T, typename PT>
00090         struct CAdvance1616Iterator
00091         {               
00092                 T It;
00093                 uint32 CurrPos;
00094                 uint32 Step;
00095                 CAdvance1616Iterator() {}
00097                 CAdvance1616Iterator(T it, uint32 index, uint32 step)
00098                 {
00099                         It = it;
00100                         CurrPos = index * step;
00101                         Step = step;
00102                 }
00103                         
00104                 const PT &get() const { return *(It + (CurrPos >> 16)); }
00105                 void advance() { CurrPos += Step; }
00106                 void advance(uint numSteps) 
00107                 { 
00108                         CurrPos = CurrPos + numSteps * Step; 
00109                 }       
00110                 const PT &operator * () const { return get(); }
00112                 CAdvance1616Iterator &operator++() { advance(); return *this; }
00113                 CAdvance1616Iterator operator++(int) { CAdvance1616Iterator tmp = this; advance(); return tmp; }                
00114                 bool operator==(const CAdvance1616Iterator &other) const 
00115                 { 
00116                         #ifdef _DEBUG
00117                                 nlassert(other.It == It);
00118                                 nlassert(other.Step == Step);
00119                         #endif                  
00120                         return other.CurrPos == CurrPos; 
00121                 }
00122                 bool operator!=(const CAdvance1616Iterator &other) const { return !(*this == other); }
00123                 CAdvance1616Iterator operator+(sint quantity) 
00124                 { 
00125                         CAdvance1616Iterator res; 
00126                         res.It = It;
00127                         res.CurrPos = CurrPos + Step * quantity;
00128                         res.Step = Step;
00129                         return res;
00130                 }
00131                 CAdvance1616Iterator &operator+=(sint quantity)
00132                 {
00133                         CurrPos += quantity * Step;
00134                         return *this;
00135                 }
00136         };
00137 
00138 
00139         
00142 
00144         typedef CAdvance1Iterator<TPSAttribFloat::const_iterator, float> TIteratorFloatStep1;
00145         typedef CAdvance1Iterator<TPSAttribFloat::const_iterator, TAnimationTime> TIteratorFloatStep1;
00146         typedef CAdvance1Iterator<TPSAttribVector::const_iterator, NLMISC::CVector> TIteratorVectStep1;
00147         typedef CAdvance1616Iterator<TPSAttribFloat::const_iterator, float> TIteratorFloatStep1616;
00148         typedef CAdvance1616Iterator<TPSAttribFloat::const_iterator, TAnimationTime> TIteratorTimeStep1616;
00149         typedef CAdvance1616Iterator<TPSAttribVector::const_iterator, NLMISC::CVector> TIteratorVectStep1616;
00150                 
00151 } // NL3D
00152 
00153 
00154 #endif