1
0
Fork 0

Merge branch 'aql2' of https://github.com/triAGENS/ArangoDB into aql2

This commit is contained in:
Jan Steemann 2014-07-24 14:00:19 +02:00
commit 1b5c1118bd
2 changed files with 105 additions and 4 deletions

View File

@ -27,6 +27,8 @@
#include "Aql/ExecutionPlan.h"
#include <Basics/JsonHelper.h>
using namespace triagens::aql;
// -----------------------------------------------------------------------------
@ -38,12 +40,95 @@ using namespace triagens::aql;
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* ExecutionPlan::toJson (TRI_memory_zone_t* zone) {
TRI_json_t* json = TRI_CreateArray2Json(zone, 1);
TRI_json_t* sub = TRI_CreateStringCopyJson(zone, "ILLEGAL");
TRI_Insert2ArrayJson(zone, json, "type", sub);
TRI_json_t* json = TRI_CreateArray2Json(zone, 2);
if (nullptr == json) {
return nullptr;
}
std::string type = getTypeString();
TRI_json_t* sub = TRI_CreateString2CopyJson(zone, type.c_str(), type.size());
if (nullptr == sub) {
TRI_FreeJson(zone, json);
return nullptr;
}
TRI_Insert3ArrayJson(zone, json, "type", sub);
if (_dependencies.size() != 0) {
sub = TRI_CreateList2Json(zone, _dependencies.size());
if (nullptr == sub) {
TRI_FreeJson(zone, json);
return nullptr;
}
for (size_t i = 0; i < _dependencies.size(); i++) {
TRI_json_t* subsub = _dependencies[i]->toJson(zone);
if (subsub == nullptr) {
TRI_FreeJson(zone, json);
return nullptr;
}
TRI_PushBack3ListJson(zone, sub, subsub);
}
TRI_Insert3ArrayJson(zone, json, "dependencies", sub);
}
return json;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief convert to a string, basically for debugging purposes
////////////////////////////////////////////////////////////////////////////////
static void someSpaces (std::string& st, int nr) {
for (int i = 0; i < nr; i++) {
st.push_back(' ');
}
}
void ExecutionPlan::appendAsString (std::string& st, int indent) {
someSpaces(st, indent);
st.push_back('<');
st.append(getTypeString());
if (_dependencies.size() != 0) {
st.push_back('\n');
for (size_t i = 0; i < _dependencies.size(); i++) {
_dependencies[i]->appendAsString(st, indent+2);
if (i != _dependencies.size()-1) {
st.push_back(',');
}
else {
st.push_back(' ');
}
}
}
st.push_back('>');
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test function
////////////////////////////////////////////////////////////////////////////////
void testExecutionPlans () {
ExecutionPlan* e = new ExecutionPlan();
ExecutionPlan* f = new ExecutionPlan(e);
std::string st;
e->appendAsString(st, 0);
std::cout << "e as string:\n" << st << std::endl;
st.clear();
f->appendAsString(st, 0);
std::cout << "f as string:\n" << st << std::endl;
TRI_json_t* json = e->toJson(TRI_UNKNOWN_MEM_ZONE);
if (json != nullptr) {
std::cout << "e as JSON:\n" <<
triagens::basics::JsonHelper::toString(json) << std::endl;
}
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
json = f->toJson(TRI_UNKNOWN_MEM_ZONE);
if (json != nullptr) {
std::cout << "f as JSON:\n" <<
triagens::basics::JsonHelper::toString(json) << std::endl;
}
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
delete f; // should not leave a leak
}
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"

View File

@ -112,6 +112,14 @@ namespace triagens {
return ILLEGAL;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the type of the node as a string
////////////////////////////////////////////////////////////////////////////////
virtual std::string getTypeString () {
return std::string("ExecutionPlan (abstract)");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief add a dependency
////////////////////////////////////////////////////////////////////////////////
@ -145,7 +153,9 @@ namespace triagens {
/// @brief clone execution plan recursively, this makes the class abstract
////////////////////////////////////////////////////////////////////////////////
virtual ExecutionPlan* clone () = 0;
virtual ExecutionPlan* clone () { // = 0; make this abstract later
return this;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief export to JSON
@ -153,6 +163,12 @@ namespace triagens {
virtual TRI_json_t* toJson (TRI_memory_zone_t* zone);
////////////////////////////////////////////////////////////////////////////////
/// @brief convert to a string, basically for debugging purposes
////////////////////////////////////////////////////////////////////////////////
virtual void appendAsString (std::string& st, int indent = 0);
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------