/*
 * @(#) bitstrea.h - I/O bit stream support functions library header.
 * (c) 1998 Ivan Maidanski <ivmai@chat.ru> http://ivmai.chat.ru
 * Freeware function library source. All rights reserved.
 **
 * Language: ISO/ANSI C++
 * Tested with: Watcom C++ 16/32 v11.0
 * Last modified: 1998-06-21 21:00:00 GMT+04:00
 */

// Library source file: bitstrea.cpp

// BitPut();
// BitFlush();
// BitGet();
// BitValPut();
// BitValGet();

#ifndef _BITSTREA_H_INCLUDED
#define _BITSTREA_H_INCLUDED

#ifndef __cplusplus
#error This file is for use with C++
#endif

#include <iostream.h> // istream, ostream

// declaration section

ostream &BitPut(ostream &, unsigned char &, int);
 // BitPut - stores one bit (the 3rd argument) into stream;
// the 2nd argument is a work variable (put buffer),
// which initially must be 0.

ostream &BitFlush(ostream &, unsigned char &);
 // BitFlush - flushes all unstored bits into stream
// without stream flushing;
// the 2nd argument is a work variable (put buffer),
// it will be set to 0 after flushing.

int BitGet(istream &, unsigned char &);
 // BitGet - reads one bit from stream;
// the 2nd argument is a work variable (get buffer),
// which initially must be 0.

ostream &BitValPut(ostream &, unsigned char &, unsigned long, unsigned long);
 // BitValPut - stores specified value (the 3rd argument) into stream as
// a serial of bits; work buffer (the 2nd argument) is the same
// as for BitPut; current maximal output value (the 4th argument) is
// necessary to determine the bit length of the stored value.

unsigned long BitValGet(istream &, unsigned char &, unsigned long);
unsigned long BitValGet(istream &, unsigned char &, unsigned long, int &);
 // BitValGet() - reads stored value from the stream as a serial of bits;
// work buffer (the 2nd argument) is the same as for BitGet;
// current maximal input value (the 3th argument) is necessary to
// determine the bit length of the stored value;
// if stored value exceedes maximal, it will be wrapped around 0;
// the 4th argument (optional) is the value-wrapped flag.

// inline section

inline unsigned long BitValGet(istream &Stream, unsigned char &BufG,
                               unsigned long MaxVal)
{
 int Wrapped;
 return BitValGet(Stream,BufG,MaxVal,Wrapped);
}

#endif
