18 unsigned int getPadding(
unsigned int sizeToReserve) {
31 void serialize (
const std::vector<std::string>& strings, std::vector<uint32_t>& storage ) {
32 std::ostringstream ostream;
36 copy(strings.begin(), strings.end(), std::ostream_iterator<std::string>(ostream,
delimiter));
38 unsigned sizeToReserve = ostream.str().size();
41 unsigned int sizeToPad = getPadding(sizeToReserve);
43 if ( sizeToPad != 0 ) {
44 sizeToReserve += sizeToPad;
45 for (
unsigned i = 0 ;
i < sizeToPad;
i++ )
50 char * carray =
new char [sizeToReserve];
51 strncpy(carray, ostream.str().c_str(), sizeToReserve);
54 storage.push_back(strings.size());
55 storage.insert(storage.end(), &uarray[0], &uarray[sizeToReserve/
sizeof(
uint32_t)]);
60 void serialize (
const std::string&
str, std::vector<uint32_t>& storage ) {
61 std::vector<std::string>
tmp(1,
str);
67 std::vector<uint32_t>::const_iterator last,
68 std::vector<std::string>& strings)
72 if ( storageSize <= 1 )
return storageSize;
73 unsigned int numOfStrings = *
first;
77 std::vector<uint32_t>::const_iterator itBegin =
first;
79 copy(itBegin, last, &uarray[0]);
81 const char * carray = (
const char*)uarray;
82 std::string whole(carray, (storageSize-1)*
sizeof(
uint32_t));
83 std::istringstream istream;
89 unsigned int readInStrings=0;
92 while ( istream.good() && readInStrings < numOfStrings ) {
94 strings.push_back(
one);
96 nChars +=
one.size() + 1;
100 return 1 + (nChars+getPadding(nChars))/
sizeof(
uint32_t);
104 std::vector<uint32_t>::const_iterator last,
107 std::vector<std::string>
tmp;
109 if (
tmp.size() == 1 )