Structs serialization to KVStore finished 39/27039/1
authorPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Wed, 3 Sep 2014 12:14:05 +0000 (14:14 +0200)
committerPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Wed, 3 Sep 2014 12:26:46 +0000 (14:26 +0200)
[Bug/Feature]   Missing serialization/deserialization of vector of
                structs.
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run tests

Change-Id: I562bb89550b4af5ce86c3f818738cb878830f828

src/config/from-kvstore-visitor.hpp
src/config/to-kvstore-visitor.hpp

index 25c4182..40ecaaa 100644 (file)
@@ -76,6 +76,21 @@ private:
         FromKVStoreVisitor visitor(*this, name);
         value.accept(visitor);
     }
+
+    template<typename T>
+    void getInternal(const std::string& name, std::vector<T>& values)
+    {
+        values.clear();
+        for (unsigned int i = 0;; ++i) {
+            const std::string k = key(name, std::to_string(i));
+            if (mStorePtr->count(k) == 0) {
+                return;
+            }
+            T value;
+            getInternal(k, value);
+            values.push_back(value);
+        }
+    }
 };
 
 } // namespace config
index dcb7d8c..8da093b 100644 (file)
@@ -77,6 +77,15 @@ private:
         ToKVStoreVisitor visitor(*this, name);
         value.accept(visitor);
     }
+
+    template<typename T>
+    void setInternal(const std::string& name, const std::vector<T>& values)
+    {
+        mStorePtr->remove(name);
+        for (size_t i = 0; i < values.size(); ++i) {
+            setInternal(key(name, std::to_string(i)), values[i]);
+        }
+    }
 };
 
 } // namespace config