2013-10-30 11:46:18 +00:00
|
|
|
#ifndef PACKSTREAM_H
|
|
|
|
#define PACKSTREAM_H
|
|
|
|
|
|
|
|
#include "system_global.h"
|
2013-12-10 21:32:58 +00:00
|
|
|
|
2015-12-15 22:07:19 +00:00
|
|
|
#include <memory>
|
2013-10-30 11:46:18 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
namespace paysages {
|
|
|
|
namespace system {
|
2013-10-30 11:46:18 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Data (de)serialization in files or streams.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class SYSTEMSHARED_EXPORT PackStream {
|
|
|
|
public:
|
2013-10-30 11:46:18 +00:00
|
|
|
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);
|
2015-11-20 00:07:31 +00:00
|
|
|
/**
|
|
|
|
* Open a reading stream on a buffer content.
|
|
|
|
*/
|
2015-12-10 23:36:50 +00:00
|
|
|
PackStream(const string &buffer_content);
|
2015-11-20 00:07:31 +00:00
|
|
|
|
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-10-30 11:46:18 +00:00
|
|
|
|
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);
|
2013-10-30 11:46:18 +00:00
|
|
|
|
2015-08-13 21:46:50 +00:00
|
|
|
/**
|
|
|
|
* Write the contents of another stream into this one.
|
|
|
|
*
|
|
|
|
* The other stream must not have been bound to a file (still a memory buffer).
|
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
|
2015-11-20 00:07:31 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
2015-11-20 00:07:31 +00:00
|
|
|
|
2015-08-13 21:46:50 +00:00
|
|
|
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();
|
2013-10-30 11:46:18 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void skip(const int &value, int count = 1);
|
|
|
|
void skip(const double &value, int count = 1);
|
2015-08-13 21:46:50 +00:00
|
|
|
void skipBytes(int bytes);
|
2014-08-21 10:36:28 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-12-15 22:07:19 +00:00
|
|
|
class pimpl;
|
|
|
|
unique_ptr<pimpl> pv;
|
2013-10-30 11:46:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PACKSTREAM_H
|