Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2011-10-21 16:26:04 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:26:24 +0300
commit485c280e20b0ab5459ab6af48574feab9940483d (patch)
tree16425028a35c33387df4b44e2baadfa0938d895d /coding/read_write_utils.hpp
parent6fb963c435eeaf1bdc56fd12dca348d79c18cd04 (diff)
Add read write functions for some std containers.
Diffstat (limited to 'coding/read_write_utils.hpp')
-rw-r--r--coding/read_write_utils.hpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/coding/read_write_utils.hpp b/coding/read_write_utils.hpp
new file mode 100644
index 0000000000..fb961834f2
--- /dev/null
+++ b/coding/read_write_utils.hpp
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "varint.hpp"
+
+#include "../std/string.hpp"
+#include "../std/vector.hpp"
+
+
+namespace rw
+{
+ template <class TSink>
+ void Write(TSink & sink, string const & s)
+ {
+ uint32_t const count = static_cast<uint32_t>(s.size());
+ WriteVarUint(sink, count);
+ if (!s.empty())
+ sink.Write(&s[0], count);
+ }
+
+ template <class TSource>
+ void Read(TSource & src, string & s)
+ {
+ uint32_t const count = ReadVarUint<uint32_t>(src);
+ s.resize(count);
+ if (count > 0)
+ src.Read(&s[0], count);
+ }
+
+ template <class TSink, class T>
+ void Write(TSink & sink, vector<T> const & v)
+ {
+ uint32_t const count = static_cast<uint32_t>(v.size());
+ WriteVarUint(sink, count);
+ for (uint32_t i = 0; i < count; ++i)
+ Write(sink, v[i]);
+ }
+
+ template <class TSource, class T>
+ void Read(TSource & src, vector<T> & v)
+ {
+ uint32_t const count = ReadVarUint<uint32_t>(src);
+ v.resize(count);
+ for (size_t i = 0; i < count; ++i)
+ Read(src, v[i]);
+ }
+}