00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#ifndef SH_BITSTRING_H
00022
#define SH_BITSTRING_H
00023
00024
#include <vector>
00025
#include <string>
00026
00027
#include "AUtils.h"
00028
#include "common.h"
00029
00042 class BitString {
00043
public:
00047
BitString (
EmbValue arity = 2) ;
00048
00052
BitString (
const BitString& bs) ;
00053
00057
BitString (
const unsigned long l) ;
00058
00062
BitString (
const std::vector<BYTE>& d) ;
00063
00067
BitString (
const std::string& d) ;
00068
00069
void setArity (
EmbValue arity) ;
00070
00071 EmbValue getArity (
void)
const
00072
{
return Arity ; } ;
00073
00077 UWORD32 getLength (
void)
const
00078
{
return Length ; } ;
00079
00083 UWORD32 getNAryLength (
void)
const
00084
{
return AUtils::div_roundup<UWORD32> (
Length,
ArityNBits) ; } ;
00085
00089
BitString&
clear (
void) ;
00090
00094
BitString& append (
const BIT v) ;
00095
00101
BitString& append (
const BYTE v,
const unsigned short n = 8) ;
00102
00108
BitString& append (
const UWORD16 v,
const unsigned short n = 16) ;
00109
00115
BitString& append (
const UWORD32 v,
const unsigned short n = 32) ;
00116
00120
BitString& append (
const std::string& v) ;
00121
00125
BitString& append (
const std::vector<BYTE>& v) ;
00126
00131
BitString& append (
const BitString& v) ;
00132
00138
BitString& setBit (
unsigned long i, BIT v) ;
00139
00146
BitString getBits (
const unsigned long s,
const unsigned long l)
const ;
00147
00156
BitString cutBits (
const unsigned long s,
const unsigned long l) ;
00157
00164
UWORD32 getValue (
const unsigned long s,
const unsigned short l)
const ;
00165
00172
const std::vector<BYTE>&
getBytes (
void) const ;
00173
00180
BitString& truncate (const
unsigned long s, const
unsigned long e) ;
00181
00187
BitString& pad (const
unsigned long mult, const BIT v) ;
00188
00193
BitString& padRandom (const
unsigned long mult) ;
00194
00200 BYTE getNAry (
unsigned long p) const ;
00201
00206
void appendNAry (BYTE v) ;
00207
00208 #ifdef USE_ZLIB
00216
BitString& compress (
int level) ;
00217
00231
BitString& uncompress (
unsigned long idestlen) ;
00232 #endif
00233
00237 BIT operator[] (const
unsigned long i) const ;
00238
00243
BitString& operator^= (const
BitString &v) ;
00244
00249
bool operator== (const
BitString& v) const ;
00250
00255
bool operator!= (const
BitString& v) const ;
00256
00257
void print (
unsigned short spc = 0) const ;
00258 #ifdef DEBUG
00259
void printDebug (
unsigned short level,
unsigned short spc = 0) const ;
00260 #endif
00261
00262 private:
00264 UWORD32 Length ;
00266 EmbValue Arity ;
00268 unsigned short ArityNBits ;
00270 std::vector<BYTE> Data ;
00271
00272
void _append (
BIT v) ;
00273
00277
void clearUnused (
void) ;
00278 } ;
00279
00280 #endif