当前位置: 首页>>代码示例>>C++>>正文


C++ TRI_AtVector函数代码示例

本文整理汇总了C++中TRI_AtVector函数的典型用法代码示例。如果您正苦于以下问题:C++ TRI_AtVector函数的具体用法?C++ TRI_AtVector怎么用?C++ TRI_AtVector使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TRI_AtVector函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TRI_LookupArrayJson

TRI_json_t* TRI_LookupArrayJson (const TRI_json_t* const object, char const* name) {
  size_t i, n;

  if (object == NULL) {
    return NULL;
  }

  TRI_ASSERT(object->_type == TRI_JSON_ARRAY);
  TRI_ASSERT(name != NULL);

  n = object->_value._objects._length;

  for (i = 0;  i < n;  i += 2) {
    TRI_json_t* key;

    key = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i);

    if (! IsString(key)) {
      continue;
    }

    if (TRI_EqualString(key->_value._string.data, name)) {
      return (TRI_json_t*) TRI_AtVector(&object->_value._objects, i + 1);
    }
  }

  return NULL;
}
开发者ID:morsdatum,项目名称:ArangoDB,代码行数:28,代码来源:json.cpp

示例2: MergeRecursive

static TRI_json_t* MergeRecursive (TRI_memory_zone_t* zone,
                                   const TRI_json_t* const lhs,
                                   const TRI_json_t* const rhs,
                                   const bool nullMeansRemove) {
  size_t i, n;

  TRI_json_t* result = TRI_CopyJson(zone, lhs);

  if (result == NULL) {
    return NULL;
  }

  n = rhs->_value._objects._length;
  for (i = 0; i < n; i += 2) {
    // enumerate all the replacement values
    TRI_json_t* key = TRI_AtVector(&rhs->_value._objects, i);
    TRI_json_t* value = TRI_AtVector(&rhs->_value._objects, i + 1);

    if (value->_type == TRI_JSON_NULL && nullMeansRemove) {
      // replacement value is a null and we don't want to store nulls => delete attribute from the result
      TRI_DeleteArrayJson(zone, result, key->_value._string.data);
    }
    else {
      // replacement value is not a null or we want to store nulls
      TRI_json_t* lhsValue = TRI_LookupArrayJson(lhs, key->_value._string.data);

      if (lhsValue == NULL) {
        // existing array does not have the attribute => append new attribute
        if (value->_type == TRI_JSON_ARRAY) {
          TRI_json_t* empty = TRI_CreateArrayJson(zone);
          TRI_json_t* merged = MergeRecursive(zone, empty, value, nullMeansRemove);
          TRI_Insert3ArrayJson(zone, result, key->_value._string.data, merged);

          TRI_FreeJson(zone, empty);
        }
        else {
          TRI_Insert3ArrayJson(zone, result, key->_value._string.data, TRI_CopyJson(zone, value));
        }
      }
      else {
        // existing array already has the attribute => replace attribute
        if (lhsValue->_type == TRI_JSON_ARRAY && value->_type == TRI_JSON_ARRAY) {
          TRI_json_t* merged = MergeRecursive(zone, lhsValue, value, nullMeansRemove);
          TRI_ReplaceArrayJson(zone, result, key->_value._string.data, merged);
          TRI_FreeJson(zone, merged);
        }
        else {
          TRI_ReplaceArrayJson(zone, result, key->_value._string.data, value);
        }
      }
    }

  }

  return result;
}
开发者ID:bdacode,项目名称:ArangoDB,代码行数:56,代码来源:json-utilities.c

示例3: TRI_CopyToJson

int TRI_CopyToJson (TRI_memory_zone_t* zone,
                    TRI_json_t* dst,
                    TRI_json_t const* src) {
  int res;
  size_t n;
  size_t i;

  dst->_type = src->_type;

  switch (src->_type) {
    case TRI_JSON_UNUSED:
    case TRI_JSON_NULL:
      break;

    case TRI_JSON_BOOLEAN:
      dst->_value._boolean = src->_value._boolean;
      break;

    case TRI_JSON_NUMBER:
      dst->_value._number = src->_value._number;
      break;

    case TRI_JSON_STRING:
      return TRI_CopyToBlob(zone, &dst->_value._string, &src->_value._string);

    case TRI_JSON_STRING_REFERENCE:
      return TRI_AssignToBlob(zone, &dst->_value._string, &src->_value._string);

    case TRI_JSON_ARRAY:
    case TRI_JSON_LIST:
      n = src->_value._objects._length;

      TRI_InitVector(&dst->_value._objects, zone, sizeof(TRI_json_t));
      res = TRI_ResizeVector(&dst->_value._objects, n);

      if (res != TRI_ERROR_NO_ERROR) {
        return res;
      }

      for (i = 0;  i < n;  ++i) {
        TRI_json_t const* v = static_cast<TRI_json_t const*>(TRI_AtVector(&src->_value._objects, i));
        TRI_json_t* w = static_cast<TRI_json_t*>(TRI_AtVector(&dst->_value._objects, i));

        res = TRI_CopyToJson(zone, w, v);

        if (res != TRI_ERROR_NO_ERROR) {
          return res;
        }
      }

      break;
  }

  return TRI_ERROR_NO_ERROR;
}
开发者ID:morsdatum,项目名称:ArangoDB,代码行数:55,代码来源:json.cpp

