111 if (pos < 0 || pos >=
size()) {
114 throw CoinError(
"Incorrest position setting.",
"setPosition",
132 size_t addSize1 =
static_cast<size_t>(addSize);
166 size_ +=
static_cast<int>(
sizeof(T));
176 throw CoinError(
"Reading over the end of buffer.",
177 "readRep(const T& value)",
"AlpsEncoded");
191 make_fit( static_cast<int>(
sizeof(
int)) +
192 static_cast<int>(
sizeof(T)) * length );
194 size_ +=
static_cast<int>(
sizeof(int));
197 static_cast<int>(
sizeof(T)) * length);
198 size_ +=
static_cast<int>(
sizeof(T)) * length;
218 bool needAllocateMemory =
true)
221 if (needAllocateMemory) {
226 throw CoinError(
"Reading over the end of buffer.",
227 "readRep(T*& values, int& length,...",
236 throw CoinError(
"Reading over the end of buffer.",
237 "readRep(T*& values, int& length,...",
241 values =
new T[length];
243 pos_ +=
sizeof(T) * length;
252 throw CoinError(
"Reading over the end of buffer.",
253 "readRep(T*& values, int& length,...",
260 throw CoinError(
"Reading over the end of buffer.",
261 "readRep(T*& values, int& length,...",
267 throw CoinError(
"Reading over the end of buffer.",
268 "readRep(T*& values, int& length,...",
273 pos_ +=
sizeof(T) * length;
283 const int len =
static_cast<const int> (value.length());
284 make_fit( static_cast<int>(
sizeof(
int)) + len );
286 size_ +=
static_cast<int>(
sizeof(int));
305 int objnum = vec.
size();
306 int new_bytes = objnum *
sizeof(T);
307 make_fit(
sizeof(
int) + new_bytes );
309 size_ +=
sizeof(int);
322 throw CoinError(
"Reading over the end of buffer.",
323 "AlpsEncoded",
"readRep(std::vector<T>& vec");
331 throw CoinError(
"Reading over the end of buffer.",
332 "AlpsEncoded",
"readRep(std::vector<T>& vec");
334 vec.insert(vec.end(), objnum, T());
336 pos_ += objnum *
sizeof(T);
AlpsEncoded & readRep(T &value)
Read a single object of type <code>T</code> from <code>repsentation_ .
AlpsEncoded & writeRep(const T &value)
Write a single object of type <code>T</code> in <code>repsentation_ .
AlpsEncoded(int t)
Useful constructor.
AlpsEncoded(int t, int s, char *&r)
Useful constructor.
const char * representation() const
AlpsEncoded & readRep(T *&values, int &length, bool needAllocateMemory=true)
Read an array of objects of type <code>T</code> from <code> repsentation_, where T must be a built-i...
AlpsEncoded()
The default constructor creates a buffer of size 16 Kbytes with no message in it.
This data structure is to contain the packed form of an encodable knowledge.
AlpsEncoded & writeRep(const std::vector< T > &vec)
Write a std::vector into repsentation_ .
~AlpsEncoded()
Destructor.
AlpsEncoded & writeRep(const T *const values, const int length)
Write a C style array of objects of type <code>T</code> in repsentation_.
void make_fit(const int addSize)
Reallocate the size of encoded if necessary so that at least addsize_ number of additional bytes will...
char * representation_
The encoded/compressed representation of the object.
AlpsEncoded & operator=(const AlpsEncoded &)
Disable copy constructor and assignment operator.
AlpsEncoded & readRep(std::string &value)
Read a std::string from repsentation_ .
size_t maxSize_
The amount of memory allocated for the representation.
int type_
Represent the type of the object.
Error Class thrown by an exception.
size_t pos_
The next read/write position in the representation.
void clear()
Completely clear the encoded.
void setRepresentation(char *&buf)
AlpsEncoded & writeRep(std::string &value)
Read a std::string in repsentation_ .
void setPosition(const int pos)
int size_
The size of the packed representation.
AlpsEncoded & readRep(std::vector< T > &vec)
Read a std::vector from repsentation_ .