コード例 #1
0
ファイル: json.cpp プロジェクト: morsdatum/ArangoDB
void TRI_Insert2ArrayJson (TRI_memory_zone_t* zone,
                           TRI_json_t* object,
                           char const* name,
                           TRI_json_t* subobject) {
  TRI_json_t copy;
  char* att;
  size_t length;

  TRI_ASSERT(object->_type == TRI_JSON_ARRAY);

  if (subobject == NULL) {
    return;
  }

  if (TRI_ReserveVector(&object->_value._objects, 2) != TRI_ERROR_NO_ERROR) {
    // TODO: signal OOM here
    return;
  }

  length = strlen(name);
  att = TRI_DuplicateString2Z(zone, name, length);

  if (att == NULL) {
    // TODO: signal OOM here
    return;
  }

  // attribute name
  InitString(&copy, att, length);
  TRI_PushBackVector(&object->_value._objects, &copy);

  // attribute value
  TRI_PushBackVector(&object->_value._objects, subobject);
}
コード例 #2
0
ファイル: json.cpp プロジェクト: m0ppers/arangodb
void TRI_Insert2ObjectJson (TRI_memory_zone_t* zone,
                           TRI_json_t* object,
                           char const* name,
                           TRI_json_t const* subobject) {
  TRI_ASSERT(object->_type == TRI_JSON_OBJECT);

  if (subobject == nullptr) {
    return;
  }

  if (TRI_ReserveVector(&object->_value._objects, 2) != TRI_ERROR_NO_ERROR) {
    // TODO: signal OOM here
    return;
  }

  size_t length = strlen(name);
  char* att = TRI_DuplicateString2Z(zone, name, length);

  if (att == nullptr) {
    // TODO: signal OOM here
    return;
  }

  // create attribute name in place
  TRI_json_t* next = static_cast<TRI_json_t*>(TRI_NextVector(&object->_value._objects));
  // we have made sure above with the reserve call that the vector has enough capacity
  TRI_ASSERT(next != nullptr);
  InitString(next, att, length);

  // attribute value
  TRI_PushBackVector(&object->_value._objects, subobject);
}
コード例 #3
0
ファイル: json.cpp プロジェクト: morsdatum/ArangoDB
void TRI_Insert4ArrayJson (TRI_memory_zone_t* zone, TRI_json_t* object, char* name, size_t nameLength, TRI_json_t* subobject, bool asReference) {
  TRI_json_t copy;

  TRI_ASSERT(name != NULL);

  // attribute name
  if (asReference) {
    InitStringReference(&copy, name, nameLength);
  }
  else {
    InitString(&copy, name, nameLength);
  }

  if (TRI_ReserveVector(&object->_value._objects, 2) != TRI_ERROR_NO_ERROR) {
    // TODO: signal OOM here
    return;
  }

  TRI_PushBackVector(&object->_value._objects, &copy);

  // attribute value
  TRI_PushBackVector(&object->_value._objects, subobject);
}