Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
kvstore-visitor-utils.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 
25 #ifndef CARGO_SQLITE_KVSTORE_VISITOR_UTILS_HPP
26 #define CARGO_SQLITE_KVSTORE_VISITOR_UTILS_HPP
27 
28 #include <vector>
29 #include <string>
30 #include <sstream>
31 
32 namespace cargo {
33 
34 template<typename T>
35 T fromString(const std::string& strValue)
36 {
37  std::istringstream iss(strValue);
38  T value;
39  iss >> value;
40  return value;
41 }
42 
43 template<typename T>
44 std::string toString(const T& value)
45 {
46  std::ostringstream oss;
47  oss << value;
48  return oss.str();
49 }
50 
59 template<char delim = '.', typename Arg1, typename ... Args>
60 std::string key(const Arg1& a1, const Args& ... args)
61 {
62  std::string ret = toString(a1);
63  std::initializer_list<std::string> strings {toString(args)...};
64  for (const std::string& s : strings) {
65  ret += delim + s;
66  }
67 
68  return ret;
69 }
70 
77 template<char delim = '.'>
78 std::string key()
79 {
80  return std::string();
81 }
82 
83 } // namespace cargo
84 
85 #endif // CARGO_SQLITE_KVSTORE_VISITOR_UTILS_HPP
T fromString(const std::string &strValue)
Definition: kvstore-visitor-utils.hpp:35
std::string toString(const T &value)
Definition: kvstore-visitor-utils.hpp:44
std::vector< std::string > Args
Definition: command-line-interface.hpp:41
std::string key(const Arg1 &a1, const Args &...args)
Concatenates all parameters into one std::string.
Definition: kvstore-visitor-utils.hpp:60