~thomas-voss/location-service/next

« back to all changes in this revision

Viewing changes to src/location/util/settings.h

  • Committer: Thomas Voß
  • Date: 2017-05-12 09:19:03 UTC
  • mfrom: (309.1.1 unify-settings-backend)
  • Revision ID: thomas.voss@canonical.com-20170512091903-1lf20l72y0l7acac
Merge lp:~thomas-voss/location-service/unify-settings-backend.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2017 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3,
 
6
 * as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
 
17
 */
 
18
 
 
19
#ifndef LOCATION_UTIL_SETTINGS_H_
 
20
#define LOCATION_UTIL_SETTINGS_H_
 
21
 
 
22
#include <location/optional.h>
 
23
#include <location/visibility.h>
 
24
 
 
25
#include <boost/property_tree/ptree.hpp>
 
26
 
 
27
#include <sstream>
 
28
#include <string>
 
29
 
 
30
namespace location
 
31
{
 
32
namespace util
 
33
{
 
34
namespace settings
 
35
{
 
36
 
 
37
class LOCATION_DLL_PUBLIC Source
 
38
{
 
39
public:
 
40
    explicit Source(const boost::property_tree::ptree& ptree = boost::property_tree::ptree{});
 
41
 
 
42
    template<typename T>
 
43
    T get_value(const std::string& key, T&& value) const
 
44
    {
 
45
        if (auto v = get(key))
 
46
        {
 
47
            std::istringstream iss{*v};
 
48
            iss >> value;
 
49
        }
 
50
 
 
51
        return value;
 
52
    }
 
53
 
 
54
private:
 
55
    Optional<std::string> get(const std::string& key) const;
 
56
 
 
57
    boost::property_tree::ptree ptree;
 
58
};
 
59
 
 
60
}  // namespace settings
 
61
}  // namespace util
 
62
}  // namespace location
 
63
 
 
64
#endif // LOCATION_UTIL_SETTINGS_H_