为可压缩存储,我真是煞费苦心,能不能帮我看看还有没有其他方法实现双下标?
能不能帮我看看还有没有其他方法实现双下标
#include <assert.h>
#include <iostream>
#define HALF(X) ((X+1)/2)
class CBit4Matrix
{
typedef struct
{
unsigned char High:4;
unsigned char Low:4;
}DFOURBITS;
class CBit4Value
{
DFOURBITS& _Value;
bool _bLow;
public:
CBit4Value(DFOURBITS& value,bool bLow):_Value(value) {};
virtual ~CBit4Value() {};
unsigned char operator= (unsigned char n)
{assert(n<16);_bLow?_Value.Low=n:_Value.High=n;return n;}
operator unsigned char () {return _bLow?_Value.Low:_Value.High;}
};
class CBit4Line
{
DFOURBITS* _pLine;
CBit4Matrix* _pMat;
public:
CBit4Line(DFOURBITS* p,CBit4Matrix* pMat):_pLine(p),_pMat(pMat)
{ASSERT(nLn>0 && nCol>0);
_pData = new DFOURBITS[_sLn*HALF(_sCol)];}
virtual ~CBit4Line()
if (_pData)
{delete []_pData;_pData = NULL; }
CBit4Value operator [] (long nCol)
{assert(nCol<_pMat->getCol() && nCol>=0);
CBit4Value rMV(_pLine[nCol/2],nCol%2);
return rMV;}
};
DFOURBITS *_pData;
long _sLn,_sCol;
///< 逻辑上的总行列数 \n\e不是物理上的 \n\e 使用时要加HALF宏转变成物理上的
public:
CBit4Matrix();
CBit4Matrix(long nLn,long nCol);
virtual ~CBit4Matrix();
long getLn() const {return _sLn;}
long getCol() const {return _sCol;}
CBit4Line operator [] (long nLn)
{assert(nLn<_sLn && nLn>=0);
CBit4Line r(_pData+nLn*HALF(_sCol),this);
return r;}
friend std::ostream& operator<<(std::ostream& os,CBit4Matrix& m)
{
long i,j;
for (i=0;i<m._sLn;i++)
{
for (j=0;j<HALF(m._sCol);j++)
{
os<<(int)m._pData[i*HALF(m._sCol)+j].High<<" ";
os<<(int)m._pData[i*HALF(m._sCol)+j].Low<<" ";
}
os<<std::endl;
}
return os;
}
};
就是为了实现双下标,好麻烦,呵呵,
void test_run()
{
CBit4Matrix m(3,3);
int i,j;
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
m[i][j] = i*3+j;
cerr<<i*3+j;
}cerr<<endl;
}
cerr<<m;//这块还有点问题,莫名奇妙,再研究研究
//error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class CBit4Matrix' (or there is no acceptable conversion)
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cerr<<(int)m[i][j]<<' ';
}cerr<<endl;
}
}
#include <assert.h>
#include <iostream>
#define HALF(X) ((X+1)/2)
class CBit4Matrix
{
typedef struct
{
unsigned char High:4;
unsigned char Low:4;
}DFOURBITS;
class CBit4Value
{
DFOURBITS& _Value;
bool _bLow;
public:
CBit4Value(DFOURBITS& value,bool bLow):_Value(value) {};
virtual ~CBit4Value() {};
unsigned char operator= (unsigned char n)
{assert(n<16);_bLow?_Value.Low=n:_Value.High=n;return n;}
operator unsigned char () {return _bLow?_Value.Low:_Value.High;}
};
class CBit4Line
{
DFOURBITS* _pLine;
CBit4Matrix* _pMat;
public:
CBit4Line(DFOURBITS* p,CBit4Matrix* pMat):_pLine(p),_pMat(pMat)
{ASSERT(nLn>0 && nCol>0);
_pData = new DFOURBITS[_sLn*HALF(_sCol)];}
virtual ~CBit4Line()
if (_pData)
{delete []_pData;_pData = NULL; }
CBit4Value operator [] (long nCol)
{assert(nCol<_pMat->getCol() && nCol>=0);
CBit4Value rMV(_pLine[nCol/2],nCol%2);
return rMV;}
};
DFOURBITS *_pData;
long _sLn,_sCol;
///< 逻辑上的总行列数 \n\e不是物理上的 \n\e 使用时要加HALF宏转变成物理上的
public:
CBit4Matrix();
CBit4Matrix(long nLn,long nCol);
virtual ~CBit4Matrix();
long getLn() const {return _sLn;}
long getCol() const {return _sCol;}
CBit4Line operator [] (long nLn)
{assert(nLn<_sLn && nLn>=0);
CBit4Line r(_pData+nLn*HALF(_sCol),this);
return r;}
friend std::ostream& operator<<(std::ostream& os,CBit4Matrix& m)
{
long i,j;
for (i=0;i<m._sLn;i++)
{
for (j=0;j<HALF(m._sCol);j++)
{
os<<(int)m._pData[i*HALF(m._sCol)+j].High<<" ";
os<<(int)m._pData[i*HALF(m._sCol)+j].Low<<" ";
}
os<<std::endl;
}
return os;
}
};
就是为了实现双下标,好麻烦,呵呵,
void test_run()
{
CBit4Matrix m(3,3);
int i,j;
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
m[i][j] = i*3+j;
cerr<<i*3+j;
}cerr<<endl;
}
cerr<<m;//这块还有点问题,莫名奇妙,再研究研究
//error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class CBit4Matrix' (or there is no acceptable conversion)
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cerr<<(int)m[i][j]<<' ';
}cerr<<endl;
}
}
...全文
相关推荐
循环托普利兹块相位掩模可压缩双透镜成像
"循环托普利兹块相位掩模可压缩双透镜成像"本文探讨了压缩成像技术的一种新应用,即循环托普利兹块相位掩模矩阵可压缩双透镜成像方法。压缩成像,源自压缩传感理论,是图像处理领域的一个重要分支,其核心思想
微可压缩液体流场模拟的预处理方法
这种方法在大多数情况下是适用的,但是对于低速流动,尤其是在考虑微压缩性时,传统的不可压缩流体模拟方法就显得力不从心。
基于分层屈曲的碳纳米管/橡胶双护套芯纤维的柔性和可压缩温度传感器
"基于分层屈曲的碳纳米管/橡胶双护套芯纤维的柔性和可压缩温度传感器"本文是一篇研究论文,发表在《纳米科学与纳米技术》期刊上,探讨了一种新型的柔性且可压缩的温度传感器设计。这种传感器采用独特的分层弯
二维不可压缩流的谱方法 (1999年)
谱方法的概念最早可以追溯到经典的Ritz-Galerkin方法,该方法以其高精度而著称,又被称为“无穷阶收敛”。由于早期计算资源有限,这种方法在一段时间内并没有被广泛使用。
最终源代码_管道_matlab管道_瞬变流_可压缩流体_特征线法
在MATLAB中,可以编程实现特征线法来模拟瞬变流体流动。在"最终源代码.txt"文件中,可能包含了用MATLAB编写的程序代码,用于实现特征线法求解管道中的可压缩流瞬变流动问题。



