Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cargo-sqlite.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Pawel Kubik (p.kubik@samsung.com)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
26 #ifndef CARGO_SQLITE_CARGO_SQLITE_HPP
27 #define CARGO_SQLITE_CARGO_SQLITE_HPP
28 
32 
33 namespace cargo {
34 
44 template <class Cargo>
45 void loadFromKVStore(const std::string& filename, Cargo& visitable, const std::string& visitableName)
46 {
47  static_assert(isVisitable<Cargo>::value, "Use CARGO_REGISTER macro");
48 
49  KVStore store(filename);
50  KVStore::Transaction transaction(store);
51  FromKVStoreVisitor visitor(store, visitableName);
52  visitable.accept(visitor);
53  transaction.commit();
54 }
55 
63 template <class Cargo>
64 void saveToKVStore(const std::string& filename, const Cargo& visitable, const std::string& visitableName)
65 {
66  static_assert(isVisitable<Cargo>::value, "Use CARGO_REGISTER macro");
67 
68  KVStore store(filename);
69  KVStore::Transaction transaction(store);
70  ToKVStoreVisitor visitor(store, visitableName);
71  visitable.accept(visitor);
72  transaction.commit();
73 }
74 
75 } // namespace cargo
76 
79 #endif // CARGO_SQLITE_CARGO_SQLITE_HPP
void saveToKVStore(const std::string &filename, const Cargo &visitable, const std::string &visitableName)
Saves the visitable to a KVStore.
Definition: cargo-sqlite.hpp:64
A guard struct for thread synchronization and transaction management.
Definition: kvstore.hpp:49
Definition: to-kvstore-visitor.hpp:39
Definition: kvstore.hpp:43
Visitor for saving to KVStore.
Visitor for loading from KVStore that doesn't fail on missing values.
Default KVStore visitor.
Definition: from-kvstore-visitor.hpp:36
void loadFromKVStore(const std::string &filename, Cargo &visitable, const std::string &visitableName)
Loads a visitable structure from KVStore.
Definition: cargo-sqlite.hpp:45
Default visitor for loading from KVStore.
Helper for compile-time checking against existance of template method 'accept'.
Definition: is-visitable.hpp:49
void commit()
Definition: kvstore.cpp:126