2015-08-30 07:12:46 +08:00
|
|
|
#ifndef MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTIES_HPP
|
|
|
|
#define MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTIES_HPP
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "property.hpp"
|
|
|
|
|
2015-08-31 03:23:48 +08:00
|
|
|
namespace props
|
|
|
|
{
|
|
|
|
|
2015-08-30 07:12:46 +08:00
|
|
|
class Properties
|
|
|
|
{
|
|
|
|
using props_t = std::map<std::string, Property::sptr>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
props_t::iterator find(const std::string& key)
|
|
|
|
{
|
|
|
|
return props.find(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
Property* at(const std::string& key)
|
|
|
|
{
|
2015-08-31 03:23:48 +08:00
|
|
|
auto it = props.find(key);
|
|
|
|
return it == props.end() ? nullptr : it->second.get();
|
2015-08-30 07:12:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void put(const std::string& key, Property::sptr value)
|
|
|
|
{
|
|
|
|
props[key] = std::move(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear(const std::string& key)
|
|
|
|
{
|
|
|
|
props.erase(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump(std::string& buffer)
|
|
|
|
{
|
|
|
|
buffer += '{';
|
|
|
|
|
|
|
|
for(auto& kvp : props)
|
|
|
|
{
|
|
|
|
buffer += '"'; buffer += kvp.first; buffer += "\":";
|
|
|
|
kvp.second->dump(buffer); buffer += ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.pop_back(); // erase last comma
|
|
|
|
buffer += '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
props_t props;
|
|
|
|
};
|
|
|
|
|
2015-08-31 03:23:48 +08:00
|
|
|
}
|
|
|
|
|
2015-08-30 07:12:46 +08:00
|
|
|
#endif
|