Transaction and synchronization guard
[archive/platform/core/system/libConfig.git] / src / config / from-kvstore-visitor.hpp
index 0c91eb5..c7e3540 100644 (file)
@@ -38,13 +38,15 @@ class FromKVStoreVisitor {
 public:
     explicit FromKVStoreVisitor(const std::string& filePath, const std::string& prefix)
         : mStorePtr(new KVStore(filePath)),
-          mKeyPrefix(prefix)
+          mKeyPrefix(prefix),
+          mTransaction(mStorePtr->getTransaction())
     {
     }
 
     FromKVStoreVisitor(const FromKVStoreVisitor& visitor, const std::string& prefix)
         : mStorePtr(visitor.mStorePtr),
-          mKeyPrefix(prefix)
+          mKeyPrefix(prefix),
+          mTransaction(visitor.mTransaction)
     {
     }
 
@@ -63,6 +65,7 @@ public:
 private:
     std::shared_ptr<KVStore> mStorePtr;
     std::string mKeyPrefix;
+    KVStore::Transaction mTransaction;
 
     template<typename T, typename std::enable_if<!isVisitable<T>::value, int>::type = 0>
     void getInternal(const std::string& name, T& value)
@@ -81,6 +84,7 @@ private:
     void getInternal(const std::string& name, std::vector<T>& values)
     {
         values.clear();
+
         size_t vectorSize = mStorePtr->get<size_t>(name);
         if (vectorSize == 0) {
             return;