📄 matrixiterator.hpp
字号:
{
}
SelfType& operator ++()
{
MoveNext();
return *this;
}
SelfType operator ++(int)
{
SelfType t(*this);
++*this;
return t;
}
NumberType& operator * ()
{
return pData[index(CurrRow, CurrCol)];
}
Bool MoveNext()
{
if (++CurrCol == Col)
{
CurrCol = ++CurrRow;
if (CurrRow == Row)
{
ok = false;
}
}
return ok;
}
protected:
Int32 index(Int32 _row, Int32 _col) const
{
return (Row + Row - _row - 1) * _row / 2 + _col;
}
};
template<
typename _DataType,
typename _NumberType
>
struct ConstUpperMatrixStoredElementIterator
: public UpperMatrixStoredElementIterator<_DataType, _NumberType>
{
typedef ConstUpperMatrixStoredElementIterator SelfType;
typedef _NumberType NumberType;
typedef _DataType DataType;
typedef UpperMatrixStoredElementIterator<_DataType, _NumberType>
BaseType;
using BaseType::pData;
using BaseType::Row;
using BaseType::Col;
using BaseType::CurrRow;
using BaseType::CurrCol;
using BaseType::ok;
using BaseType::MoveNext;
ConstUpperMatrixStoredElementIterator(DataType * _pData, Int32 _Row, Int32 _Col)
: BaseType(_pData, _Row, _Col)
{
}
SelfType& operator ++()
{
MoveNext();
return *this;
}
SelfType operator ++(int)
{
SelfType t(*this);
++*this;
return t;
}
NumberType operator * ()
{
return pData[index(CurrRow, CurrCol)];
}
};
template<
typename _DataType,
typename _NumberType
>
struct LowerMatrixStoredElementIterator
: public MatrixStoredElementIterator<_DataType, _NumberType,
LowerMatrixStoredElementIterator<_DataType, _NumberType> >
{
typedef LowerMatrixStoredElementIterator SelfType;
typedef _NumberType NumberType;
typedef _DataType DataType;
typedef MatrixStoredElementIterator<_DataType, _NumberType, SelfType >
BaseType;
using BaseType::pData;
using BaseType::Row;
using BaseType::Col;
using BaseType::CurrRow;
using BaseType::CurrCol;
using BaseType::ok;
LowerMatrixStoredElementIterator(DataType * _pData, Int32 _Row, Int32 _Col)
: BaseType(_pData, _Row, _Col)
{
}
SelfType& operator ++()
{
MoveNext();
return *this;
}
SelfType operator ++(int)
{
SelfType t(*this);
++*this;
return t;
}
NumberType& operator * ()
{
return pData[index(CurrRow, CurrCol)];
}
Bool MoveNext()
{
if (++CurrCol == CurrRow+1)
{
CurrCol = 0;
if (++CurrRow == Row)
{
ok = false;
}
}
return ok;
}
protected:
Int32 index(Int32 _row, Int32 _col) const
{
return (1 + _row) * _row / 2 + _col;
}
};
template<
typename _DataType,
typename _NumberType
>
struct ConstLowerMatrixStoredElementIterator
: public LowerMatrixStoredElementIterator<_DataType, _NumberType>
{
typedef ConstLowerMatrixStoredElementIterator SelfType;
typedef _NumberType NumberType;
typedef _DataType DataType;
typedef LowerMatrixStoredElementIterator<_DataType, _NumberType>
BaseType;
using BaseType::pData;
using BaseType::Row;
using BaseType::Col;
using BaseType::CurrRow;
using BaseType::CurrCol;
using BaseType::ok;
using BaseType::MoveNext;
ConstLowerMatrixStoredElementIterator(DataType * _pData, Int32 _Row, Int32 _Col)
: BaseType(_pData, _Row, _Col)
{
}
SelfType& operator ++()
{
MoveNext();
return *this;
}
SelfType operator ++(int)
{
SelfType t(*this);
++*this;
return t;
}
NumberType operator * ()
{
return pData[index(CurrRow, CurrCol)];
}
};
template<
typename _DataType,
typename _NumberType
>
struct SymMatrixStoredElementIterator
: public MatrixStoredElementIterator<_DataType, _NumberType,
SymMatrixStoredElementIterator<_DataType, _NumberType> >
{
typedef SymMatrixStoredElementIterator SelfType;
typedef _NumberType NumberType;
typedef _DataType DataType;
typedef MatrixStoredElementIterator<_DataType, _NumberType, SelfType >
BaseType;
using BaseType::pData;
using BaseType::Row;
using BaseType::Col;
using BaseType::CurrRow;
using BaseType::CurrCol;
using BaseType::ok;
SymMatrixStoredElementIterator(DataType * _pData, Int32 _Row, Int32 _Col)
: BaseType(_pData, _Row, _Col)
{
}
SelfType& operator ++()
{
MoveNext();
return *this;
}
SelfType operator ++(int)
{
SelfType t(*this);
++*this;
return t;
}
NumberType& operator * ()
{
return pData[index(CurrRow, CurrCol)];
}
Bool MoveNext()
{
if (++CurrCol == CurrRow+1)
{
CurrCol = 0;
if (++CurrRow == Row)
{
ok = false;
}
}
return ok;
}
protected:
Int32 index(Int32 _row, Int32 _col) const
{
return (1 + _row) * _row / 2 + _col;
}
};
template<
typename _DataType,
typename _NumberType
>
struct ConstSymMatrixStoredElementIterator
: public SymMatrixStoredElementIterator<_DataType, _NumberType>
{
typedef ConstSymMatrixStoredElementIterator SelfType;
typedef _NumberType NumberType;
typedef _DataType DataType;
typedef SymMatrixStoredElementIterator<_DataType, _NumberType>
BaseType;
using BaseType::pData;
using BaseType::Row;
using BaseType::Col;
using BaseType::CurrRow;
using BaseType::CurrCol;
using BaseType::ok;
using BaseType::MoveNext;
ConstSymMatrixStoredElementIterator(DataType * _pData, Int32 _Row, Int32 _Col)
: BaseType(_pData, _Row, _Col)
{
}
SelfType& operator ++()
{
MoveNext();
return *this;
}
SelfType operator ++(int)
{
SelfType t(*this);
++*this;
return t;
}
NumberType operator * ()
{
return pData[index(CurrRow, CurrCol)];
}
};
template<
typename _DataType,
typename _NumberType
>
struct SparseMatrixStoredElementIterator
: public MatrixStoredElementIterator<_DataType, _NumberType,
SparseMatrixStoredElementIterator<_DataType, _NumberType> >
{
typedef SparseMatrixStoredElementIterator SelfType;
typedef _NumberType NumberType;
typedef _DataType DataType;
typedef MatrixStoredElementIterator<_DataType, _NumberType, SelfType >
BaseType;
using BaseType::pData;
using BaseType::Row;
using BaseType::Col;
using BaseType::CurrRow;
using BaseType::CurrCol;
using BaseType::ok;
SparseMatrixStoredElementIterator(DataType * _pData, Int32 _Row, Int32 _Col)
: BaseType(_pData, _Row, _Col)
{
Reset();
}
SelfType& operator ++()
{
MoveNext();
return *this;
}
SelfType operator ++(int)
{
SelfType t(*this);
++*this;
return t;
}
NumberType& operator * ()
{
return Iter->second;
}
Bool MoveNext()
{
++Iter;
BindIndex();
return ok;
}
void Reset()
{
Iter = pData->begin();
BindIndex();
}
protected:
void BindIndex()
{
if (Iter == pData->end())
{
ok = false;
}
else
{
CurrRow = (Iter->first >> 16);
CurrCol = (Iter->first & 0x0000ffff);
ok = true;
}
}
protected:
typename DataType::iterator Iter;
};
template<
typename _DataType,
typename _NumberType
>
struct ConstSparseMatrixStoredElementIterator
: public SparseMatrixStoredElementIterator<_DataType, _NumberType>
{
typedef ConstSparseMatrixStoredElementIterator SelfType;
typedef _NumberType NumberType;
typedef _DataType DataType;
typedef SparseMatrixStoredElementIterator<_DataType, _NumberType>
BaseType;
using BaseType::pData;
using BaseType::Row;
using BaseType::Col;
using BaseType::CurrRow;
using BaseType::CurrCol;
using BaseType::ok;
using BaseType::Iter;
using BaseType::MoveNext;
ConstSparseMatrixStoredElementIterator(DataType * _pData, Int32 _Row, Int32 _Col)
: BaseType(_pData, _Row, _Col)
{
}
SelfType& operator ++()
{
MoveNext();
return *this;
}
SelfType operator ++(int)
{
SelfType t(*this);
++*this;
return t;
}
NumberType operator * ()
{
return Iter->second;
}
};
SDL_MATHS_MATRIX_END
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -