Add datastore support for bits

Change-Id: I9a1619f6b892bbde71e75376e9a3a84911236b5d
diff --git a/src/sysrepo_access.cpp b/src/sysrepo_access.cpp
index e792ed8..205db3a 100644
--- a/src/sysrepo_access.cpp
+++ b/src/sysrepo_access.cpp
@@ -6,9 +6,11 @@
  *
 */
 
+#include <experimental/iterator>
 #include <libyang/Tree_Data.hpp>
 #include <libyang/Tree_Schema.hpp>
 #include <sysrepo-cpp/Session.hpp>
+#include <sstream>
 #include "libyang_utils.hpp"
 #include "sysrepo_access.hpp"
 #include "utils.hpp"
@@ -57,6 +59,18 @@
         return special_{SpecialValue::PresenceContainer};
     case SR_LIST_T:
         return special_{SpecialValue::List};
+    case SR_BITS_T:
+    {
+        bits_ res;
+        std::istringstream ss(value->data()->get_bits());
+        while (!ss.eof()) {
+            std::string bit;
+            ss >> bit;
+            res.m_bits.insert(bit);
+        }
+        return res;
+
+    }
     default: // TODO: implement all types
         return value->val_to_string();
     }
@@ -94,6 +108,13 @@
         return std::make_shared<sysrepo::Val>(value.c_str());
     }
 
+    sysrepo::S_Val operator()(const bits_& value) const
+    {
+        std::stringstream ss;
+        std::copy(value.m_bits.begin(), value.m_bits.end(), std::experimental::make_ostream_joiner(ss, " "));
+        return std::make_shared<sysrepo::Val>(ss.str().c_str(), SR_BITS_T);
+    }
+
     template <typename T>
     sysrepo::S_Val operator()(const T& value) const
     {
@@ -144,6 +165,13 @@
         }
     }
 
+    auto operator()(const bits_& value) const
+    {
+        std::stringstream ss;
+        std::copy(value.m_bits.begin(), value.m_bits.end(), std::experimental::make_ostream_joiner(ss, " "));
+        v->set(xpath.c_str(), ss.str().c_str(), SR_BITS_T);
+    }
+
     void operator()(const std::string& value) const
     {
         v->set(xpath.c_str(), value.c_str(), SR_STRING_T);