namespace simgrid {
namespace surf {
-PropertyHolder::~PropertyHolder() {
- delete properties_;
-}
-
/** @brief Return the property associated to the provided key (or nullptr if not existing) */
const char* PropertyHolder::get_property(const std::string& key) const
{
- if (properties_ == nullptr)
+ if (not properties_)
return nullptr;
auto prop = properties_->find(key);
return prop == properties_->end() ? nullptr : prop->second.c_str();
void PropertyHolder::set_property(const std::string& key, const std::string& value)
{
if (not properties_)
- properties_ = new std::unordered_map<std::string, std::string>;
+ properties_.reset(new std::unordered_map<std::string, std::string>);
(*properties_)[key] = value;
}
std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
{
if (not properties_)
- properties_ = new std::unordered_map<std::string, std::string>;
- return properties_;
+ properties_.reset(new std::unordered_map<std::string, std::string>);
+ return properties_.get();
}
} /* namespace surf */
#ifndef SRC_SURF_PROPERTYHOLDER_HPP_
#define SRC_SURF_PROPERTYHOLDER_HPP_
+
+#include <memory>
#include <string>
#include <unordered_map>
PropertyHolder() = default;
PropertyHolder(const PropertyHolder&) = delete;
PropertyHolder& operator=(const PropertyHolder&) = delete;
- ~PropertyHolder();
const char* get_property(const std::string& key) const;
void set_property(const std::string& id, const std::string& value);
std::unordered_map<std::string, std::string>* get_properties();
private:
- std::unordered_map<std::string, std::string>* properties_ = nullptr;
+ std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
};
} /* namespace surf */