Go to the documentation of this file.
35 #include "CoinError.hpp"
149 if (pos < 0 || pos >=
size()) {
152 throw CoinError(
"Incorrest position setting.",
"setPosition",
170 size_t addSize1 =
static_cast<size_t>(addSize);
204 size_ +=
static_cast<int>(
sizeof(T));
214 throw CoinError(
"Reading over the end of buffer.",
215 "readRep(const T& value)",
"AlpsEncoded");
229 make_fit(
static_cast<int>(
sizeof(
int)) +
230 static_cast<int>(
sizeof(T)) * length );
232 size_ +=
static_cast<int>(
sizeof(int));
235 static_cast<int>(
sizeof(T)) * length);
236 size_ +=
static_cast<int>(
sizeof(T)) * length;
256 bool needAllocateMemory =
true)
259 if (needAllocateMemory) {
264 throw CoinError(
"Reading over the end of buffer.",
265 "readRep(T*& values, int& length,...",
274 throw CoinError(
"Reading over the end of buffer.",
275 "readRep(T*& values, int& length,...",
279 values =
new T[length];
281 pos_ +=
sizeof(T) * length;
290 throw CoinError(
"Reading over the end of buffer.",
291 "readRep(T*& values, int& length,...",
298 throw CoinError(
"Reading over the end of buffer.",
299 "readRep(T*& values, int& length,...",
305 throw CoinError(
"Reading over the end of buffer.",
306 "readRep(T*& values, int& length,...",
311 pos_ +=
sizeof(T) * length;
321 const int len =
static_cast<const int> (value.length());
322 make_fit(
static_cast<int>(
sizeof(
int)) + len );
324 size_ +=
static_cast<int>(
sizeof(int));
343 int objnum = vec.size();
344 int new_bytes = objnum *
sizeof(T);
345 make_fit(
sizeof(
int) + new_bytes );
347 size_ +=
sizeof(int);
360 throw CoinError(
"Reading over the end of buffer.",
361 "AlpsEncoded",
"readRep(std::vector<T>& vec");
369 throw CoinError(
"Reading over the end of buffer.",
370 "AlpsEncoded",
"readRep(std::vector<T>& vec");
372 vec.insert(vec.end(), objnum, T());
374 pos_ += objnum *
sizeof(T);
~AlpsEncoded()
Destructor.
void make_fit(const int addSize)
Reallocate the size of encoded if necessary so that at least addsize_ number of additional bytes will...
AlpsEncoded & writeRep(const std::vector< T > &vec)
Write a std::vector into repsentation_ .
char * representation_
The encoded/compressed representation of the object.
AlpsEncoded & readRep(T *&values, int &length, bool needAllocateMemory=true)
Read an array of objects of type T from repsentation_, where T must be a built-in type (ar at least ...
int type_
Represent the type of the object.
AlpsEncoded & readRep(std::string &value)
Read a std::string from repsentation_ .
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
void setPosition(const int pos)
int size_
The size of the packed representation.
AlpsEncoded & writeRep(const T *const values, const int length)
Write a C style array of objects of type T in repsentation_.
size_t maxSize_
The amount of memory allocated for the representation.
AlpsEncoded(int t, int s, char *&r)
Useful constructor.
size_t pos_
The next read/write position in the representation.
AlpsEncoded & operator=(const AlpsEncoded &)
AlpsEncoded & readRep(std::vector< T > &vec)
Read a std::vector from repsentation_ .
AlpsEncoded(int t)
Useful constructor.
void setRepresentation(char *&buf)
AlpsEncoded & writeRep(std::string &value)
Read a std::string in repsentation_ .
const char * representation() const
void clear()
Completely clear the encoded.
AlpsEncoded()
The default constructor creates a buffer of size 16 Kbytes with no message in it.