git-svn-id: svn://db.shs.com.ru/pip@400 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
55
src_main/core/pichunkstream.cpp
Normal file
55
src_main/core/pichunkstream.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "pichunkstream.h"
|
||||
|
||||
/*! \class PIChunkStream
|
||||
* \brief Class for binary serialization
|
||||
*
|
||||
* \section PIChunkStream_sec0 Synopsis
|
||||
* This class provides very handly mechanism to store and restore values to and from
|
||||
* \a PIByteArray. The main advantage of using this class is that your binary data
|
||||
* become independent from order and collection of your values.
|
||||
*
|
||||
* \section PIChunkStream_sec1 Mechanism
|
||||
* %PIChunkStream works with items called "chunk". Chunk is an ID and any value that
|
||||
* can be stored and restored to \a PIByteArray with stream operators << and >>.
|
||||
* You can place chunks to stream and read chunks from stream.
|
||||
*
|
||||
* To construct %PIChunkStream for writing data use any constructor. Empty constructor
|
||||
* creates internal empty buffer that can be accessed by function \a data().
|
||||
* Non-empty constructor works with given byte array.
|
||||
*
|
||||
* To read chunks from byte array use function \a read() that returns ID of
|
||||
* next chunk. Then you can get value of this chunk with function \a getData(),
|
||||
* but you should definitely know type of this value. You can read from byte array
|
||||
* while \a atEnd() if false.
|
||||
*
|
||||
* \section PIChunkStream_ex0 Example
|
||||
* Prepare your structs to work with %PIChunkStream
|
||||
* \snippet pichunkstream.cpp struct
|
||||
* Writing to %PIChunkStream
|
||||
* \snippet pichunkstream.cpp write
|
||||
* Reading from %PIChunkStream
|
||||
* \snippet pichunkstream.cpp read
|
||||
*/
|
||||
|
||||
|
||||
void PIChunkStream::setSource(const PIByteArray & data) {
|
||||
data_ = const_cast<PIByteArray*>(&data);
|
||||
_init();
|
||||
}
|
||||
|
||||
|
||||
void PIChunkStream::setSource(PIByteArray * data) {
|
||||
data_ = (data ? data : &tmp_data);
|
||||
_init();
|
||||
}
|
||||
|
||||
|
||||
PIChunkStream::~PIChunkStream() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PIChunkStream::_init() {
|
||||
last_id = -1;
|
||||
last_data.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user