VPTissue Reference Manual
MergedPreferences.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 "MergedPreferences.h"
21 
22 using namespace std;
23 using namespace boost::property_tree;
24 
25 namespace SimShell {
26 namespace Ws {
27 
28 shared_ptr<MergedPreferences> MergedPreferences::Create(const shared_ptr<Ws::IWorkspace>& w,
29  const shared_ptr<Ws::IProject>& p)
30 {
31  auto result = shared_ptr<MergedPreferences>(new MergedPreferences(w,p));
32  w->Subject<Ws::Event::PreferencesChanged, std::weak_ptr<const void>>::Register(
33  result, bind(&MergedPreferences::ListenPreferencesChanged, result.get(), _1));
34  p->Subject<Ws::Event::PreferencesChanged, std::weak_ptr<const void>>::Register(
35  result, bind(&MergedPreferences::ListenPreferencesChanged, result.get(), _1));
36 
37  return result;
38 }
39 
40 MergedPreferences::MergedPreferences(const shared_ptr<Ws::IWorkspace>& w,
41  const shared_ptr<Ws::IProject>& p)
42  : m_path(), m_workspace(w), m_project(p)
43 {
44 }
45 
46 MergedPreferences::MergedPreferences(const boost::property_tree::ptree::path_type& p, const MergedPreferences& other)
47  : m_path(p), m_workspace(other.m_workspace), m_project(other.m_project)
48 {
49 }
50 
51 MergedPreferences::~MergedPreferences()
52 {
53 }
54 
55 shared_ptr<MergedPreferences> MergedPreferences::GetChild(const boost::property_tree::ptree::path_type& p) const
56 {
57  auto result = shared_ptr<MergedPreferences>(new MergedPreferences(m_path / p, *this));
58 
59  m_workspace->Subject<Ws::Event::PreferencesChanged, std::weak_ptr<const void>>::Register(
60  result, bind(&MergedPreferences::ListenPreferencesChanged, result.get(), _1));
61  m_project->Subject<Ws::Event::PreferencesChanged, std::weak_ptr<const void>>::Register(
62  result, bind(&MergedPreferences::ListenPreferencesChanged, result.get(), _1));
63 
64  return result;
65 }
66 
67 shared_ptr<MergedPreferences> MergedPreferences::GetGlobal() const
68 {
69  boost::property_tree::ptree::path_type empty_path;
70  auto result = shared_ptr<MergedPreferences>(new MergedPreferences(empty_path, *this));
71 
72  m_workspace->Subject<Ws::Event::PreferencesChanged, std::weak_ptr<const void>>::Register(
73  result, bind(&MergedPreferences::ListenPreferencesChanged, result.get(), _1));
74  m_project->Subject<Ws::Event::PreferencesChanged, std::weak_ptr<const void>>::Register(
75  result, bind(&MergedPreferences::ListenPreferencesChanged, result.get(), _1));
76 
77  return result;
78 }
79 
80 const std::string& MergedPreferences::GetPath() const
81 {
82  return m_project->GetPath();
83 }
84 
85 const boost::property_tree::ptree& MergedPreferences::GetProjectPreferencesTree()
86 {
87 
88  return m_project->GetPreferences();
89 
90 }
91 
92 void MergedPreferences::ListenPreferencesChanged(const Ws::Event::PreferencesChanged&)
93 {
94  Notify({shared_from_this()});
95 }
96 
97 } // namespace Ws
98 } // namespace SimShell
Event used to inform some observer that preferences have changed.
STL namespace.
Wrapper around workspace to have read and write access to merged (workspace + project) preferences...
Interface for MergedPreferences.
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32