Files
envi-code/SourceCode/Code2026/inc/AdsXRx/BitTable.h
T

72 lines
1.9 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
//-----------------------------------------------------------------------------+
2026-09-28 15:28:50 +08:00
// Copyright (C), 1998-2007, SH Software Co. Ltd.
// = FileName : BitTable.h
// = Version : ver2.0
// = Author : zjq
// = CreateDate : 2002-09-09
2026-10-04 00:04:20 +08:00
// = Description: 类的声明,位数组,以位或位单元的模式来进行数据读写和内存分配,用于大规模控制矩阵
2026-09-28 15:28:50 +08:00
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#ifndef _BITTABLE_H_
#define _BITTABLE_H_
class GEOAPI BitTable
{
public:
BitTable(long unitNum, long unitSize = 1);
BitTable(void* p, long byteSize, bool bClient = true);
BitTable& operator = (const BitTable& bTable);
void Attach(long byteSize, char *p);
char* Detach();
~BitTable();
2026-10-04 00:04:20 +08:00
//位数转字节数
2026-09-28 15:28:50 +08:00
static long BitToByte(long bitNum);
bool IsValidIndex(long i) const;
long GetLength() const;
long GetByteSize() const;
long GetBitSize() const;
void SetUnitSize(long size);
long GetUnitSize() const;
2026-10-04 00:04:20 +08:00
//新单元数
2026-09-28 15:28:50 +08:00
void Realloc(long unitNum);
2026-10-04 00:04:20 +08:00
//bit read/write,使用位索引,非单元索引!
2026-09-28 15:28:50 +08:00
bool operator[](long i);
void Set(long i);
void Reset(long i);
//unit read/write
2026-10-04 00:04:20 +08:00
//取单元值
2026-09-28 15:28:50 +08:00
long GetValue(long i) const;
2026-10-04 00:04:20 +08:00
//单元赋值
2026-09-28 15:28:50 +08:00
void SetValue(long i,char value);
void SetAll(char value);
void SetAll();
void Reset();
//data transfer
operator char() const;
operator int() const;
operator float() const;
operator double() const;
operator const char*() const;
operator const int*() const;
operator const float*() const;
operator const double*() const;
protected:
2026-10-04 00:04:20 +08:00
//位定位
2026-09-28 15:28:50 +08:00
void BitToByte(long i, long& byteIndex,long& bitIndex) const;
2026-10-04 00:04:20 +08:00
//单元定位
2026-09-28 15:28:50 +08:00
void UnitToByte(long i, long& byteIndex,long& bitIndex) const;
protected:
long length; //unit num
2026-10-04 00:04:20 +08:00
long unit; //unit length; 仅支持1,2,4
2026-09-28 15:28:50 +08:00
char *pData;
2026-10-04 00:04:20 +08:00
bool bOwner; //是否数据代理
2026-09-28 15:28:50 +08:00
};
#endif