VPTissue Reference Manual
Preferences.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "Preferences.h"
21 
23 
24 #include <boost/property_tree/xml_parser.hpp>
25 
26 using namespace std;
27 using namespace boost::property_tree;
28 using namespace boost::property_tree::xml_parser;
29 using namespace SimPT_Sim::Util;
30 
31 namespace SimShell {
32 namespace Ws {
33 
34 Preferences::Preferences(const std::string& file)
35  : m_file(file)
36 {
37  ptree p;
38  try {
39  read_xml(m_file, p, trim_whitespace);
40  m_preferences = p.get_child("preferences");
41  }
42  // Ignore errors, if preferences can't be found, leave them empty.
43  catch (xml_parser_error&) {}
44  catch (ptree_bad_path&) {}
45 }
46 
47 Preferences::Preferences(Preferences&& other)
48  : m_preferences(move(other.m_preferences)),
49  m_file(move(other.m_file))
50 {
51 }
52 
53 const ptree& Preferences::GetPreferences() const
54 {
55  return m_preferences;
56 }
57 
58 void Preferences::SetPreferences(const ptree& prefs)
59 {
60  m_preferences = prefs;
61  ptree p;
62  p.put_child("preferences", m_preferences);
63  write_xml(m_file, p, std::locale(), XmlWriterSettings::GetTab());
64  Notify({m_preferences});
65 }
66 
67 } // namespace Ws
68 } // namespace SimShell
STL namespace.
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Interface for Preferences.
Xml writer settings class.
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32