00001 #ifndef TRIGSTEERINGEVENT_STRINGSERIALIZER_H
00002 #define TRIGSTEERINGEVENT_STRINGSERIALIZER_H
00003 #include <iostream>
00004 #include <sstream>
00005 #include <vector>
00006 #include <cstdlib>
00007 #include <iterator>
00008 #include <stdint.h>
00009
00010
00011 namespace TrigSteeringEvent {
00012
00013
00019 class StringSerializer {
00020
00021 public:
00032 void serialize (const std::vector<std::string>& strings, std::vector<uint32_t>& storage );
00033 void serialize (const std::string& str, std::vector<uint32_t>& storage );
00034
00044 std::size_t deserialize (std::vector<uint32_t>::const_iterator first,
00045 std::vector<uint32_t>::const_iterator last,
00046 std::vector<std::string>& strings);
00047
00049 std::size_t deserialize (const std::vector<uint32_t>& storage, std::vector<std::string>& strings ) {
00050 return deserialize(storage.begin(), storage.end(), strings);
00051 }
00052
00054 std::size_t deserialize (std::vector<uint32_t>::const_iterator first,
00055 std::vector<uint32_t>::const_iterator last,
00056 std::string& str);
00057
00059 std::size_t deserialize (const std::vector<uint32_t>& storage, std::string& str ) {
00060 return deserialize(storage.begin(), storage.end(), str);
00061 }
00062
00066 unsigned int inquireSize(const std::vector<uint32_t>& storage);
00067
00068 private:
00069
00073 unsigned int getPadding(unsigned int sizeToReserve) {
00074 return (sizeof(uint32_t) - sizeToReserve%sizeof(uint32_t)) % sizeof(uint32_t);
00075 }
00076
00077 std::ostringstream m_ostream;
00078 std::istringstream m_istream;
00079 static const char* s_delimiter;
00080 };
00081
00082
00083 }
00084
00085
00086 #endif // TRIGSTEERINGEVENT_STRINGSERIALIZER_H