Program Listing for File PackedBits.h
↰ Return to documentation for file (ADS/compression/PackedBits.h)
/*--------------------------------------------------------------------------*/
/*--------------------------- File PackedBits.h ----------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_PackedBits
#define __ADS_PackedBits
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <vector>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
/*--------------------------------------------------------------------------*/
/*------------------------- CLASS PackedBitWriter --------------------------*/
/*--------------------------------------------------------------------------*/
class PackedBitWriter {
/*--------------------------------------------------------------------------*/
public:
void put( bool b );
void put( std::uint64_t v , int k );
void put( const std::string & s );
[[nodiscard]] std::size_t size( void ) const { return( f_size ); }
[[nodiscard]] const std::vector< std::uint8_t > & bytes( void ) const {
return( f_bytes );
}
/*--------------------------------------------------------------------------*/
private:
std::vector< std::uint8_t > f_bytes;
std::size_t f_size = 0;
}; // end( class PackedBitWriter )
/*--------------------------------------------------------------------------*/
/*------------------------- CLASS PackedBitReader --------------------------*/
/*--------------------------------------------------------------------------*/
class PackedBitReader {
/*--------------------------------------------------------------------------*/
public:
explicit PackedBitReader( std::span< const std::uint8_t > b )
: f_bytes( b ) {}
bool get( void );
std::uint64_t get( int k );
[[nodiscard]] std::size_t position( void ) const { return( f_pos ); }
[[nodiscard]] std::size_t size( void ) const {
return( 8 * f_bytes.size() );
}
/*--------------------------------------------------------------------------*/
private:
std::span< const std::uint8_t > f_bytes;
std::size_t f_pos = 0;
}; // end( class PackedBitReader )
/*--------------------------------------------------------------------------*/
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/compression/impl/PackedBits.tpp"
/*--------------------------------------------------------------------------*/
#endif /* PackedBits.h included */
/*--------------------------------------------------------------------------*/
/*------------------------- End File PackedBits.h --------------------------*/
/*--------------------------------------------------------------------------*/