Imported Upstream version 1.2.99~20120606~SE~ff65aef~SYSYNC~2728cb4
[platform/upstream/syncevolution.git] / src / syncevo / ConfigNode.cpp
1 /*
2  * Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
3  * Copyright (C) 2009 Intel Corporation
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) version 3.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301  USA
19  */
20
21 #include <syncevo/IniConfigNode.h>
22 #include <syncevo/SafeConfigNode.h>
23
24 #include <syncevo/declarations.h>
25
26 using namespace std;
27
28 SE_BEGIN_CXX
29
30 boost::shared_ptr<ConfigNode> ConfigNode::createFileNode(const string &filename)
31 {
32     string::size_type off = filename.rfind('/');
33     boost::shared_ptr<ConfigNode> filenode;
34     if (off != filename.npos) {
35         filenode.reset(new IniFileConfigNode(filename.substr(0, off),
36                                              filename.substr(off + 1),
37                                              false));
38     } else {
39         filenode.reset(new IniFileConfigNode(".", filename, false));
40     }
41     boost::shared_ptr<SafeConfigNode> savenode(new SafeConfigNode(filenode));
42     savenode->setMode(false);
43     return savenode;
44 }
45
46 void ConfigNode::writeProperties(const ConfigProps &props)
47 {
48     BOOST_FOREACH(const ConfigProps::value_type &entry, props) {
49         setProperty(entry.first, entry.second);
50     }
51 }
52
53 SE_END_CXX