示例4: TRI_DestroyJson

void TRI_DestroyJson (TRI_memory_zone_t* zone, TRI_json_t* object) {
  switch (object->_type) {
    case TRI_JSON_UNUSED:
    case TRI_JSON_NULL:
    case TRI_JSON_BOOLEAN:
    case TRI_JSON_NUMBER:
      break;

    case TRI_JSON_STRING:
      TRI_DestroyBlob(zone, &object->_value._string);
      break;

    case TRI_JSON_STRING_REFERENCE:
      // we will not be destroying the string!!
      break;

    case TRI_JSON_ARRAY:
    case TRI_JSON_LIST: {
      size_t i, n;
      n = object->_value._objects._length;

      for (i = 0;  i < n;  ++i) {
        TRI_json_t* v = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i);
        TRI_DestroyJson(zone, v);
      }

      TRI_DestroyVector(&object->_value._objects);
      break;
    }
  }
}
开发者ID:morsdatum,项目名称:ArangoDB,代码行数:31,代码来源:json.cpp

示例5: TRI_UniquifyArrayJson

TRI_json_t* TRI_UniquifyArrayJson (TRI_json_t const* array) {
    TRI_ASSERT(array != nullptr);
    TRI_ASSERT(array->_type == TRI_JSON_ARRAY);

    // create result array
    std::unique_ptr<TRI_json_t> result(TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE));

    if (result == nullptr) {
        return nullptr;
    }

    size_t const n = TRI_LengthVector(&array->_value._objects);

    TRI_json_t const* last = nullptr;
    for (size_t i = 0; i < n; ++i) {
        auto p = static_cast<TRI_json_t const*>(TRI_AtVector(&array->_value._objects, i));

        // don't push value if it is the same as the last value
        if (last == nullptr || TRI_CompareValuesJson(p, last, false) != 0) {
            TRI_PushBackArrayJson(TRI_UNKNOWN_MEM_ZONE, result.get(), p);

            // remember last element
            last = p;
        }
    }

    return result.release();
}
开发者ID:janavolkova9,项目名称:arangodb,代码行数:28,代码来源:json-utilities.cpp

示例6: CheckAndLockCompaction

static bool CheckAndLockCompaction (TRI_vocbase_t* vocbase) {
  double now;
  size_t i, n;

  now = TRI_microtime();
 
  // check if we can acquire the write lock instantly
  if (! TryLockCompaction(vocbase)) {
    // couldn't acquire the write lock
    return false;
  }

  // we are now holding the write lock

  // check if we have a still-valid compaction blocker
  n = vocbase->_compactionBlockers._data._length;
  for (i = 0; i < n; ++i) {
    compaction_blocker_t* blocker = TRI_AtVector(&vocbase->_compactionBlockers._data, i);

    if (blocker->_expires > now) {
      // found a compaction blocker. unlock and return
      UnlockCompaction(vocbase);
      return false;
    }
  }

  return true;
}
开发者ID:FikiHafana,项目名称:ArangoDB,代码行数:28,代码来源:compactor.c

示例7: TRI_TouchBlockerCompactorVocBase

int TRI_TouchBlockerCompactorVocBase (TRI_vocbase_t* vocbase,
                                      TRI_voc_tick_t id,
                                      double lifetime) {
  size_t i, n;
  bool found;

  found = false;
  
  if (lifetime <= 0.0) {
    return TRI_ERROR_BAD_PARAMETER;
  }
  
  LockCompaction(vocbase);

  n = vocbase->_compactionBlockers._data._length;

  for (i = 0; i < n; ++i) {
    compaction_blocker_t* blocker = TRI_AtVector(&vocbase->_compactionBlockers._data, i);

    if (blocker->_id == id) {
      blocker->_expires = TRI_microtime() + lifetime;
      found = true;
      break;
    }
  }

  UnlockCompaction(vocbase);  

  if (! found) {
    return TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND;
  }

  return TRI_ERROR_NO_ERROR;
}
开发者ID:FikiHafana,项目名称:ArangoDB,代码行数:34,代码来源:compactor.c

