diff options
author | Philip Rauwolf <rauwolf@itestra.de> | 2013-02-22 14:35:58 +0100 |
---|---|---|
committer | Philip Rauwolf <rauwolf@itestra.de> | 2013-02-22 14:35:58 +0100 |
commit | c42776d96335c0f5f380731211d47562a88e215b (patch) | |
tree | d2dec08554f35e5368acf2ca31ea092c8d140de5 | |
parent | 3cf55e3fe9a1dc5914b623d6bfcd396ec637bd86 (diff) | |
download | genivi-common-api-runtime-c42776d96335c0f5f380731211d47562a88e215b.tar.gz |
InputStream and OutputStream now have a way to recognize beginning/end
of each entry in a map
-rw-r--r-- | src/CommonAPI/InputStream.h | 4 | ||||
-rw-r--r-- | src/CommonAPI/OutputStream.h | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/CommonAPI/InputStream.h b/src/CommonAPI/InputStream.h index 82da755..302023d 100644 --- a/src/CommonAPI/InputStream.h +++ b/src/CommonAPI/InputStream.h @@ -100,6 +100,8 @@ class InputStream { virtual void beginReadMap() = 0; virtual bool hasMoreMapElements() = 0; virtual void endReadMap() = 0; + virtual void beginReadMapElement() = 0; + virtual void endReadMapElement() = 0; }; template <typename _EnumBackingType, typename _EnumType> @@ -312,7 +314,9 @@ InputStream& operator>>(InputStream& inputStream, std::unordered_map<_KeyType, _ _KeyType elementKey; _ValueType elementValue; + inputStream.beginReadMapElement(); inputStream >> elementKey >> elementValue; + inputStream.endReadMapElement(); if (inputStream.hasError()) break; diff --git a/src/CommonAPI/OutputStream.h b/src/CommonAPI/OutputStream.h index 16bbcc7..fccb31c 100644 --- a/src/CommonAPI/OutputStream.h +++ b/src/CommonAPI/OutputStream.h @@ -11,6 +11,8 @@ #include "SerializableStruct.h" #include "SerializableVariant.h" #include "types.h" +#include <unistd.h> +#include <iostream> #include <cstdint> #include <functional> @@ -314,6 +316,8 @@ class OutputStream { virtual void beginWriteMap(size_t elementCount) = 0; virtual void endWriteMap() = 0; + virtual void beginWriteMapElement() = 0; + virtual void endWriteMapElement() = 0; }; @@ -518,14 +522,14 @@ OutputStream& operator<<(OutputStream& outputStream, const std::unordered_map<_K typedef typename std::unordered_map<_KeyType, _ValueType>::const_iterator MapConstIterator; const size_t elementCount = mapValue.size(); - outputStream.beginWriteMap(elementCount); for (MapConstIterator iter = mapValue.cbegin(); iter != mapValue.cend(); iter++) { + outputStream.beginWriteMapElement(); outputStream << iter->first << iter->second; - if (outputStream.hasError()) return outputStream; + outputStream.endWriteMapElement(); } outputStream.endWriteMap(); |