28 #include <boost/serialization/nvp.hpp>
29 #include <boost/serialization/shared_ptr.hpp>
30 #include <boost/serialization/unordered_map.hpp>
39 std::unique_lock lhs_lock(
mutex_, std::defer_lock);
40 std::shared_lock rhs_lock(other.
mutex_, std::defer_lock);
41 std::scoped_lock lock{ lhs_lock, rhs_lock };
49 std::unique_lock lhs_lock(
mutex_, std::defer_lock);
50 std::shared_lock rhs_lock(other.
mutex_, std::defer_lock);
51 std::scoped_lock lock{ lhs_lock, rhs_lock };
60 std::unique_lock lhs_lock(mutex_, std::defer_lock);
61 std::unique_lock rhs_lock(other.mutex_, std::defer_lock);
62 std::scoped_lock lock{ lhs_lock, rhs_lock };
64 profiles_ = std::move(other.profiles_);
70 std::unique_lock lhs_lock(mutex_, std::defer_lock);
71 std::unique_lock rhs_lock(other.mutex_, std::defer_lock);
72 std::scoped_lock lock{ lhs_lock, rhs_lock };
74 profiles_ = std::move(other.profiles_);
80 const std::shared_lock lock(
mutex_);
85 return (it->second.find(key) != it->second.end());
90 const std::unique_lock lock(
mutex_);
96 it->second.erase(key);
97 if (it->second.empty())
102 const std::string& ns)
const
104 const std::shared_lock lock(
mutex_);
107 throw std::runtime_error(
"Profile namespace does not exist for '" + ns +
"'!");
109 auto it2 = it->second.find(key);
110 if (it2 != it->second.end())
113 throw std::runtime_error(
"Profile entry does not exist for type name '" + std::to_string(key) +
"' in namespace '" +
117 std::unordered_map<std::string, std::unordered_map<std::size_t, std::unordered_map<std::string, Profile::ConstPtr>>>
120 const std::shared_lock lock(
mutex_);
125 const std::string& profile_name,
129 throw std::runtime_error(
"Adding profile with an empty namespace!");
131 if (profile_name.empty())
132 throw std::runtime_error(
"Adding profile with an empty string as the key!");
134 if (profile ==
nullptr)
135 throw std::runtime_error(
"Adding profile that is a nullptr");
137 const std::unique_lock lock(
mutex_);
141 std::unordered_map<std::string, Profile::ConstPtr> new_entry;
142 new_entry[profile_name] = profile;
143 profiles_[ns][profile->getKey()] = new_entry;
147 auto it2 = it->second.find(profile->getKey());
148 if (it2 != it->second.end())
150 it2->second[profile_name] = profile;
154 std::unordered_map<std::string, Profile::ConstPtr> new_entry;
155 new_entry[profile_name] = profile;
156 it->second[profile->getKey()] = new_entry;
162 const std::vector<std::string>& profile_names,
166 throw std::runtime_error(
"Adding profile with an empty namespace!");
168 if (profile_names.empty())
169 throw std::runtime_error(
"Adding profile with an empty vector of keys!");
171 if (profile ==
nullptr)
172 throw std::runtime_error(
"Adding profile that is a nullptr");
174 const std::unique_lock lock(
mutex_);
178 std::unordered_map<std::string, Profile::ConstPtr> new_entry;
179 for (
const auto& profile_name : profile_names)
181 if (profile_name.empty())
182 throw std::runtime_error(
"Adding profile with an empty string as the key!");
184 new_entry[profile_name] = profile;
186 profiles_[ns][profile->getKey()] = new_entry;
190 auto it2 = it->second.find(profile->getKey());
191 if (it2 != it->second.end())
193 for (
const auto& profile_name : profile_names)
195 if (profile_name.empty())
196 throw std::runtime_error(
"Adding profile with an empty string as the key!");
198 it2->second[profile_name] = profile;
203 std::unordered_map<std::string, Profile::ConstPtr> new_entry;
204 for (
const auto& profile_name : profile_names)
206 if (profile_name.empty())
207 throw std::runtime_error(
"Adding profile with an empty string as the key!");
209 new_entry[profile_name] = profile;
211 it->second[profile->getKey()] = new_entry;
218 const std::shared_lock lock(
mutex_);
223 auto it2 = it->second.find(key);
224 if (it2 != it->second.end())
226 auto it3 = it2->second.find(profile_name);
227 if (it3 != it2->second.end())
234 const std::string& ns,
235 const std::string& profile_name)
const
237 const std::shared_lock lock(
mutex_);
238 return profiles_.at(ns).at(key).at(profile_name);
243 const std::unique_lock lock(
mutex_);
248 auto it2 = it->second.find(key);
249 if (it2 != it->second.end())
251 it2->second.erase(profile_name);
252 if (it2->second.empty())
254 it->second.erase(it2);
255 if (it->second.empty())
263 const std::unique_lock lock(
mutex_);
267 template <
class Archive>
270 const std::shared_lock lock(
mutex_);
271 ar& boost::serialization::make_nvp(
"profiles",
profiles_);