//Editor-Info: -*- C++ -*-
//
//Subject:  TOVE project / 
//
//File: bitstring.h
//
//Version: $Revision: 1.12 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/12/17 17:42:41 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Authors:
//      Sami Raatikainen
//
//Description:
//      Class for bit string manipulation.
//      The length of the bit string is not limited.
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//      
//Licence:
//     
//
//History:
//
// 

#ifndef __PF_BITSTRING_H__
#define __PF_BITSTRING_H__

#include <typeinfo>
#include <string>
#include "pf/types.h"
#include "pf/frame.h"

const pfUlong OCTET = 8;

class pfBitString
{
    public:
        pfBitString(void);
        explicit pfBitString(const char *string_);
        explicit pfBitString(const string &string_);
        pfBitString(const pfBitString &other_);
        virtual ~pfBitString(void);
        
	const pfBitString &operator=(const pfBitString &other_);
        bool operator==(const pfBitString &other_) const;
        bool operator!=(const pfBitString &other_) const;
        friend ostream& operator<<(ostream &ostream_,
                                   const pfBitString &bitString_);
        pfUlong length(void) const;
        void clear(void);

        void putFirstBits(pfUlong value_, pfUlong length_);
        void putFirstBits(const string &string_);
        void putLastBits(pfUlong value_, pfUlong length_);
        void putLastBits(const string &string_);
        
        pfUlong getFirstBits(pfUlong length_);
        pfUlong getLastBits(pfUlong length_);
        pfUlong readBits(pfUlong offset_, pfUlong length_) const;
        string toString(pfUlong length_ = 0) const;
        
        void fromFrame(pfFrame &frame_, pfUlong length_);
        void toFrame(pfFrame &frame_);
        
    private:
        void checkString(const string &string_) const;
        string longToString(pfUlong value_, pfUlong length_) const;

        string _bitString;
};

#endif // __PF_BITSTRING_H__

