memgraph/storage/model/properties/properties.hpp

58 lines
1.0 KiB
C++
Raw Normal View History

#ifndef MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTIES_HPP
#define MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTIES_HPP
#include <map>
#include "property.hpp"
namespace model
2015-08-31 03:23:48 +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();
}
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
}
#endif