static bool ExtractDoubleArray (TRI_shaper_t* shaper, TRI_shaped_json_t const* document, TRI_shape_pid_t pid, double* result, bool* missing) { TRI_shape_t const* shape; TRI_shaped_json_t json; bool ok; *missing = false; ok = TRI_ExtractShapedJsonVocShaper(shaper, document, 0, pid, &json, &shape); if (! ok) { return false; } if (shape == NULL) { *missing = true; return false; } else if (json._sid == TRI_LookupBasicSidShaper(TRI_SHAPE_NUMBER)) { *result = * (double*) json._data.data; return true; } else if (json._sid == TRI_LookupBasicSidShaper(TRI_SHAPE_NULL)) { *missing = true; return false; } else { return false; } }
static int HashIndexHelper (TRI_hash_index_t const* hashIndex, T* hashElement, TRI_doc_mptr_t const* document) { TRI_shaper_t* shaper; // underlying shaper TRI_shaped_json_t shapedObject; // the sub-object TRI_shaped_json_t shapedJson; // the object behind document TRI_shaped_sub_t shapedSub; // the relative sub-object shaper = hashIndex->base._collection->getShaper(); // ONLY IN INDEX, PROTECTED by RUNTIME // ............................................................................. // Assign the document to the TRI_hash_index_element_t structure - so that it // can later be retreived. // ............................................................................. TRI_EXTRACT_SHAPED_JSON_MARKER(shapedJson, document->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME hashElement->_document = const_cast<TRI_doc_mptr_t*>(document); char const* ptr = document->getShapedJsonPtr(); // ONLY IN INDEX // ............................................................................. // Extract the attribute values // ............................................................................. int res = TRI_ERROR_NO_ERROR; size_t const n = NumPaths(hashIndex); for (size_t j = 0; j < n; ++j) { TRI_shape_pid_t path = *((TRI_shape_pid_t*)(TRI_AtVector(&hashIndex->_paths, j))); // determine if document has that particular shape TRI_shape_access_t const* acc = TRI_FindAccessorVocShaper(shaper, shapedJson._sid, path); // field not part of the object if (acc == nullptr || acc->_resultSid == TRI_SHAPE_ILLEGAL) { shapedSub._sid = TRI_LookupBasicSidShaper(TRI_SHAPE_NULL); shapedSub._length = 0; shapedSub._offset = 0; res = TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING; } // extract the field else { if (! TRI_ExecuteShapeAccessor(acc, &shapedJson, &shapedObject)) { // hashElement->fields: memory deallocated in the calling procedure return TRI_ERROR_INTERNAL; } if (shapedObject._sid == TRI_LookupBasicSidShaper(TRI_SHAPE_NULL)) { res = TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING; } shapedSub._sid = shapedObject._sid; shapedSub._length = shapedObject._data.length; shapedSub._offset = static_cast<uint32_t>(((char const*) shapedObject._data.data) - ptr); } // store the json shaped sub-object -- this is what will be hashed hashElement->_subObjects[j] = shapedSub; } return res; }
static bool ExtractDoubleList (TRI_shaper_t* shaper, TRI_shaped_json_t const* document, TRI_shape_pid_t pid, double* latitude, double* longitude, bool* missing) { TRI_shape_t const* shape; TRI_shaped_json_t entry; TRI_shaped_json_t list; bool ok; size_t len; *missing = false; ok = TRI_ExtractShapedJsonVocShaper(shaper, document, 0, pid, &list, &shape); if (! ok) { return false; } if (shape == NULL) { *missing = true; return false; } // in-homogenous list if (shape->_type == TRI_SHAPE_LIST) { len = TRI_LengthListShapedJson((const TRI_list_shape_t*) shape, &list); if (len < 2) { return false; } // latitude ok = TRI_AtListShapedJson((const TRI_list_shape_t*) shape, &list, 0, &entry); if (! ok || entry._sid != TRI_LookupBasicSidShaper(TRI_SHAPE_NUMBER)) { return false; } *latitude = * (double*) entry._data.data; // longitude ok = TRI_AtListShapedJson((const TRI_list_shape_t*) shape, &list, 1, &entry); if (! ok || entry._sid != TRI_LookupBasicSidShaper(TRI_SHAPE_NUMBER)) { return false; } *longitude = * (double*) entry._data.data; return true; } // homogenous list else if (shape->_type == TRI_SHAPE_HOMOGENEOUS_LIST) { const TRI_homogeneous_list_shape_t* hom; hom = (const TRI_homogeneous_list_shape_t*) shape; if (hom->_sidEntry != TRI_LookupBasicSidShaper(TRI_SHAPE_NUMBER)) { return false; } len = TRI_LengthHomogeneousListShapedJson((const TRI_homogeneous_list_shape_t*) shape, &list); if (len < 2) { return false; } // latitude ok = TRI_AtHomogeneousListShapedJson((const TRI_homogeneous_list_shape_t*) shape, &list, 0, &entry); if (! ok) { return false; } *latitude = * (double*) entry._data.data; // longitude ok = TRI_AtHomogeneousListShapedJson((const TRI_homogeneous_list_shape_t*) shape, &list, 1, &entry); if (! ok) { return false; } *longitude = * (double*) entry._data.data; return true; } // homogeneous list else if (shape->_type == TRI_SHAPE_HOMOGENEOUS_SIZED_LIST) { const TRI_homogeneous_sized_list_shape_t* hom; hom = (const TRI_homogeneous_sized_list_shape_t*) shape; if (hom->_sidEntry != TRI_LookupBasicSidShaper(TRI_SHAPE_NUMBER)) { return false; } len = TRI_LengthHomogeneousSizedListShapedJson((const TRI_homogeneous_sized_list_shape_t*) shape, &list); if (len < 2) { return false; } // latitude ok = TRI_AtHomogeneousSizedListShapedJson((const TRI_homogeneous_sized_list_shape_t*) shape, &list, 0, &entry); if (! ok) { return false; } *latitude = * (double*) entry._data.data; // longitude ok = TRI_AtHomogeneousSizedListShapedJson((const TRI_homogeneous_sized_list_shape_t*) shape, &list, 1, &entry); if (! ok) { return false; } *longitude = * (double*) entry._data.data; return true; } // null else if (shape->_type == TRI_SHAPE_NULL) { *missing = true; } // ups return false; }