paysages3d/src/system/PackStream.h

65 lines
1.5 KiB
C
Raw Permalink Normal View History

#pragma once
#include "system_global.h"
2015-12-15 22:07:19 +00:00
#include <memory>
namespace paysages {
namespace system {
2016-01-03 18:21:23 +00:00
/**
* Data (de)serialization in files or streams.
*/
class SYSTEMSHARED_EXPORT PackStream {
public:
PackStream();
2015-08-13 22:22:20 +00:00
/**
* Open a reading stream for another stream.
*
* The other stream must not have been bound to a file (still a memory buffer).
*/
PackStream(const PackStream *other);
/**
* Open a reading stream on a buffer content.
*/
2015-12-10 23:36:50 +00:00
PackStream(const string &buffer_content);
2015-12-15 22:07:19 +00:00
~PackStream();
2015-12-10 23:36:50 +00:00
bool bindToFile(const string &filepath, bool write = false);
2013-11-11 12:56:39 +00:00
void write(const int *value);
void write(const double *value);
void write(const char *value, const int max_length);
2015-12-10 23:36:50 +00:00
void write(const string &value);
/**
* Write the contents of another stream into this one.
*
* The other stream must not have been bound to a file (still a memory buffer).
*
2016-01-06 18:55:49 +00:00
* If 'prepend_size' is true, an integer will be written on front with the number of bytes written.
*/
void writeFromBuffer(const PackStream &other, bool prepend_size = false);
/**
* Get the contents of the memory buffer, if this stream is not bound to a file.
*/
2015-12-10 23:36:50 +00:00
string getBuffer();
void read(int *value);
void read(double *value);
void read(char *value, int max_length);
2015-12-10 23:36:50 +00:00
string readString();
void skip(const int &value, int count = 1);
void skip(const double &value, int count = 1);
void skipBytes(int bytes);
private:
2015-12-15 22:07:19 +00:00
class pimpl;
unique_ptr<pimpl> pv;
};
}
}