18#ifdef MCRL2_PLATFORM_WINDOWS
31template<
typename int_t = std::
size_t>
34 size_t outputSize = 0;
41 output[outputSize] = (
static_cast<uint8_t
>(value & 127)) | 128;
48 output[outputSize] = (
static_cast<uint8_t
>(value));
49 return outputSize + 1;
56template<
typename int_t = std::
size_t>
60 for (
size_t i = 0; i < integer_encoding_size<int_t>(); i++)
66 value |= (
static_cast<int_t
>(byte) & 127) << (7 * i);
73 else if (i >= integer_encoding_size<int_t>() - 1)
76 throw std::runtime_error(
"Fail to read an int from the input");
87#ifdef MCRL2_PLATFORM_WINDOWS
88 if (_setmode(_fileno(handle), _O_BINARY) == -1)
105 if (
stream.rdbuf() == std::cout.rdbuf())
109 else if (
stream.rdbuf() == std::cerr.rdbuf())
118 assert(number_of_bits <= std::numeric_limits<std::size_t>::digits);
119 if (number_of_bits < std::numeric_limits<std::size_t>::digits)
121 value &= (
static_cast<std::size_t
>(1) << number_of_bits) - 1;
130 unsigned long long write_value = (
write_buffer >> 64).to_ullong();
134 for (int32_t i = 7; i >= 0; --i)
137 stream.put(
static_cast<char>((write_value >> (8 * i)) & 255));
153 write(
reinterpret_cast<const std::uint8_t*
>(
string.c_str()),
string.size());
167 if (
stream.rdbuf() == std::cin.rdbuf())
196 assert(number_of_bits <= std::numeric_limits<std::size_t>::digits);
218 std::size_t value = (
read_buffer >> (128 - number_of_bits)).to_ullong();
249 for (std::size_t index = 0; index < size; ++index)
258 for (std::size_t index = 0; index < size; ++index)
262 buffer[index] =
static_cast<std::uint8_t
>(value);
static void set_stream_binary(const std::string &name, FILE *handle)
Change the current stream to binary mode (no handle of newline characters),.
static size_t encode_variablesize_int(int_t value, uint8_t *output)
Encodes an unsigned variable-length integer using the most significant bit (MSB) algorithm....
int_t decode_variablesize_int(ibitstream &stream)
Decodes an unsigned variable-length integer using the MSB algorithm.
Standard exception class for reporting runtime errors.
The counterpart of obitstream, guarantees that the same data is read as has been written when calling...
std::size_t read_integer()
unsigned int bits_in_buffer
how many bits in the buffer are used.
std::size_t read_bits(unsigned int num_of_bits)
Reads an num_of_bits bits from the input stream and stores them in the least significant part (in des...
void read(std::size_t size, std::uint8_t *buffer)
Read size bytes into the provided buffer.
std::vector< char > m_text_buffer
A temporary buffer to store char array strings.
const char * read_string()
std::bitset< 128 > read_buffer
Buffer that is filled starting from bit 127 when reading.
ibitstream(std::istream &stream)
Provides the stream on which the read function operate.
void flush()
Flush the remaining bits in the buffer to the output stream.
std::bitset< 128 > write_buffer
Buffer that is filled starting from bit 127 when writing.
unsigned int bits_in_buffer
how many bits in are used in the buffer.
std::uint8_t integer_buffer[integer_encoding_size< std::size_t >()]
Reserved space to store an n byte integer.
void write_bits(std::size_t value, unsigned int num_of_bits)
Write the num_of_bits least significant bits in descending order from value.
void write(const std::uint8_t *buffer, std::size_t size)
Writes size bytes from the given buffer.
void write_string(const std::string &string)
Write the given string to the output stream.
void write_integer(std::size_t value)
Write the given value to the output stream.
obitstream(std::ostream &stream)
Provides the stream on which the write function operate.
Exception classes for use in libraries and tools.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
static T round_up_to_power_of_two(T value)
void mcrl2_unused(T &&...)
Function that can be used to silence unused parameter warnings.
add your file description here.