@@ -58,7 +58,7 @@ bool AqlValue::isTrue () const {
58
58
}
59
59
}
60
60
else if (_type == RANGE || _type == DOCVEC) {
61
- // a range or a docvec is equivalent to a list
61
+ // a range or a docvec is equivalent to an array
62
62
return true ;
63
63
}
64
64
else if (_type == EMPTY) {
@@ -244,7 +244,7 @@ bool AqlValue::isBoolean () const {
244
244
}
245
245
246
246
// //////////////////////////////////////////////////////////////////////////////
247
- // / @brief whether or not the AqlValue contains a list value
247
+ // / @brief whether or not the AqlValue contains an array value
248
248
// //////////////////////////////////////////////////////////////////////////////
249
249
250
250
bool AqlValue::isArray () const {
@@ -272,7 +272,7 @@ bool AqlValue::isArray () const {
272
272
}
273
273
274
274
// //////////////////////////////////////////////////////////////////////////////
275
- // / @brief whether or not the AqlValue contains an array value
275
+ // / @brief whether or not the AqlValue contains an object value
276
276
// //////////////////////////////////////////////////////////////////////////////
277
277
278
278
bool AqlValue::isObject () const {
@@ -296,6 +296,80 @@ bool AqlValue::isObject () const {
296
296
THROW_ARANGO_EXCEPTION (TRI_ERROR_INTERNAL);
297
297
}
298
298
299
+ // //////////////////////////////////////////////////////////////////////////////
300
+ // / @brief whether or not the AqlValue contains a null value
301
+ // //////////////////////////////////////////////////////////////////////////////
302
+
303
+ bool AqlValue::isNull (bool emptyIsNull) const {
304
+ switch (_type) {
305
+ case JSON: {
306
+ TRI_json_t const * json = _json->json ();
307
+ return json == nullptr || json->_type == TRI_JSON_NULL;
308
+ }
309
+
310
+ case SHAPED: {
311
+ return false ;
312
+ }
313
+
314
+ case DOCVEC:
315
+ case RANGE: {
316
+ return false ;
317
+ }
318
+
319
+ case EMPTY: {
320
+ return emptyIsNull;
321
+ }
322
+ }
323
+
324
+ THROW_ARANGO_EXCEPTION (TRI_ERROR_INTERNAL);
325
+ }
326
+
327
+ // //////////////////////////////////////////////////////////////////////////////
328
+ // / @brief returns the array member at position i
329
+ // //////////////////////////////////////////////////////////////////////////////
330
+
331
+ triagens::basics::Json AqlValue::at (triagens::arango::AqlTransaction* trx,
332
+ size_t i) const {
333
+ switch (_type) {
334
+ case JSON: {
335
+ TRI_json_t const * json = _json->json ();
336
+ if (TRI_IsArrayJson (json)) {
337
+ if (i < TRI_LengthArrayJson (json)) {
338
+ return triagens::basics::Json (TRI_UNKNOWN_MEM_ZONE, static_cast <TRI_json_t*>(TRI_AtVector (&json->_value ._objects , i)), triagens::basics::Json::NOFREE);
339
+ }
340
+ }
341
+ break ; // fall-through to exception
342
+ }
343
+
344
+ case DOCVEC: {
345
+ TRI_ASSERT (_vector != nullptr );
346
+ // calculate the result list length
347
+ size_t offset = 0 ;
348
+ for (auto it = _vector->begin (); it != _vector->end (); ++it) {
349
+ auto current = (*it);
350
+ size_t const n = current->size ();
351
+ if (offset + i < n) {
352
+ auto vecCollection = current->getDocumentCollection (0 );
353
+ return current->getValue (i - offset, 0 ).toJson (trx, vecCollection);
354
+ }
355
+ offset += (*it)->size ();
356
+ }
357
+ break ; // fall-through to exception
358
+ }
359
+
360
+ case RANGE: {
361
+ TRI_ASSERT (_range != nullptr );
362
+ return triagens::basics::Json (static_cast <double >(_range->at (i)));
363
+ }
364
+
365
+ case SHAPED:
366
+ case EMPTY: {
367
+ }
368
+ }
369
+
370
+ THROW_ARANGO_EXCEPTION (TRI_ERROR_INTERNAL);
371
+ }
372
+
299
373
// //////////////////////////////////////////////////////////////////////////////
300
374
// / @brief returns the length of an AqlValue containing an array
301
375
// //////////////////////////////////////////////////////////////////////////////
@@ -487,13 +561,13 @@ v8::Handle<v8::Value> AqlValue::toV8 (v8::Isolate* isolate,
487
561
case DOCVEC: {
488
562
TRI_ASSERT (_vector != nullptr );
489
563
490
- // calculate the result list length
564
+ // calculate the result array length
491
565
size_t totalSize = 0 ;
492
566
for (auto it = _vector->begin (); it != _vector->end (); ++it) {
493
567
totalSize += (*it)->size ();
494
568
}
495
569
496
- // allocate the result list
570
+ // allocate the result array
497
571
v8::Handle<v8::Array> result = v8::Array::New (isolate, static_cast <int >(totalSize));
498
572
uint32_t j = 0 ; // output row count
499
573
@@ -583,13 +657,13 @@ Json AqlValue::toJson (triagens::arango::AqlTransaction* trx,
583
657
case DOCVEC: {
584
658
TRI_ASSERT (_vector != nullptr );
585
659
586
- // calculate the result list length
660
+ // calculate the result array length
587
661
size_t totalSize = 0 ;
588
662
for (auto it = _vector->begin (); it != _vector->end (); ++it) {
589
663
totalSize += (*it)->size ();
590
664
}
591
665
592
- // allocate the result list
666
+ // allocate the result array
593
667
Json json (Json::Array, static_cast <size_t >(totalSize));
594
668
595
669
for (auto it = _vector->begin (); it != _vector->end (); ++it) {
@@ -755,7 +829,7 @@ Json AqlValue::extractArrayMember (triagens::arango::AqlTransaction* trx,
755
829
}
756
830
757
831
if (position >= 0 && position < static_cast <int64_t >(length)) {
758
- // only look up the value if it is within list bounds
832
+ // only look up the value if it is within array bounds
759
833
TRI_json_t const * found = TRI_LookupArrayJson (json, static_cast <size_t >(position));
760
834
761
835
if (found != nullptr ) {
@@ -784,7 +858,7 @@ Json AqlValue::extractArrayMember (triagens::arango::AqlTransaction* trx,
784
858
}
785
859
786
860
if (position >= 0 && position < static_cast <int64_t >(n)) {
787
- // only look up the value if it is within list bounds
861
+ // only look up the value if it is within array bounds
788
862
return Json (static_cast <double >(_range->at (static_cast <size_t >(position))));
789
863
}
790
864
break ; // fall-through to returning null
@@ -794,7 +868,7 @@ Json AqlValue::extractArrayMember (triagens::arango::AqlTransaction* trx,
794
868
TRI_ASSERT (_vector != nullptr );
795
869
size_t const p = static_cast <size_t >(position);
796
870
797
- // calculate the result list length
871
+ // calculate the result array length
798
872
size_t totalSize = 0 ;
799
873
for (auto it = _vector->begin (); it != _vector->end (); ++it) {
800
874
if (p < totalSize + (*it)->size ()) {
0 commit comments