memgraph/query_engine/traverser/node_traverser.hpp

60 lines
1.3 KiB
C++
Raw Normal View History

#pragma once
2015-10-28 03:21:28 +08:00
2015-11-02 06:28:08 +08:00
#include <iostream>
#include <typeinfo>
#include <map>
2015-11-02 06:28:08 +08:00
2015-10-28 03:21:28 +08:00
#include "cypher/visitor/traverser.hpp"
2015-10-30 08:24:01 +08:00
using std::cout;
using std::endl;
class NodeTraverser : public Traverser
2015-10-28 03:21:28 +08:00
{
struct PropertiesTraverser : public Traverser
2015-10-28 03:21:28 +08:00
{
PropertiesTraverser(NodeTraverser* node_traverser)
: node_traverser(node_traverser) {}
// friend NodeTraverser;
2015-11-02 06:28:08 +08:00
void visit(ast::Property& property) override
{
name = property.idn->name;
Traverser::visit(property);
json[name] = value;
2015-10-30 08:24:01 +08:00
}
2015-11-02 06:28:08 +08:00
void visit(ast::String& string) override
2015-10-30 08:24:01 +08:00
{
2015-11-02 06:28:08 +08:00
value = string.value;
}
2015-10-30 08:24:01 +08:00
void visit(ast::Integer& integer) override
{
value = std::to_string(integer.value);
}
2015-11-02 06:28:08 +08:00
void visit(ast::Node& node) override
{
2015-10-30 08:24:01 +08:00
Traverser::visit(node);
node_traverser->json = json;
2015-10-28 03:21:28 +08:00
}
2015-11-02 06:28:08 +08:00
private:
std::string name;
std::string value;
std::map<std::string, std::string> json;
NodeTraverser* node_traverser;
2015-10-28 03:21:28 +08:00
};
public:
// TODO: replace with generic value
std::map<std::string, std::string> json;
2015-10-28 03:21:28 +08:00
2015-10-30 08:24:01 +08:00
void visit(ast::Create& create) override
2015-10-28 03:21:28 +08:00
{
auto create_nodes = PropertiesTraverser(this);
create.accept(create_nodes);
2015-10-28 03:21:28 +08:00
};
};