2016-12-14 17:27:41 +08:00
|
|
|
#pragma once
|
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
2016-12-14 17:27:41 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-03-01 02:38:57 +08:00
|
|
|
#include "query/backend/cpp/typed_value.hpp"
|
2017-02-23 21:19:52 +08:00
|
|
|
#include "storage/edge_accessor.hpp"
|
|
|
|
#include "storage/vertex_accessor.hpp"
|
|
|
|
|
|
|
|
void write_properties(std::ostream &os, const GraphDbAccessor &access,
|
2017-03-29 18:37:58 +08:00
|
|
|
const PropertyValueStore<GraphDbTypes::Property> &properties) {
|
2017-02-23 21:19:52 +08:00
|
|
|
if (properties.size() > 0) {
|
|
|
|
os << "{";
|
|
|
|
for (auto x : properties) {
|
|
|
|
os << access.property_name(x.first) << ": " << x.second << ",";
|
|
|
|
}
|
|
|
|
os << "}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const VertexAccessor &vertex) {
|
|
|
|
if (vertex.labels().size() > 0) {
|
2017-03-29 18:37:58 +08:00
|
|
|
for (GraphDbTypes::Label label : vertex.labels()) {
|
2017-02-23 21:19:52 +08:00
|
|
|
os << vertex.db_accessor().property_name(label) << ", ";
|
|
|
|
}
|
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
write_properties(os, vertex.db_accessor(), vertex.Properties());
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const EdgeAccessor &edge) {
|
|
|
|
os << "Edge: " << edge.db_accessor().edge_type_name(edge.edge_type()) << "\n";
|
|
|
|
write_properties(os, edge.db_accessor(), edge.Properties());
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:10:16 +08:00
|
|
|
class PrintRecordStream {
|
2017-02-18 18:54:37 +08:00
|
|
|
private:
|
2017-02-15 21:10:16 +08:00
|
|
|
std::ostream &stream;
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
public:
|
2017-02-15 21:10:16 +08:00
|
|
|
PrintRecordStream(std::ostream &stream) : stream(stream) {}
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-03-22 23:36:48 +08:00
|
|
|
// TODO: all these functions should pretty print their data
|
|
|
|
void Header(const std::vector<std::string> &fields) {
|
|
|
|
stream << "Header\n";
|
2017-02-15 21:10:16 +08:00
|
|
|
}
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-03-22 23:36:48 +08:00
|
|
|
void Result(std::vector<TypedValue> &values) {
|
|
|
|
stream << "Result\n";
|
2017-02-15 21:10:16 +08:00
|
|
|
}
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-03-22 23:36:48 +08:00
|
|
|
void Summary(const std::map<std::string, TypedValue> &summary) {
|
|
|
|
stream << "Summary\n";
|
2017-02-15 21:10:16 +08:00
|
|
|
}
|
2016-12-14 17:27:41 +08:00
|
|
|
};
|