示例8: TRI_CleanupCompactorVocBase

bool TRI_CleanupCompactorVocBase (TRI_vocbase_t* vocbase) {
  double now;
  size_t i, n;

  now = TRI_microtime();
  
  // check if we can instantly acquire the lock
  if (! TryLockCompaction(vocbase)) {
    // couldn't acquire lock
    return false;
  }

  // we are now holding the write lock

  n = vocbase->_compactionBlockers._data._length;
 
  i = 0;
  while (i < n) {
    compaction_blocker_t* blocker = TRI_AtVector(&vocbase->_compactionBlockers._data, i);

    if (blocker->_expires < now) {
      TRI_RemoveVector(&vocbase->_compactionBlockers._data, i);
      n--;
    }
    else {
      i++;
    }
  }

  UnlockCompaction(vocbase);

  return true;
}
开发者ID:FikiHafana,项目名称:ArangoDB,代码行数:33,代码来源:compactor.c

示例9: TRI_RemoveBlockerCompactorVocBase

int TRI_RemoveBlockerCompactorVocBase (TRI_vocbase_t* vocbase,
                                       TRI_voc_tick_t id) {
  size_t i, n;
  bool found;

  found = false;

  LockCompaction(vocbase);  

  n = vocbase->_compactionBlockers._data._length;

  for (i = 0; i < n; ++i) {
    compaction_blocker_t* blocker = TRI_AtVector(&vocbase->_compactionBlockers._data, i);

    if (blocker->_id == id) {
      TRI_RemoveVector(&vocbase->_compactionBlockers._data, i);
      found = true;
      break;
    }
  }
  
  UnlockCompaction(vocbase);  
  
  if (! found) {
    return TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND;
  }

  return TRI_ERROR_NO_ERROR;
}
开发者ID:FikiHafana,项目名称:ArangoDB,代码行数:29,代码来源:compactor.c

示例10: TRI_AddParameterValuesAql

bool TRI_AddParameterValuesAql (TRI_aql_context_t* const context,
                                const TRI_json_t* const parameters) {
  size_t i;
  size_t n;

  assert(context);

  if (parameters == NULL) {
    // no bind parameters, direclty return
    return true;
  }

  if (parameters->_type != TRI_JSON_ARRAY) {
    // parameters must be a list
    TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_BIND_PARAMETERS_INVALID, NULL);
    return false;
  }

  n = parameters->_value._objects._length;
  if (n == 0) {
    // empty list, this is ok
    return true;
  }

  for (i = 0; i < n; i += 2) {
    TRI_json_t* name = TRI_AtVector(&parameters->_value._objects, i);
    TRI_json_t* value = TRI_AtVector(&parameters->_value._objects, i + 1);
    TRI_aql_bind_parameter_t* parameter;

    assert(TRI_IsStringJson(name));
    assert(value);

    parameter = CreateParameter(name->_value._string.data, 
                                name->_value._string.length - 1,
                                value);

    if (parameter == NULL) {
      TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);

      return false;
    }

    TRI_InsertKeyAssociativePointer(&context->_parameters._values, parameter->_name, parameter, false);
  }

  return true;
}
开发者ID:FikiHafana,项目名称:ArangoDB,代码行数:47,代码来源:ahuacatl-bind-parameter.c

示例11: GetAt

static TRI_general_cursor_row_t GetAt (TRI_general_cursor_result_t const* result,
                                       const TRI_general_cursor_length_t n) {
  TRI_json_t* json = (TRI_json_t*) result->_data;

  TRI_ASSERT(json);

  return (TRI_general_cursor_row_t*) TRI_AtVector(&json->_value._objects, (size_t) n);
}
开发者ID:bdacode,项目名称:ArangoDB,代码行数:8,代码来源:ahuacatl-result.cpp

示例12: GetMergedKeyList

