1 #ifndef WS_MERGED_PREFERENCES_H_INCLUDED
2 #define WS_MERGED_PREFERENCES_H_INCLUDED
26 #include <type_traits>
27 #include <boost/property_tree/ptree.hpp>
34 class MergedPreferences;
38 const std::shared_ptr<MergedPreferences> source;
54 static std::shared_ptr<MergedPreferences> Create(
const std::shared_ptr<Ws::IWorkspace>&,
55 const std::shared_ptr<Ws::IProject>&);
62 typename std::enable_if<std::is_same<T, std::string>::value, T>::type
63 Get(
const boost::property_tree::ptree::path_type&)
const;
68 typename std::enable_if<!std::is_same<T, std::string>::value, T>::type
69 Get(
const boost::property_tree::ptree::path_type&)
const;
73 typename std::enable_if<std::is_same<T, std::string>::value, T>::type
74 Get(
const boost::property_tree::ptree::path_type&,
const T&)
const;
78 typename std::enable_if<!std::is_same<T, std::string>::value, T>::type
79 Get(
const boost::property_tree::ptree::path_type&,
const T&)
const;
87 void Put(
const boost::property_tree::ptree::path_type&,
const T&);
90 std::shared_ptr<MergedPreferences>
GetChild(
const boost::property_tree::ptree::path_type&)
const;
93 std::shared_ptr<MergedPreferences>
GetGlobal()
const;
96 const std::string&
GetPath()
const;
103 const std::shared_ptr<Ws::IProject>&);
109 boost::property_tree::ptree::path_type m_path;
110 std::shared_ptr<Ws::IWorkspace> m_workspace;
111 std::shared_ptr<Ws::IProject> m_project;
114 template <
typename T>
115 typename std::enable_if<std::is_same<T, std::string>::value, T>::type
118 auto str = m_project->GetPreferences().get<std::string>(m_path / p);
119 if (str ==
"$WORKSPACE$") {
120 return m_workspace->GetPreferences().get<T>(m_path / p);
126 template <
typename T>
127 typename std::enable_if<!std::is_same<T, std::string>::value, T>::type
130 auto str = m_project->GetPreferences().get<std::string>(m_path / p);
131 if (str ==
"$WORKSPACE$") {
132 return m_workspace->GetPreferences().get<T>(m_path / p);
134 return m_project->GetPreferences().get<T>(m_path / p);
138 template <
typename T>
139 typename std::enable_if<std::is_same<T, std::string>::value, T>::type
142 auto str_optional = m_project->GetPreferences().get_optional<std::string>(m_path / p);
144 auto& str = str_optional.get();
145 if (str ==
"$WORKSPACE$") {
146 return m_workspace->GetPreferences().get<T>(m_path / p);
155 template <
typename T>
156 typename std::enable_if<!std::is_same<T, std::string>::value, T>::type
159 auto str_optional = m_project->GetPreferences().get_optional<std::string>(m_path / p);
161 auto& str = str_optional.get();
162 if (str ==
"$WORKSPACE$") {
163 return m_workspace->GetPreferences().get<T>(m_path / p);
165 return m_project->GetPreferences().get<T>(m_path / p);
172 template <
typename T>
175 auto prefs = m_project->GetPreferences();
176 prefs.put<T>(m_path / p, v);
177 m_project->SetPreferences(prefs);
183 #endif // end_of_inclde_guard
Event used to inform some observer that preferences have changed.
const std::string & GetPath() const
Get path of project.
std::shared_ptr< MergedPreferences > GetGlobal() const
Get MergedPreferences instance pointing to global preferences. (undoes GetChild() operations) ...
Wrapper around workspace to have read and write access to merged (workspace + project) preferences...
void Put(const boost::property_tree::ptree::path_type &, const T &)
Put value at given path in project preferences if another value at the same path exists, otherwise, put value in workspace preferences.
Interface/Implementation of Subject.
std::shared_ptr< MergedPreferences > GetChild(const boost::property_tree::ptree::path_type &) const
Get MergedPreferences instance for working with preferences subtree.
Interface for IWorkspace.
const boost::property_tree::ptree & GetProjectPreferencesTree()
Get project preferences.
Subject in Observer pattern.
Namespace for generic graphical shell for simulators.
std::enable_if< std::is_same< T, std::string >::value, T >::type Get(const boost::property_tree::ptree::path_type &) const
see the online C++11 documentation