|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_IO_DESERIALIZER_H_
2 #define GENESIS_UTILS_IO_DESERIALIZER_H_
69 throw std::runtime_error(
"Creating Deserializer from file failed.");
77 throw std::runtime_error(
"Creating Deserializer from stream failed.");
85 inline operator bool()
const
145 size_t const got = buffer_.
read(buffer, n);
147 throw std::runtime_error(
148 "Could only read " +
std::to_string(got) +
" bytes instead of n=" +
159 char* buffer =
new char[n];
163 for (
size_t i = 0; i < n; ++i) {
164 ret &= (buffer[i] ==
'\0');
176 char* buffer =
new char[n];
179 std::string str (buffer, n);
190 size_t len = get_int<size_t>();
203 get_raw(
reinterpret_cast<char*
>( &res ),
sizeof(T) );
214 get_raw(
reinterpret_cast<char*
>( &res ),
sizeof(T) );
223 return get_plain<T>();
232 res = get_plain<T>();
241 return get_plain<T>();
250 res = get_plain<T>();
266 #endif // include guard
void get_raw(char *buffer, size_t n)
Read n bytes from the stream and store them in the buffer.
void get_int(T &res)
Read an integer number from the stream and store it in the result.
void get_plain(T &res)
Read as many bytes from the stream as the type T holds, and put them in the result value of type T.
T get_float()
Read a floating point number from the stream and return it.
std::string get_raw_string(size_t n)
Read n bytes from the stream and return them as a string.
std::string get_string()
Read a string from the stream, provided that its length it written preceding it, as done by put_strin...
Provides some valuable additions to STD.
std::string to_string(GenomeLocus const &locus)
T get_plain()
Read as many bytes from the stream as the type T holds, and return them in form of a value of type T.
T get_int()
Read an integer number from the stream and return it.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
bool get_null(size_t n)
Reads n bytes from the stream and returns whether all of them are \0 bytes.
void get_float(T &res)
Read an floating point number from the stream and store it in the result.
Deserializer(std::istream &instream)
Deserializer(std::string const &file_name)