static TRI_json_t* GetMergedKeyList (const TRI_json_t* const lhs,
                                     const TRI_json_t* const rhs) {
  TRI_json_t* keys;
  TRI_json_t* unique;
  size_t i, n;

  TRI_ASSERT(lhs->_type == TRI_JSON_ARRAY);
  TRI_ASSERT(rhs->_type == TRI_JSON_ARRAY);

  keys = TRI_CreateList2Json(TRI_UNKNOWN_MEM_ZONE,
                             lhs->_value._objects._length + rhs->_value._objects._length);

  if (keys == NULL) {
    return NULL;
  }

  n = lhs->_value._objects._length;

  for (i = 0 ; i < n; i += 2) {
    TRI_json_t* key = TRI_AtVector(&lhs->_value._objects, i);

    TRI_ASSERT(TRI_IsStringJson(key));
    TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, keys, key);
  }


  n = rhs->_value._objects._length;

  for (i = 0 ; i < n; i += 2) {
    TRI_json_t* key = TRI_AtVector(&rhs->_value._objects, i);

    TRI_ASSERT(TRI_IsStringJson(key));
    TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, keys, key);
  }

  // sort the key list in place
  TRI_SortListJson(keys);

  // list is now sorted
  unique = TRI_UniquifyListJson(keys);

  TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, keys);

  return unique; // might be NULL
}
开发者ID:bdacode,项目名称:ArangoDB,代码行数:45,代码来源:json-utilities.c

示例13: GetMergedKeyArray

static TRI_json_t* GetMergedKeyArray (TRI_json_t const* lhs,
                                      TRI_json_t const* rhs) {
    TRI_ASSERT(lhs->_type == TRI_JSON_OBJECT);
    TRI_ASSERT(rhs->_type == TRI_JSON_OBJECT);

    size_t n = TRI_LengthVector(&lhs->_value._objects) + TRI_LengthVector(&rhs->_value._objects);

    std::unique_ptr<TRI_json_t> keys(TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE, n));

    if (keys == nullptr) {
        return nullptr;
    }

    if (TRI_CapacityVector(&(keys.get()->_value._objects)) < n) {
        return nullptr;
    }

    n = TRI_LengthVector(&lhs->_value._objects);

    for (size_t i = 0 ; i < n; i += 2) {
        auto key = static_cast<TRI_json_t const*>(TRI_AtVector(&lhs->_value._objects, i));

        TRI_ASSERT(TRI_IsStringJson(key));
        TRI_PushBackArrayJson(TRI_UNKNOWN_MEM_ZONE, keys.get(), key);
    }


    n = TRI_LengthVector(&rhs->_value._objects);

    for (size_t i = 0 ; i < n; i += 2) {
        auto key = static_cast<TRI_json_t const*>(TRI_AtVector(&rhs->_value._objects, i));

        TRI_ASSERT(TRI_IsStringJson(key));
        TRI_PushBackArrayJson(TRI_UNKNOWN_MEM_ZONE, keys.get(), key);
    }

    // sort the key array in place
    TRI_SortArrayJson(keys.get());

    // array is now sorted
    return TRI_UniquifyArrayJson(keys.get());
}
开发者ID:janavolkova9,项目名称:arangodb,代码行数:42,代码来源:json-utilities.cpp

示例14: TRI_DeleteArrayJson

bool TRI_DeleteArrayJson (TRI_memory_zone_t* zone, TRI_json_t* object, char const* name) {
  size_t n;
  size_t i;

  TRI_ASSERT(object->_type == TRI_JSON_ARRAY);
  TRI_ASSERT(name);

  n = object->_value._objects._length;

  for (i = 0;  i < n;  i += 2) {
    TRI_json_t* key;

    key = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i);

    if (! IsString(key)) {
      continue;
    }

    if (TRI_EqualString(key->_value._string.data, name)) {
      TRI_json_t* old;

      // remove key
      old = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i);
      if (old != NULL) {
        TRI_DestroyJson(zone, old);
      }
      TRI_RemoveVector(&object->_value._objects, i);

      // remove value
      old = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i);
      if (old != NULL) {
        TRI_DestroyJson(zone, old);
      }
      TRI_RemoveVector(&object->_value._objects, i);

      return true;
    }
  }

  return false;
}
开发者ID:morsdatum,项目名称:ArangoDB,代码行数:41,代码来源:json.cpp

示例15: TRI_LookupArrayJson

TRI_json_t* TRI_LookupArrayJson (TRI_json_t const* array, size_t pos) {
  TRI_ASSERT(array->_type == TRI_JSON_ARRAY);

  size_t const n = TRI_LengthVector(&array->_value._objects);

  if (pos >= n) {
    // out of bounds
    return nullptr;
  }

  return static_cast<TRI_json_t*>(TRI_AtVector(&array->_value._objects, pos));
}
开发者ID:m0ppers,项目名称:arangodb,代码行数:12,代码来源:json.cpp


注:本文中的TRI_AtVector函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。