From d05fece2e608679268390fcf8f706e1187e47cc7 Mon Sep 17 00:00:00 2001 From: Felipe Garay Date: Thu, 21 Dec 2023 10:08:19 -0800 Subject: [PATCH] odb: Adding support to serialize and de-serialize std::unordered_map This is based on the already existing case for std::map Signed-off-by: Felipe Garay --- src/odb/include/odb/dbStream.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/odb/include/odb/dbStream.h b/src/odb/include/odb/dbStream.h index 0599a46354e..c14a6517838 100644 --- a/src/odb/include/odb/dbStream.h +++ b/src/odb/include/odb/dbStream.h @@ -38,6 +38,7 @@ #include #include #include +#include #include "ZException.h" #include "dbObject.h" @@ -192,6 +193,18 @@ class dbOStream return *this; } + template + dbOStream& operator<<(const std::unordered_map& m) + { + uint sz = m.size(); + *this << sz; + for (auto const& [key, val] : m) { + *this << key; + *this << val; + } + return *this; + } + template dbOStream& operator<<(const std::array& a) { @@ -342,6 +355,20 @@ class dbIStream } return *this; } + template + dbIStream& operator>>(std::unordered_map& m) + { + uint sz; + *this >> sz; + for (uint i = 0; i < sz; i++) { + T1 key; + T2 val; + *this >> key; + *this >> val; + m[key] = val; + } + return *this; + } template dbIStream& operator>>(std::array& a) {