#ifndef DPTUTFENCODE_H #define DPTUTFENCODE_H typedef unsigned int u32; class IDptByteEncode { public: int Encode(unsigned char *b, u32 val); int Decode(const unsigned char *b, u32 &val); }; // Iterator class which uses above encoding and runlength encoding of zeroes class IDptByteEncodeItr { public: IDptByteEncodeItr(unsigned char *buff) : fZeros(0), fEndPtr(buff), fZeroPtr(NULL) {} // ctor unsigned char *GetEndPtr() { return fEndPtr; } void Insert(u32 val); void InsertEndMark() { *fEndPtr = 0xFE; fEndPtr++; fZeros=0; } private: IDptByteEncode e; // Just a clump of histograms u32 fZeros; // Number of zeros in current run unsigned char *fEndPtr; // Pointer to the first unused location unsigned char *fZeroPtr; // Pointer to the current zeros record }; // Companion decoder for DptByteEncodeItr // To use, // Call ctor // while (I want another histogram) { // Loop nbins times, call GetNextValue // GetState, if 0, continue, if 1 we have finished spot on, // if 2 we have overrun, if 3 something bad happened and we cheerfully returned 0 to some of the calls // } class IDptByteDecodeItr { public: IDptByteDecodeItr(const unsigned char *buff) : fZeros(0), fEndPtr(buff), fState(0) {} const unsigned char *GetEndPtr() { return fEndPtr; } int GetState() { return fState; } u32 GetNextValue(); int IsNextAnEndMark() { return ((*fEndPtr)==0xFE); } private: IDptByteEncode e; // Just a clump of histograms u32 fZeros; // Number of zeros issued so far this run const unsigned char *fEndPtr; // Pointer to the first unused location int fState; // Status: 0=Normal, 1 = reached end OK, // 2 = read beyond end, 3 = error in decoding }; #endif