Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed bugs in logging, fixed problems in ProgramOptions, more Graph f…

…unctions
  • Loading branch information...
commit 38bd97bde4e9da5ba5869f83b954fccc0048d0d8 1 parent 58a1f11
Frank Celler fceller authored
110 Basics/ProgramOptions.cpp
@@ -97,30 +97,6 @@ static T find (map<string, T> const& m, string const& key) {
97 97 }
98 98
99 99 ////////////////////////////////////////////////////////////////////////////////
100   -/// @brief extracts a boolean
101   -////////////////////////////////////////////////////////////////////////////////
102   -
103   -static void ExtractBool (char const* ptr, bool* value) {
104   - TRI_set_errno(TRI_ERROR_NO_ERROR);
105   -
106   - if (TRI_CaseEqualString(ptr, "yes")) {
107   - *value = true;
108   - }
109   - else if (TRI_CaseEqualString(ptr, "no")) {
110   - *value = false;
111   - }
112   - else if (TRI_CaseEqualString(ptr, "true")) {
113   - *value = true;
114   - }
115   - else if (TRI_CaseEqualString(ptr, "false")) {
116   - *value = false;
117   - }
118   - else {
119   - TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION);
120   - }
121   -}
122   -
123   -////////////////////////////////////////////////////////////////////////////////
124 100 /// @brief extracts a double
125 101 ////////////////////////////////////////////////////////////////////////////////
126 102
@@ -295,7 +271,15 @@ static void ExtractVectorUInt64 (TRI_vector_string_t* ptr, vector<uint64_t>* val
295 271 /// @brief constructor
296 272 ////////////////////////////////////////////////////////////////////////////////
297 273
298   -ProgramOptions::ProgramOptions () {
  274 +ProgramOptions::ProgramOptions ()
  275 + : _valuesBool(),
  276 + _valuesString(),
  277 + _valuesVector(),
  278 + _options(),
  279 + _errorMessage(),
  280 + _helpOptions(),
  281 + _flags(),
  282 + _seen() {
299 283 }
300 284
301 285 ////////////////////////////////////////////////////////////////////////////////
@@ -316,6 +300,10 @@ ProgramOptions::~ProgramOptions () {
316 300 for (map<string, TRI_vector_string_t*>::iterator i = _valuesVector.begin(); i != _valuesVector.end(); ++i) {
317 301 TRI_FreeVectorString(i->second);
318 302 }
  303 +
  304 + for (map<string, bool*>::iterator i = _valuesBool.begin(); i != _valuesBool.end(); ++i) {
  305 + TRI_Free(i->second);
  306 + }
319 307 }
320 308
321 309 ////////////////////////////////////////////////////////////////////////////////
@@ -345,11 +333,13 @@ bool ProgramOptions::parse (ProgramOptionsDescription const& description, int ar
345 333 bool ok = TRI_ParseArgumentsProgramOptions(options, argc, argv);
346 334
347 335 if (ok) {
348   - ok = extractValues(description, options);
  336 + ok = extractValues(description, options, _seen);
349 337
350   - if (description._positionals != 0) {
351   - for (size_t i = 0; i < options->_arguments._length; ++i) {
352   - description._positionals->push_back(options->_arguments._buffer[i]);
  338 + if (ok) {
  339 + if (description._positionals != 0) {
  340 + for (size_t i = 0; i < options->_arguments._length; ++i) {
  341 + description._positionals->push_back(options->_arguments._buffer[i]);
  342 + }
353 343 }
354 344 }
355 345 }
@@ -357,11 +347,11 @@ bool ProgramOptions::parse (ProgramOptionsDescription const& description, int ar
357 347 _errorMessage = TRI_last_error();
358 348 }
359 349
360   - //freeValues(options);
  350 + // freeValues(options);
361 351 TRI_FreeProgramOptions(options);
362 352 TRI_FreePODescription(desc);
363 353
364   - return true;
  354 + return ok;
365 355 }
366 356
367 357 ////////////////////////////////////////////////////////////////////////////////
@@ -378,13 +368,13 @@ bool ProgramOptions::parse (ProgramOptionsDescription const& description, string
378 368 bool ok = TRI_ParseFileProgramOptions(options, filename.c_str());
379 369
380 370 if (ok) {
381   - ok = extractValues(description, options);
  371 + ok = extractValues(description, options, _seen);
382 372 }
383 373 else {
384 374 _errorMessage = TRI_last_error();
385 375 }
386 376
387   - //freeValues(options);
  377 + // freeValues(options);
388 378 TRI_FreeProgramOptions(options);
389 379 TRI_FreePODescription(desc);
390 380
@@ -499,14 +489,24 @@ void ProgramOptions::setupSubDescription (ProgramOptionsDescription const& descr
499 489 if (j != description._optionTypes.end()) {
500 490 ProgramOptionsDescription::option_type_e type = j->second;
501 491 char** ptr;
  492 + bool* btr;
502 493 TRI_vector_string_t* wtr;
503 494
504 495 switch (type) {
505 496 case ProgramOptionsDescription::OPTION_TYPE_FLAG:
506   - TRI_AddFlagPODescription(desc, option.c_str(), 0, help.c_str(), 0);
  497 + TRI_AddFlagPODescription(desc, option.c_str(), shortOption, help.c_str(), 0);
507 498 break;
508 499
509 500 case ProgramOptionsDescription::OPTION_TYPE_BOOL:
  501 + btr = _valuesBool[option];
  502 +
  503 + if (btr == 0) {
  504 + btr = _valuesBool[option] = (bool*) TRI_Allocate(sizeof(bool));
  505 + }
  506 +
  507 + TRI_AddFlagPODescription(desc, option.c_str(), shortOption, help.c_str(), btr);
  508 + break;
  509 +
510 510 case ProgramOptionsDescription::OPTION_TYPE_DOUBLE:
511 511 case ProgramOptionsDescription::OPTION_TYPE_INT32:
512 512 case ProgramOptionsDescription::OPTION_TYPE_INT64:
@@ -564,9 +564,11 @@ void ProgramOptions::setupSubDescription (ProgramOptionsDescription const& descr
564 564 /// @brief extracts the parsed options
565 565 ////////////////////////////////////////////////////////////////////////////////
566 566
567   -bool ProgramOptions::extractValues (ProgramOptionsDescription const& description, TRI_program_options_t* options) {
  567 +bool ProgramOptions::extractValues (ProgramOptionsDescription const& description, TRI_program_options_t* options, set<string> seen) {
568 568 size_t i;
569 569 char** ptr;
  570 + bool* btr;
  571 + bool* b;
570 572 TRI_vector_string_t* wtr;
571 573
572 574 for (i = 0; i < options->_items._length; ++i) {
@@ -577,19 +579,41 @@ bool ProgramOptions::extractValues (ProgramOptionsDescription const& description
577 579 if (item->_used) {
578 580 string name = item->_desc->_name;
579 581
  582 + if (seen.find(name) != seen.end()) {
  583 + continue;
  584 + }
  585 +
580 586 _flags.insert(name);
  587 + _seen.insert(name);
581 588
582   - if (item->_desc->_type == TRI_PO_STRING) {
583   - ptr = _valuesString[name];
  589 + if (item->_desc->_type == TRI_PO_FLAG) {
  590 + btr = _valuesBool[name];
584 591
585   - if (ptr != 0) {
  592 + if (btr != 0) {
586 593 ProgramOptionsDescription::option_type_e type = lookup(description._optionTypes, name);
587 594
588 595 switch (type) {
589 596 case ProgramOptionsDescription::OPTION_TYPE_BOOL:
590   - ExtractBool(*ptr, lookup(description._boolOptions, name));
  597 + b = lookup(description._boolOptions, name);
  598 +
  599 + if (b != 0) {
  600 + *b = *btr;
  601 + }
  602 +
  603 + break;
  604 +
  605 + default:
591 606 break;
  607 + }
  608 + }
  609 + }
  610 + else if (item->_desc->_type == TRI_PO_STRING) {
  611 + ptr = _valuesString[name];
  612 +
  613 + if (ptr != 0) {
  614 + ProgramOptionsDescription::option_type_e type = lookup(description._optionTypes, name);
592 615
  616 + switch (type) {
593 617 case ProgramOptionsDescription::OPTION_TYPE_DOUBLE:
594 618 ExtractDouble(*ptr, lookup(description._doubleOptions, name));
595 619 break;
@@ -679,13 +703,17 @@ bool ProgramOptions::extractValues (ProgramOptionsDescription const& description
679 703 for (vector<ProgramOptionsDescription>::const_iterator i = description._subDescriptions.begin();
680 704 i != description._subDescriptions.end();
681 705 ++i) {
682   - extractValues(*i, options);
  706 + if (! extractValues(*i, options, seen)) {
  707 + return false;
  708 + }
683 709 }
684 710
685 711 for (vector<ProgramOptionsDescription>::const_iterator i = description._hiddenSubDescriptions.begin();
686 712 i != description._hiddenSubDescriptions.end();
687 713 ++i) {
688   - extractValues(*i, options);
  714 + if (! extractValues(*i, options, seen)) {
  715 + return false;
  716 + }
689 717 }
690 718
691 719 return true;
14 Basics/ProgramOptions.h
@@ -163,7 +163,7 @@ namespace triagens {
163 163 /// @brief result data
164 164 ////////////////////////////////////////////////////////////////////////////////
165 165
166   - bool extractValues (ProgramOptionsDescription const&, struct TRI_program_options_s*);
  166 + bool extractValues (ProgramOptionsDescription const&, struct TRI_program_options_s*, set<string> seen);
167 167
168 168 ////////////////////////////////////////////////////////////////////////////////
169 169 /// @}
@@ -181,6 +181,12 @@ namespace triagens {
181 181 private:
182 182
183 183 ////////////////////////////////////////////////////////////////////////////////
  184 +/// @brief bool values
  185 +////////////////////////////////////////////////////////////////////////////////
  186 +
  187 + map<string, bool*> _valuesBool;
  188 +
  189 +////////////////////////////////////////////////////////////////////////////////
184 190 /// @brief string values
185 191 ////////////////////////////////////////////////////////////////////////////////
186 192
@@ -215,6 +221,12 @@ namespace triagens {
215 221 ////////////////////////////////////////////////////////////////////////////////
216 222
217 223 set<string> _flags;
  224 +
  225 +////////////////////////////////////////////////////////////////////////////////
  226 +/// @brief flags which are already set
  227 +////////////////////////////////////////////////////////////////////////////////
  228 +
  229 + set<string> _seen;
218 230 };
219 231 }
220 232 }
2  Basics/logging.c
@@ -478,7 +478,7 @@ static size_t GenerateMessage (char* buffer,
478 478 // append the message
479 479 // .............................................................................
480 480
481   - n = vsnprintf(buffer + m, size - n, fmt, ap);
  481 + n = vsnprintf(buffer + m, size - m, fmt, ap);
482 482
483 483 if (n < 0) {
484 484 return n;
24 ProgramOptions/program-options.c
@@ -250,6 +250,12 @@ static void ParseFlagArg (char const * userarg, void * value) {
250 250 else if (TRI_CaseEqualString(userarg, "false")) {
251 251 *flag->_value = false;
252 252 }
  253 + else if (TRI_CaseEqualString(userarg, "1")) {
  254 + *flag->_value = true;
  255 + }
  256 + else if (TRI_CaseEqualString(userarg, "0")) {
  257 + *flag->_value = false;
  258 + }
253 259 }
254 260 }
255 261
@@ -264,7 +270,12 @@ static void CreateFlagOption (po_flag_t * desc, void const * input, void * outpu
264 270
265 271 po = output;
266 272
267   - InitOptionStructure(&flagOpt, desc->base._name, 0, 0, po->_longopts._length);
  273 + if (desc->_value == 0) {
  274 + InitOptionStructure(&flagOpt, desc->base._name, 0, 0, po->_longopts._length);
  275 + }
  276 + else {
  277 + InitOptionStructure(&flagOpt, desc->base._name, 1, 0, po->_longopts._length);
  278 + }
268 279
269 280 memset(&item, 0, sizeof(item));
270 281
@@ -1359,7 +1370,16 @@ bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t * options,
1359 1370 if (item->_desc->_short != '\0') {
1360 1371 TRI_AppendCharStringBuffer(&buffer, item->_desc->_short);
1361 1372
1362   - if (item->_desc->_type != TRI_PO_FLAG) {
  1373 + if (item->_desc->_type == TRI_PO_FLAG) {
  1374 + po_flag_t* p;
  1375 +
  1376 + p = (po_flag_t*) item->_desc;
  1377 +
  1378 + if (p->_value != 0) {
  1379 + TRI_AppendCharStringBuffer(&buffer, ':');
  1380 + }
  1381 + }
  1382 + else {
1363 1383 TRI_AppendCharStringBuffer(&buffer, ':');
1364 1384 }
1365 1385 }
6 RestServer/AvocadoServer.cpp
@@ -190,7 +190,7 @@ AvocadoServer::AvocadoServer (int argc, char** argv)
190 190 ////////////////////////////////////////////////////////////////////////////////
191 191
192 192 void AvocadoServer::buildApplicationServer () {
193   - _applicationServer = ApplicationServerDispatcher::create("[<options>] - starts the triAGENS AvocadoDB", TRIAGENS_VERSION);
  193 + _applicationServer = ApplicationServerDispatcher::create("[<options>] <database-directory>", TRIAGENS_VERSION);
194 194 _applicationServer->setSystemConfigFile("avocado.conf");
195 195 _applicationServer->setUserConfigFile(".avocado/avocado.conf");
196 196
@@ -253,8 +253,8 @@ void AvocadoServer::buildApplicationServer () {
253 253 // database options
254 254 // .............................................................................
255 255
256   - additional["DATABASE Options"]
257   - ("database.directory", &_databasePath, "path to the database directory")
  256 + additional["DATABASE Options:help-extended"]
  257 + ("database.directory", &_databasePath, "path to the database directory (use this option in configuration files instead of passing it via the command line)")
258 258 ;
259 259
260 260 // .............................................................................
271 RestServer/js-graph.h
@@ -48,14 +48,16 @@ static string JS_graph =
48 48 "/// </ol>\n"
49 49 "/// <li>Vertex</li>\n"
50 50 "/// <ol>\n"
  51 + "/// <li>Vertex.edges</li>\n"
  52 + "/// <li>Vertex.addInEdge</li>\n"
  53 + "/// <li>Vertex.addOutEdge</li>\n"
51 54 "/// <li>Vertex.getId</li>\n"
52 55 "/// <li>Vertex.getInEdges</li>\n"
53 56 "/// <li>Vertex.getOutEdges</li>\n"
54 57 "/// <li>Vertex.getProperty</li>\n"
55 58 "/// <li>Vertex.getPropertyKeys</li>\n"
56   - "/// <li>Vertex.setProperty</li>\n"
57   - "/// <li>Vertex.edges</li>\n"
58 59 "/// <li>Vertex.properties</li>\n"
  60 + "/// <li>Vertex.setProperty</li>\n"
59 61 "/// </ol>\n"
60 62 "/// <li>Edge</li>\n"
61 63 "/// <ol>\n"
@@ -65,6 +67,7 @@ static string JS_graph =
65 67 "/// <li>Edge.getOutVertex</li>\n"
66 68 "/// <li>Edge.getProperty</li>\n"
67 69 "/// <li>Edge.getPropertyKeys</li>\n"
  70 + "/// <li>Edge.properties</li>\n"
68 71 "/// <li>Edge.setProperty</li>\n"
69 72 "/// </ol>\n"
70 73 "/// </li>\n"
@@ -84,8 +87,16 @@ static string JS_graph =
84 87 "///\n"
85 88 "/// @copydetails JSF_Graph_prototype_addVertex\n"
86 89 "///\n"
  90 + "/// @copydetails JSF_Graph_prototype_getVertex\n"
  91 + "///\n"
87 92 "/// @section Vertex\n"
88 93 "///\n"
  94 + "/// @copydetails JSF_Vertex_prototype_edges\n"
  95 + "///\n"
  96 + "/// @copydetails JSF_Vertex_prototype_addInEdge\n"
  97 + "///\n"
  98 + "/// @copydetails JSF_Vertex_prototype_addOutEdge\n"
  99 + "///\n"
89 100 "/// @copydetails JSF_Vertex_prototype_getId\n"
90 101 "///\n"
91 102 "/// @copydetails JSF_Vertex_prototype_getInEdges\n"
@@ -96,12 +107,10 @@ static string JS_graph =
96 107 "///\n"
97 108 "/// @copydetails JSF_Vertex_prototype_getPropertyKeys\n"
98 109 "///\n"
99   - "/// @copydetails JSF_Vertex_prototype_setProperty\n"
100   - "///\n"
101   - "/// @copydetails JSF_Vertex_prototype_edges\n"
102   - "///\n"
103 110 "/// @copydetails JSF_Vertex_prototype_properties\n"
104 111 "///\n"
  112 + "/// @copydetails JSF_Vertex_prototype_setProperty\n"
  113 + "///\n"
105 114 "/// @section Edge\n"
106 115 "///\n"
107 116 "/// @copydetails JSF_Edge_prototype_getId\n"
@@ -116,6 +125,8 @@ static string JS_graph =
116 125 "///\n"
117 126 "/// @copydetails JSF_Edge_prototype_getPropertyKeys\n"
118 127 "///\n"
  128 + "/// @copydetails JSF_Edge_prototype_properties\n"
  129 + "///\n"
119 130 "/// @copydetails JSF_Edge_prototype_setProperty\n"
120 131 "///\n"
121 132 "////////////////////////////////////////////////////////////////////////////////\n"
@@ -125,11 +136,11 @@ static string JS_graph =
125 136 "// -----------------------------------------------------------------------------\n"
126 137 "\n"
127 138 "// -----------------------------------------------------------------------------\n"
128   - "// --SECTION-- public functions\n"
  139 + "// --SECTION-- constructors and destructors\n"
129 140 "// -----------------------------------------------------------------------------\n"
130 141 "\n"
131 142 "////////////////////////////////////////////////////////////////////////////////\n"
132   - "/// @addtogroup V8Json V8 JSON\n"
  143 + "/// @addtogroup V8Json\n"
133 144 "/// @{\n"
134 145 "////////////////////////////////////////////////////////////////////////////////\n"
135 146 "\n"
@@ -143,6 +154,19 @@ static string JS_graph =
143 154 "}\n"
144 155 "\n"
145 156 "////////////////////////////////////////////////////////////////////////////////\n"
  157 + "/// @}\n"
  158 + "////////////////////////////////////////////////////////////////////////////////\n"
  159 + "\n"
  160 + "// -----------------------------------------------------------------------------\n"
  161 + "// --SECTION-- public functions\n"
  162 + "// -----------------------------------------------------------------------------\n"
  163 + "\n"
  164 + "////////////////////////////////////////////////////////////////////////////////\n"
  165 + "/// @addtogroup AvocadoGraph\n"
  166 + "/// @{\n"
  167 + "////////////////////////////////////////////////////////////////////////////////\n"
  168 + "\n"
  169 + "////////////////////////////////////////////////////////////////////////////////\n"
146 170 "/// @brief returns the identifier of an edge\n"
147 171 "///\n"
148 172 "/// @FUN{@FA{edge}.getId()}\n"
@@ -167,12 +191,7 @@ static string JS_graph =
167 191 "////////////////////////////////////////////////////////////////////////////////\n"
168 192 "\n"
169 193 "Edge.prototype.getInVertex = function () {\n"
170   - " if (! this.hasOwnProperty(\"_inVertex\")) {\n"
171   - " this.properties();\n"
172   - " this._inVertex = new Vertex(this._graph, this._to);\n"
173   - " }\n"
174   - "\n"
175   - " return _inVertex;\n"
  194 + " return this.graph.constructVertex(this._to);\n"
176 195 "}\n"
177 196 "\n"
178 197 "////////////////////////////////////////////////////////////////////////////////\n"
@@ -204,12 +223,7 @@ static string JS_graph =
204 223 "////////////////////////////////////////////////////////////////////////////////\n"
205 224 "\n"
206 225 "Edge.prototype.getOutVertex = function () {\n"
207   - " if (! this.hasOwnProperty(\"_outVertex\")) {\n"
208   - " this.properties();\n"
209   - " this._outVertex = new Vertex(this._graph, this._from);\n"
210   - " }\n"
211   - "\n"
212   - " return this._outVertex;\n"
  226 + " return this._graph.constructVertex(this._from);\n"
213 227 "}\n"
214 228 "\n"
215 229 "////////////////////////////////////////////////////////////////////////////////\n"
@@ -326,10 +340,23 @@ static string JS_graph =
326 340 "}\n"
327 341 "\n"
328 342 "////////////////////////////////////////////////////////////////////////////////\n"
  343 + "/// @}\n"
  344 + "////////////////////////////////////////////////////////////////////////////////\n"
  345 + "\n"
  346 + "// -----------------------------------------------------------------------------\n"
  347 + "// --SECTION-- private methods\n"
  348 + "// -----------------------------------------------------------------------------\n"
  349 + "\n"
  350 + "////////////////////////////////////////////////////////////////////////////////\n"
  351 + "/// @addtogroup AvocadoGraph\n"
  352 + "/// @{\n"
  353 + "////////////////////////////////////////////////////////////////////////////////\n"
  354 + "\n"
  355 + "////////////////////////////////////////////////////////////////////////////////\n"
329 356 "/// @brief edge printing\n"
330 357 "////////////////////////////////////////////////////////////////////////////////\n"
331 358 "\n"
332   - "Edge.prototype.print = function () {\n"
  359 + "Edge.prototype.PRINT = function () {\n"
333 360 " output(\"Edge(<graph>, \\\"\", this._id, \"\\\")\");\n"
334 361 "}\n"
335 362 "\n"
@@ -342,11 +369,11 @@ static string JS_graph =
342 369 "// -----------------------------------------------------------------------------\n"
343 370 "\n"
344 371 "// -----------------------------------------------------------------------------\n"
345   - "// --SECTION-- public functions\n"
  372 + "// --SECTION-- constructors and destructors\n"
346 373 "// -----------------------------------------------------------------------------\n"
347 374 "\n"
348 375 "////////////////////////////////////////////////////////////////////////////////\n"
349   - "/// @addtogroup V8Json V8 JSON\n"
  376 + "/// @addtogroup AvocadoGraph\n"
350 377 "/// @{\n"
351 378 "////////////////////////////////////////////////////////////////////////////////\n"
352 379 "\n"
@@ -360,11 +387,60 @@ static string JS_graph =
360 387 "}\n"
361 388 "\n"
362 389 "////////////////////////////////////////////////////////////////////////////////\n"
363   - "/// @brief vertex representation\n"
  390 + "/// @}\n"
364 391 "////////////////////////////////////////////////////////////////////////////////\n"
365 392 "\n"
366   - "Vertex.prototype.print = function () {\n"
367   - " output(\"Vertex(<graph>, \\\"\", this._id, \"\\\")\");\n"
  393 + "// -----------------------------------------------------------------------------\n"
  394 + "// --SECTION-- public functions\n"
  395 + "// -----------------------------------------------------------------------------\n"
  396 + "\n"
  397 + "////////////////////////////////////////////////////////////////////////////////\n"
  398 + "/// @addtogroup AvocadoGraph\n"
  399 + "/// @{\n"
  400 + "////////////////////////////////////////////////////////////////////////////////\n"
  401 + "\n"
  402 + "////////////////////////////////////////////////////////////////////////////////\n"
  403 + "/// @brief adds an inbound edge\n"
  404 + "///\n"
  405 + "/// @FUN{@FA{vertex}.addInEdge(@FA{peer}, @FA{label})}\n"
  406 + "///\n"
  407 + "/// Creates a new edge from @FA{peer} to @FA{vertex} with given label and\n"
  408 + "/// returns the edge object.\n"
  409 + "///\n"
  410 + "/// @verbinclude graph23\n"
  411 + "///\n"
  412 + "/// @FUN{@FA{vertex}.addInEdge(@FA{peer}, @FA{label}, @FA{data})}\n"
  413 + "///\n"
  414 + "/// Creates a new edge from @FA{peer} to @FA{vertex} with given label and\n"
  415 + "/// properties defined in @FA{data}. Returns the edge object.\n"
  416 + "///\n"
  417 + "/// @verbinclude graph24\n"
  418 + "////////////////////////////////////////////////////////////////////////////////\n"
  419 + "\n"
  420 + "Vertex.prototype.addInEdge = function (out, label, data) {\n"
  421 + " return this._graph.addEdge(out, this, label, data);\n"
  422 + "}\n"
  423 + "\n"
  424 + "////////////////////////////////////////////////////////////////////////////////\n"
  425 + "/// @brief adds an outbound edge\n"
  426 + "///\n"
  427 + "/// @FUN{@FA{vertex}.addOutEdge(@FA{peer}, @FA{label})}\n"
  428 + "///\n"
  429 + "/// Creates a new edge from @FA{vertex} to @FA{peer} with given @FA{label} and\n"
  430 + "/// returns the edge object.\n"
  431 + "///\n"
  432 + "/// @verbinclude graph23\n"
  433 + "///\n"
  434 + "/// @FUN{@FA{vertex}.addOutEdge(@FA{peer}, @FA{label}, @FA{data})}\n"
  435 + "///\n"
  436 + "/// Creates a new edge from @FA{vertex} to @FA{peer} with given @FA{label} and\n"
  437 + "/// properties defined in @FA{data}. Returns the edge object.\n"
  438 + "///\n"
  439 + "/// @verbinclude graph24\n"
  440 + "////////////////////////////////////////////////////////////////////////////////\n"
  441 + "\n"
  442 + "Vertex.prototype.addOutEdge = function (ine, label, data) {\n"
  443 + " return this._graph.addEdge(this, ine, label, data);\n"
368 444 "}\n"
369 445 "\n"
370 446 "////////////////////////////////////////////////////////////////////////////////\n"
@@ -388,7 +464,7 @@ static string JS_graph =
388 464 " result = [];\n"
389 465 "\n"
390 466 " while (query.hasNext()) {\n"
391   - " result.push(new Edge(graph, query.nextRef()));\n"
  467 + " result.push(graph.constructEdge(query.nextRef()));\n"
392 468 " }\n"
393 469 "\n"
394 470 " this._edges = result;\n"
@@ -555,7 +631,7 @@ static string JS_graph =
555 631 " result = [];\n"
556 632 "\n"
557 633 " while (query.hasNext()) {\n"
558   - " result.push(new Edge(graph, query.nextRef()));\n"
  634 + " result.push(graph.constructEdge(query.nextRef()));\n"
559 635 " }\n"
560 636 "\n"
561 637 " this._inbound = result;\n"
@@ -585,7 +661,7 @@ static string JS_graph =
585 661 " result = [];\n"
586 662 "\n"
587 663 " while (query.hasNext()) {\n"
588   - " result.push(new Edge(graph, query.nextRef()));\n"
  664 + " result.push(graph.constructEdge(query.nextRef()));\n"
589 665 " }\n"
590 666 "\n"
591 667 " this._outbound = result;\n"
@@ -660,15 +736,36 @@ static string JS_graph =
660 736 "////////////////////////////////////////////////////////////////////////////////\n"
661 737 "\n"
662 738 "// -----------------------------------------------------------------------------\n"
  739 + "// --SECTION-- private methods\n"
  740 + "// -----------------------------------------------------------------------------\n"
  741 + "\n"
  742 + "////////////////////////////////////////////////////////////////////////////////\n"
  743 + "/// @addtogroup AvocadoGraph\n"
  744 + "/// @{\n"
  745 + "////////////////////////////////////////////////////////////////////////////////\n"
  746 + "\n"
  747 + "////////////////////////////////////////////////////////////////////////////////\n"
  748 + "/// @brief vertex representation\n"
  749 + "////////////////////////////////////////////////////////////////////////////////\n"
  750 + "\n"
  751 + "Vertex.prototype.PRINT = function () {\n"
  752 + " output(\"Vertex(<graph>, \\\"\", this._id, \"\\\")\");\n"
  753 + "}\n"
  754 + "\n"
  755 + "////////////////////////////////////////////////////////////////////////////////\n"
  756 + "/// @}\n"
  757 + "////////////////////////////////////////////////////////////////////////////////\n"
  758 + "\n"
  759 + "// -----------------------------------------------------------------------------\n"
663 760 "// --SECTION-- GRAPH\n"
664 761 "// -----------------------------------------------------------------------------\n"
665 762 "\n"
666 763 "// -----------------------------------------------------------------------------\n"
667   - "// --SECTION-- public functions\n"
  764 + "// --SECTION-- constructors and destructors\n"
668 765 "// -----------------------------------------------------------------------------\n"
669 766 "\n"
670 767 "////////////////////////////////////////////////////////////////////////////////\n"
671   - "/// @addtogroup V8Json V8 JSON\n"
  768 + "/// @addtogroup AvocadoGraph\n"
672 769 "/// @{\n"
673 770 "////////////////////////////////////////////////////////////////////////////////\n"
674 771 "\n"
@@ -699,20 +796,33 @@ static string JS_graph =
699 796 " }\n"
700 797 "\n"
701 798 " this._vertices = vertices;\n"
  799 + " this._verticesCache = {};\n"
  800 + "\n"
702 801 " this._edges = edg;\n"
  802 + " this._edgesCache = {};\n"
703 803 "}\n"
704 804 "\n"
705 805 "////////////////////////////////////////////////////////////////////////////////\n"
706   - "/// @brief graph printing\n"
  806 + "/// @}\n"
707 807 "////////////////////////////////////////////////////////////////////////////////\n"
708 808 "\n"
709   - "Graph.prototype.print = function () {\n"
710   - " output(\"Graph(\\\"\", this._vertices._name, \"\\\", \\\"\" + this._edges._name, \"\\\")\");\n"
711   - "}\n"
  809 + "// -----------------------------------------------------------------------------\n"
  810 + "// --SECTION-- public functions\n"
  811 + "// -----------------------------------------------------------------------------\n"
  812 + "\n"
  813 + "////////////////////////////////////////////////////////////////////////////////\n"
  814 + "/// @addtogroup AvocadoGraph\n"
  815 + "/// @{\n"
  816 + "////////////////////////////////////////////////////////////////////////////////\n"
712 817 "\n"
713 818 "////////////////////////////////////////////////////////////////////////////////\n"
714 819 "/// @brief adds an edge to the graph\n"
715 820 "///\n"
  821 + "/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in})}\n"
  822 + "///\n"
  823 + "/// Creates a new edge from @FA{out} to @FA{in} and returns the edge\n"
  824 + "/// object.\n"
  825 + "///\n"
716 826 "/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{label})}\n"
717 827 "///\n"
718 828 "/// Creates a new edge from @FA{out} to @FA{in} with @FA{label} and returns the\n"
@@ -720,11 +830,16 @@ static string JS_graph =
720 830 "///\n"
721 831 "/// @verbinclude graph9\n"
722 832 "///\n"
723   - "/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{label}, @FA{data})}\n"
  833 + "/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{data})}\n"
724 834 "///\n"
725 835 "/// Creates a new edge and returns the edge object. The edge contains the\n"
726 836 "/// properties defined in @FA{data}.\n"
727 837 "///\n"
  838 + "/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{label}, @FA{data})}\n"
  839 + "///\n"
  840 + "/// Creates a new edge and returns the edge object. The edge has the\n"
  841 + "/// label @FA{label} and contains the properties defined in @FA{data}.\n"
  842 + "///\n"
728 843 "/// @verbinclude graph10\n"
729 844 "////////////////////////////////////////////////////////////////////////////////\n"
730 845 "\n"
@@ -734,6 +849,15 @@ static string JS_graph =
734 849 " var key;\n"
735 850 " var edge;\n"
736 851 "\n"
  852 + " if (typeof label === 'object') {\n"
  853 + " data = label;\n"
  854 + " label = undefined;\n"
  855 + " }\n"
  856 + "\n"
  857 + " if (label === undefined) {\n"
  858 + " label = null;\n"
  859 + " }\n"
  860 + "\n"
737 861 " if (data === undefined) {\n"
738 862 " ref = this._edges.save(out._id, ine._id, {\"_label\" : label});\n"
739 863 " }\n"
@@ -751,7 +875,7 @@ static string JS_graph =
751 875 " ref = this._edges.save(out._id, ine._id, shallow);\n"
752 876 " }\n"
753 877 "\n"
754   - " edge = new Edge(this, ref);\n"
  878 + " edge = this.constructEdge(ref);\n"
755 879 "\n"
756 880 " if (out.hasOwnProperty(\"_edges\")) {\n"
757 881 " out._edges.push(edge);\n"
@@ -769,9 +893,6 @@ static string JS_graph =
769 893 " ine._inbound.push(edge);\n"
770 894 " }\n"
771 895 "\n"
772   - " edge._inVertex = ine;\n"
773   - " edge._outVertex = out;\n"
774   - "\n"
775 896 " return edge;\n"
776 897 "}\n"
777 898 "\n"
@@ -802,7 +923,75 @@ static string JS_graph =
802 923 " ref = this._vertices.save(data);\n"
803 924 " }\n"
804 925 "\n"
805   - " return new Vertex(this, ref);\n"
  926 + " return this.constructVertex(ref);\n"
  927 + "}\n"
  928 + "\n"
  929 + "////////////////////////////////////////////////////////////////////////////////\n"
  930 + "/// @brief returns a vertex given its id\n"
  931 + "///\n"
  932 + "/// @FUN{@FA{graph}.getVertex(@FA{id})}\n"
  933 + "///\n"
  934 + "/// Returns the vertex identified by @FA{id} or undefined.\n"
  935 + "///\n"
  936 + "/// @verbinclude graph2\n"
  937 + "////////////////////////////////////////////////////////////////////////////////\n"
  938 + "\n"
  939 + "Graph.prototype.getVertex = function (id) {\n"
  940 + " var ref;\n"
  941 + "\n"
  942 + " ref = this._vertices.document(id);\n"
  943 + "\n"
  944 + " if (ref.count() == 1) {\n"
  945 + " return this.constructVertex(id);\n"
  946 + " }\n"
  947 + " else {\n"
  948 + " return undefined;\n"
  949 + " }\n"
  950 + "}\n"
  951 + "\n"
  952 + "////////////////////////////////////////////////////////////////////////////////\n"
  953 + "/// @}\n"
  954 + "////////////////////////////////////////////////////////////////////////////////\n"
  955 + "\n"
  956 + "// -----------------------------------------------------------------------------\n"
  957 + "// --SECTION-- private functions\n"
  958 + "// -----------------------------------------------------------------------------\n"
  959 + "\n"
  960 + "////////////////////////////////////////////////////////////////////////////////\n"
  961 + "/// @addtogroup AvocadoGraph\n"
  962 + "/// @{\n"
  963 + "////////////////////////////////////////////////////////////////////////////////\n"
  964 + "\n"
  965 + "////////////////////////////////////////////////////////////////////////////////\n"
  966 + "/// @brief private function to construct a vertex\n"
  967 + "////////////////////////////////////////////////////////////////////////////////\n"
  968 + "\n"
  969 + "Graph.prototype.constructVertex = function(id) {\n"
  970 + " if (! (id in this._verticesCache)) {\n"
  971 + " this._verticesCache[id] = new Vertex(this, id);\n"
  972 + " }\n"
  973 + "\n"
  974 + " return this._verticesCache[id];\n"
  975 + "}\n"
  976 + "\n"
  977 + "////////////////////////////////////////////////////////////////////////////////\n"
  978 + "/// @brief private function to construct an edge\n"
  979 + "////////////////////////////////////////////////////////////////////////////////\n"
  980 + "\n"
  981 + "Graph.prototype.constructEdge = function(id) {\n"
  982 + " if (! (id in this._edgesCache)) {\n"
  983 + " this._edgesCache[id] = new Edge(this, id);\n"
  984 + " }\n"
  985 + "\n"
  986 + " return this._edgesCache[id];\n"
  987 + "}\n"
  988 + "\n"
  989 + "////////////////////////////////////////////////////////////////////////////////\n"
  990 + "/// @brief graph printing\n"
  991 + "////////////////////////////////////////////////////////////////////////////////\n"
  992 + "\n"
  993 + "Graph.prototype.PRINT = function () {\n"
  994 + " output(\"Graph(\\\"\", this._vertices._name, \"\\\", \\\"\" + this._edges._name, \"\\\")\");\n"
806 995 "}\n"
807 996 "\n"
808 997 "////////////////////////////////////////////////////////////////////////////////\n"
45 RestServer/js-modules.h
@@ -92,6 +92,7 @@ static string JS_modules =
92 92 "Module.prototype.require = function (path) {\n"
93 93 " var content;\n"
94 94 " var sandbox;\n"
  95 + " var paths;\n"
95 96 " var module;\n"
96 97 "\n"
97 98 " // first get rid of any \"..\" and \".\"\n"
@@ -103,7 +104,29 @@ static string JS_modules =
103 104 " }\n"
104 105 "\n"
105 106 " // try to load the file\n"
106   - " content = read(\".\" + path + \".js\");\n"
  107 + " paths = MODULES_PATH.split(\";\");\n"
  108 + " content = undefined;\n"
  109 + "\n"
  110 + " for (var i = 0; i < paths.length; ++i) {\n"
  111 + " var p = paths[i];\n"
  112 + " var n;\n"
  113 + "\n"
  114 + " if (p == \"\") {\n"
  115 + " n = \".\" + path + \".js\"\n"
  116 + " }\n"
  117 + " else {\n"
  118 + " n = p + \"/\" + path + \".js\";\n"
  119 + " }\n"
  120 + "\n"
  121 + " if (FS_EXISTS(n)) {\n"
  122 + " content = read(n);\n"
  123 + " break;\n"
  124 + " }\n"
  125 + " }\n"
  126 + "\n"
  127 + " if (content == undefined) {\n"
  128 + " throw \"cannot find a module named '\" + path + \"' using the module path(s) '\" + MODULES_PATH + \"'\";\n"
  129 + " }\n"
107 130 "\n"
108 131 " // create a new sandbox and execute\n"
109 132 " ModuleCache[path] = module = new Module(path);\n"
@@ -206,6 +229,26 @@ static string JS_modules =
206 229 "/// @}\n"
207 230 "////////////////////////////////////////////////////////////////////////////////\n"
208 231 "\n"
  232 + "// -----------------------------------------------------------------------------\n"
  233 + "// --SECTION-- Module\n"
  234 + "// -----------------------------------------------------------------------------\n"
  235 + "\n"
  236 + "////////////////////////////////////////////////////////////////////////////////\n"
  237 + "/// @addtogroup V8ModuleFS\n"
  238 + "/// @{\n"
  239 + "////////////////////////////////////////////////////////////////////////////////\n"
  240 + "\n"
  241 + "////////////////////////////////////////////////////////////////////////////////\n"
  242 + "/// @brief fs model\n"
  243 + "////////////////////////////////////////////////////////////////////////////////\n"
  244 + "\n"
  245 + "ModuleCache[\"/fs\"] = new Module(\"/fs\");\n"
  246 + "ModuleCache[\"/fs\"].exports.exists = FS_EXISTS;\n"
  247 + "\n"
  248 + "////////////////////////////////////////////////////////////////////////////////\n"
  249 + "/// @}\n"
  250 + "////////////////////////////////////////////////////////////////////////////////\n"
  251 + "\n"
209 252 "// Local Variables:\n"
210 253 "// mode: outline-minor\n"
211 254 "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\)\"\n"
2  RestServer/js-shell.h
@@ -80,7 +80,7 @@ static string JS_shell =
80 80 " if ('PRINT' in value) {\n"
81 81 " value.PRINT();\n"
82 82 " }\n"
83   - " else if (value.prototype == undefined) {\n"
  83 + " else if (value.__proto__ === Object.prototype) {\n"
84 84 " PRINT_OBJECT(value);\n"
85 85 " }\n"
86 86 " else if ('toString' in value) {\n"
1  V8/v8-globals.h
@@ -61,6 +61,7 @@ typedef struct TRI_v8_global_s {
61 61 : JSQueries(),
62 62 JSResultSets(),
63 63 Actions(),
  64 + SystemActions(),
64 65 ActionsLock(),
65 66 EdgesTempl(),
66 67 EdgesColTempl(),
2  build.h
... ... @@ -1 +1 @@
1   -#define TRIAGENS_VERSION "0.0.6 (9730:9734)"
  1 +#define TRIAGENS_VERSION "0.0.6 (9770)"
86 js/graph.js
@@ -47,14 +47,16 @@
47 47 /// </ol>
48 48 /// <li>Vertex</li>
49 49 /// <ol>
  50 +/// <li>Vertex.edges</li>
  51 +/// <li>Vertex.addInEdge</li>
  52 +/// <li>Vertex.addOutEdge</li>
50 53 /// <li>Vertex.getId</li>
51 54 /// <li>Vertex.getInEdges</li>
52 55 /// <li>Vertex.getOutEdges</li>
53 56 /// <li>Vertex.getProperty</li>
54 57 /// <li>Vertex.getPropertyKeys</li>
55   -/// <li>Vertex.setProperty</li>
56   -/// <li>Vertex.edges</li>
57 58 /// <li>Vertex.properties</li>
  59 +/// <li>Vertex.setProperty</li>
58 60 /// </ol>
59 61 /// <li>Edge</li>
60 62 /// <ol>
@@ -64,6 +66,7 @@
64 66 /// <li>Edge.getOutVertex</li>
65 67 /// <li>Edge.getProperty</li>
66 68 /// <li>Edge.getPropertyKeys</li>
  69 +/// <li>Edge.properties</li>
67 70 /// <li>Edge.setProperty</li>
68 71 /// </ol>
69 72 /// </li>
@@ -87,6 +90,12 @@
87 90 ///
88 91 /// @section Vertex
89 92 ///
  93 +/// @copydetails JSF_Vertex_prototype_edges
  94 +///
  95 +/// @copydetails JSF_Vertex_prototype_addInEdge
  96 +///
  97 +/// @copydetails JSF_Vertex_prototype_addOutEdge
  98 +///
90 99 /// @copydetails JSF_Vertex_prototype_getId
91 100 ///
92 101 /// @copydetails JSF_Vertex_prototype_getInEdges
@@ -97,12 +106,10 @@
97 106 ///
98 107 /// @copydetails JSF_Vertex_prototype_getPropertyKeys
99 108 ///
100   -/// @copydetails JSF_Vertex_prototype_setProperty
101   -///
102   -/// @copydetails JSF_Vertex_prototype_edges
103   -///
104 109 /// @copydetails JSF_Vertex_prototype_properties
105 110 ///
  111 +/// @copydetails JSF_Vertex_prototype_setProperty
  112 +///
106 113 /// @section Edge
107 114 ///
108 115 /// @copydetails JSF_Edge_prototype_getId
@@ -117,6 +124,8 @@
117 124 ///
118 125 /// @copydetails JSF_Edge_prototype_getPropertyKeys
119 126 ///
  127 +/// @copydetails JSF_Edge_prototype_properties
  128 +///
120 129 /// @copydetails JSF_Edge_prototype_setProperty
121 130 ///
122 131 ////////////////////////////////////////////////////////////////////////////////
@@ -390,6 +399,50 @@ function Vertex (graph, id) {
390 399 ////////////////////////////////////////////////////////////////////////////////
391 400
392 401 ////////////////////////////////////////////////////////////////////////////////
  402 +/// @brief adds an inbound edge
  403 +///
  404 +/// @FUN{@FA{vertex}.addInEdge(@FA{peer}, @FA{label})}
  405 +///
  406 +/// Creates a new edge from @FA{peer} to @FA{vertex} with given label and
  407 +/// returns the edge object.
  408 +///
  409 +/// @verbinclude graph23
  410 +///
  411 +/// @FUN{@FA{vertex}.addInEdge(@FA{peer}, @FA{label}, @FA{data})}
  412 +///
  413 +/// Creates a new edge from @FA{peer} to @FA{vertex} with given label and
  414 +/// properties defined in @FA{data}. Returns the edge object.
  415 +///
  416 +/// @verbinclude graph24
  417 +////////////////////////////////////////////////////////////////////////////////
  418 +
  419 +Vertex.prototype.addInEdge = function (out, label, data) {
  420 + return this._graph.addEdge(out, this, label, data);
  421 +}
  422 +
  423 +////////////////////////////////////////////////////////////////////////////////
  424 +/// @brief adds an outbound edge
  425 +///
  426 +/// @FUN{@FA{vertex}.addOutEdge(@FA{peer}, @FA{label})}
  427 +///
  428 +/// Creates a new edge from @FA{vertex} to @FA{peer} with given @FA{label} and
  429 +/// returns the edge object.
  430 +///
  431 +/// @verbinclude graph23
  432 +///
  433 +/// @FUN{@FA{vertex}.addOutEdge(@FA{peer}, @FA{label}, @FA{data})}
  434 +///
  435 +/// Creates a new edge from @FA{vertex} to @FA{peer} with given @FA{label} and
  436 +/// properties defined in @FA{data}. Returns the edge object.
  437 +///
  438 +/// @verbinclude graph24
  439 +////////////////////////////////////////////////////////////////////////////////
  440 +
  441 +Vertex.prototype.addOutEdge = function (ine, label, data) {
  442 + return this._graph.addEdge(this, ine, label, data);
  443 +}
  444 +
  445 +////////////////////////////////////////////////////////////////////////////////
393 446 /// @brief inbound and outbound edges
394 447 ///
395 448 /// @FUN{@FA{vertex}.edges()}
@@ -764,6 +817,11 @@ function Graph (vertices, edg) {
764 817 ////////////////////////////////////////////////////////////////////////////////
765 818 /// @brief adds an edge to the graph
766 819 ///
  820 +/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in})}
  821 +///
  822 +/// Creates a new edge from @FA{out} to @FA{in} and returns the edge
  823 +/// object.
  824 +///
767 825 /// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{label})}
768 826 ///
769 827 /// Creates a new edge from @FA{out} to @FA{in} with @FA{label} and returns the
@@ -771,11 +829,16 @@ function Graph (vertices, edg) {
771 829 ///
772 830 /// @verbinclude graph9
773 831 ///
774   -/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{label}, @FA{data})}
  832 +/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{data})}
775 833 ///
776 834 /// Creates a new edge and returns the edge object. The edge contains the
777 835 /// properties defined in @FA{data}.
778 836 ///
  837 +/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{label}, @FA{data})}
  838 +///
  839 +/// Creates a new edge and returns the edge object. The edge has the
  840 +/// label @FA{label} and contains the properties defined in @FA{data}.
  841 +///
779 842 /// @verbinclude graph10
780 843 ////////////////////////////////////////////////////////////////////////////////
781 844
@@ -785,6 +848,15 @@ Graph.prototype.addEdge = function (out, ine, label, data) {
785 848 var key;
786 849 var edge;
787 850
  851 + if (typeof label === 'object') {
  852 + data = label;
  853 + label = undefined;
  854 + }
  855 +
  856 + if (label === undefined) {
  857 + label = null;
  858 + }
  859 +
788 860 if (data === undefined) {
789 861 ref = this._edges.save(out._id, ine._id, {"_label" : label});
790 862 }

0 comments on commit 38bd97b

Please sign in to comment.
Something went wrong with that request. Please try again.