本文整理汇总了C++中BSON_ITER_HOLDS_INT32函数的典型用法代码示例。如果您正苦于以下问题:C++ BSON_ITER_HOLDS_INT32函数的具体用法?C++ BSON_ITER_HOLDS_INT32怎么用?C++ BSON_ITER_HOLDS_INT32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BSON_ITER_HOLDS_INT32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getValorDeUnaCopia_ArchivoDB
/*************************************************************************************************************************
F_SECUNDARIA: Obteniendo el VALOR dlong int IP, puerto o numBloque para una copiaX de un bloque X TESTEADO =)
****************************/
long int getValorDeUnaCopia_ArchivoDB (const bson_t * documento_X, int numBloque, int numDeCopia, char * claveRequerida)
{
bson_iter_t punteroDeBusqueda;
bson_iter_t valorEncontrado;
long int valorRequerido;
// GENERO LA CLAVE DE BUSQUEDA
//Ejemplo "Bloqlong int.IP" Bloques.numBloque.ArrayDeCopias.numDeCopia.claveRequerida (clavlong int IP o puerto o numDeBloque)
char *claveGenerada = string_new();
string_append(&claveGenerada, "Bloques");
string_append(&claveGenerada, ".");
string_append(&claveGenerada, string_itoa(numBloque));
string_append(&claveGenerada, ".copias.");
string_append(&claveGenerada, string_itoa(numDeCopia-1));
string_append(&claveGenerada, ".");
string_append(&claveGenerada, claveRequerida);
if (documento_X != NULL &&
bson_iter_init (&punteroDeBusqueda, documento_X) &&
bson_iter_find_descendant (&punteroDeBusqueda, claveGenerada, &valorEncontrado) &&
BSON_ITER_HOLDS_INT32 (&valorEncontrado))
{
valorRequerido = bson_iter_int32 (&valorEncontrado);
}
free(claveGenerada);
return valorRequerido;
}
示例2: getCantidadDeCopiasDe1Bloque_ArchivoDB
//Devuelve un num positivo o Devuelve 0 si hay error
int getCantidadDeCopiasDe1Bloque_ArchivoDB(const bson_t * documento_X, int numBloque)
{
bson_iter_t punteroDeBusqueda;
bson_iter_t valorEncontrado;
int CantidadDeCopias = 0;
char *claveGenerada = string_new();
string_append(&claveGenerada, "Bloques");
string_append(&claveGenerada, ".");
string_append(&claveGenerada, string_itoa(numBloque));
string_append(&claveGenerada, ".");
string_append(&claveGenerada, "cantidadDeCopias");
if (documento_X != NULL &&
bson_iter_init (&punteroDeBusqueda, documento_X) &&
bson_iter_find_descendant (&punteroDeBusqueda, claveGenerada, &valorEncontrado) &&
BSON_ITER_HOLDS_INT32 (&valorEncontrado))
{
CantidadDeCopias = bson_iter_int32 (&valorEncontrado);
}
free(claveGenerada);
return CantidadDeCopias;
}
示例3: test_write_concern_bson_omits_defaults
static void
test_write_concern_bson_omits_defaults (void)
{
mongoc_write_concern_t *write_concern;
const bson_t *gle;
const bson_t *bson;
bson_iter_t iter;
write_concern = mongoc_write_concern_new();
/*
* Check generated bson.
*/
ASSERT(write_concern);
gle = _mongoc_write_concern_get_gle(write_concern);
ASSERT(bson_iter_init_find(&iter, gle, "getlasterror") && BSON_ITER_HOLDS_INT32(&iter) && bson_iter_int32(&iter) == 1);
ASSERT(!bson_iter_init_find(&iter, gle, "fsync"));
ASSERT(!bson_iter_init_find(&iter, gle, "j"));
ASSERT(!bson_iter_init_find(&iter, gle, "w"));
ASSERT(gle);
bson = _mongoc_write_concern_get_bson(write_concern);
ASSERT(!bson_iter_init_find(&iter, bson, "getlasterror"));
ASSERT(!bson_iter_init_find(&iter, bson, "fsync"));
ASSERT(!bson_iter_init_find(&iter, bson, "j"));
ASSERT(!bson_iter_init_find(&iter, gle, "w"));
ASSERT(bson);
mongoc_write_concern_destroy(write_concern);
}
示例4: test_write_concern_bson_includes_false_fsync_and_journal
static void
test_write_concern_bson_includes_false_fsync_and_journal (void)
{
mongoc_write_concern_t *write_concern;
const bson_t *gle;
const bson_t *bson;
bson_iter_t iter;
write_concern = mongoc_write_concern_new();
/*
* Check generated bson.
*/
ASSERT(write_concern);
mongoc_write_concern_set_fsync(write_concern, false);
mongoc_write_concern_set_journal(write_concern, false);
gle = _mongoc_write_concern_get_gle(write_concern);
ASSERT(bson_iter_init_find(&iter, gle, "getlasterror") && BSON_ITER_HOLDS_INT32(&iter) && bson_iter_int32(&iter) == 1);
ASSERT(bson_iter_init_find(&iter, gle, "fsync") && BSON_ITER_HOLDS_BOOL(&iter) && !bson_iter_bool(&iter));
ASSERT(bson_iter_init_find(&iter, gle, "j") && BSON_ITER_HOLDS_BOOL(&iter) && !bson_iter_bool(&iter));
ASSERT(!bson_iter_init_find(&iter, gle, "w"));
ASSERT(gle);
bson = _mongoc_write_concern_get_bson(write_concern);
ASSERT(!bson_iter_init_find(&iter, bson, "getlasterror"));
ASSERT(bson_iter_init_find(&iter, bson, "fsync") && BSON_ITER_HOLDS_BOOL(&iter) && !bson_iter_bool(&iter));
ASSERT(bson_iter_init_find(&iter, bson, "j") && BSON_ITER_HOLDS_BOOL(&iter) && !bson_iter_bool(&iter));
ASSERT(!bson_iter_init_find(&iter, bson, "w"));
ASSERT(bson);
mongoc_write_concern_destroy(write_concern);
}
示例5: _mongoc_convert_validate_flags
bool
_mongoc_convert_validate_flags (mongoc_client_t *client,
const bson_iter_t *iter,
bson_validate_flags_t *flags,
bson_error_t *error)
{
if (BSON_ITER_HOLDS_BOOL (iter)) {
if (!bson_iter_as_bool (iter)) {
*flags = BSON_VALIDATE_NONE;
return true;
} else {
/* validate: false is ok but validate: true is prohibited */
CONVERSION_ERR ("Invalid option \"%s\": true, must be a bitwise-OR of"
" bson_validate_flags_t values.",
bson_iter_key (iter));
}
} else if (BSON_ITER_HOLDS_INT32 (iter)) {
if (bson_iter_int32 (iter) <= 0x1F) {
*flags = (bson_validate_flags_t) bson_iter_int32 (iter);
return true;
} else {
CONVERSION_ERR ("Invalid field \"%s\" in opts, must be a bitwise-OR of"
" bson_validate_flags_t values.",
bson_iter_key (iter));
}
}
CONVERSION_ERR ("Invalid type for option \"%s\": \"%s\"."
" \"%s\" must be a boolean or a bitwise-OR of"
" bson_validate_flags_t values.",
bson_iter_key (iter),
_mongoc_bson_type_to_str (bson_iter_type (iter)),
bson_iter_key (iter));
}
示例6: mongoc_uri_set_option_as_int32
bool
mongoc_uri_set_option_as_int32 (mongoc_uri_t *uri,
const char *option,
int32_t value)
{
const bson_t *options;
bson_iter_t iter;
BSON_ASSERT (option);
if (!mongoc_uri_option_is_int32 (option)) {
return false;
}
if ((options = mongoc_uri_get_options (uri)) &&
bson_iter_init_find_case (&iter, options, option)) {
if (BSON_ITER_HOLDS_INT32 (&iter)) {
bson_iter_overwrite_int32 (&iter, value);
return true;
} else {
return false;
}
}
bson_append_int32(&uri->options, option, -1, value);
return true;
}
示例7: test_bson_iter_overwrite_int32
static void
test_bson_iter_overwrite_int32 (void)
{
bson_iter_t iter;
bson_t b;
bson_init(&b);
assert(bson_append_int32(&b, "key", -1, 1234));
assert(bson_iter_init_find(&iter, &b, "key"));
assert(BSON_ITER_HOLDS_INT32(&iter));
bson_iter_overwrite_int32(&iter, 4321);
assert(bson_iter_init_find(&iter, &b, "key"));
assert(BSON_ITER_HOLDS_INT32(&iter));
assert_cmpint(bson_iter_int32(&iter), ==, 4321);
bson_destroy(&b);
}
示例8: _mongoc_cursor_populate_error
static void
_mongoc_cursor_populate_error (mongoc_cursor_t *cursor,
const bson_t *doc,
bson_error_t *error)
{
bson_uint32_t code = MONGOC_ERROR_QUERY_FAILURE;
bson_iter_t iter;
const char *msg = "Unknown query failure";
BSON_ASSERT (cursor);
BSON_ASSERT (doc);
BSON_ASSERT (error);
if (bson_iter_init_find (&iter, doc, "code") &&
BSON_ITER_HOLDS_INT32 (&iter)) {
code = bson_iter_int32 (&iter);
}
if (bson_iter_init_find (&iter, doc, "$err") &&
BSON_ITER_HOLDS_UTF8 (&iter)) {
msg = bson_iter_utf8 (&iter, NULL);
}
if (cursor->is_command &&
bson_iter_init_find (&iter, doc, "errmsg") &&
BSON_ITER_HOLDS_UTF8 (&iter)) {
msg = bson_iter_utf8 (&iter, NULL);
}
bson_set_error(error, MONGOC_ERROR_QUERY, code, "%s", msg);
}
示例9: test_write_concern_basic
static void
test_write_concern_basic (void)
{
mongoc_write_concern_t *write_concern;
const bson_t *b;
bson_iter_t iter;
write_concern = mongoc_write_concern_new();
/*
* Test defaults.
*/
assert(write_concern);
assert(!mongoc_write_concern_get_fsync(write_concern));
assert(!mongoc_write_concern_get_journal(write_concern));
assert(mongoc_write_concern_get_w(write_concern) == MONGOC_WRITE_CONCERN_W_DEFAULT);
assert(!mongoc_write_concern_get_wtimeout(write_concern));
assert(!mongoc_write_concern_get_wmajority(write_concern));
mongoc_write_concern_set_fsync(write_concern, TRUE);
assert(mongoc_write_concern_get_fsync(write_concern));
mongoc_write_concern_set_fsync(write_concern, FALSE);
assert(!mongoc_write_concern_get_fsync(write_concern));
mongoc_write_concern_set_journal(write_concern, TRUE);
assert(mongoc_write_concern_get_journal(write_concern));
mongoc_write_concern_set_journal(write_concern, FALSE);
assert(!mongoc_write_concern_get_journal(write_concern));
/*
* Test changes to w.
*/
mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_MAJORITY);
assert(mongoc_write_concern_get_wmajority(write_concern));
mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_DEFAULT);
assert(!mongoc_write_concern_get_wmajority(write_concern));
mongoc_write_concern_set_wmajority(write_concern, 1000);
assert(mongoc_write_concern_get_wmajority(write_concern));
assert(mongoc_write_concern_get_wtimeout(write_concern) == 1000);
mongoc_write_concern_set_wtimeout(write_concern, 0);
assert(!mongoc_write_concern_get_wtimeout(write_concern));
mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_DEFAULT);
assert(mongoc_write_concern_get_w(write_concern) == MONGOC_WRITE_CONCERN_W_DEFAULT);
mongoc_write_concern_set_w(write_concern, 3);
assert(mongoc_write_concern_get_w(write_concern) == 3);
/*
* Check generated bson.
*/
mongoc_write_concern_set_fsync(write_concern, TRUE);
mongoc_write_concern_set_journal(write_concern, TRUE);
b = _mongoc_write_concern_freeze(write_concern);
assert(bson_iter_init_find(&iter, b, "fsync") && BSON_ITER_HOLDS_BOOL(&iter) && bson_iter_bool(&iter));
assert(bson_iter_init_find(&iter, b, "j") && BSON_ITER_HOLDS_BOOL(&iter) && bson_iter_bool(&iter));
assert(bson_iter_init_find(&iter, b, "w") && BSON_ITER_HOLDS_INT32(&iter) && bson_iter_int32(&iter) == 3);
assert(b);
mongoc_write_concern_destroy(write_concern);
}
示例10: mongo_get_oauth_key
static int mongo_get_oauth_key(const u08bits *kid, oauth_key_data_raw *key) {
mongoc_collection_t * collection = mongo_get_collection("oauth_key");
if (!collection)
return -1;
bson_t query;
bson_init(&query);
BSON_APPEND_UTF8(&query, "kid", (const char *)kid);
bson_t fields;
bson_init(&fields);
BSON_APPEND_INT32(&fields, "lifetime", 1);
BSON_APPEND_INT32(&fields, "timestamp", 1);
BSON_APPEND_INT32(&fields, "as_rs_alg", 1);
BSON_APPEND_INT32(&fields, "ikm_key", 1);
mongoc_cursor_t * cursor;
cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 1, 0,
&query, &fields, NULL);
int ret = -1;
ns_bzero(key,sizeof(oauth_key_data_raw));
STRCPY(key->kid,kid);
if (!cursor) {
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,
"Error querying MongoDB collection 'oauth_key'\n");
} else {
const bson_t * item;
uint32_t length;
bson_iter_t iter;
if (mongoc_cursor_next(cursor, &item)) {
if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "as_rs_alg") && BSON_ITER_HOLDS_UTF8(&iter)) {
STRCPY(key->as_rs_alg,bson_iter_utf8(&iter, &length));
}
if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "ikm_key") && BSON_ITER_HOLDS_UTF8(&iter)) {
STRCPY(key->ikm_key,bson_iter_utf8(&iter, &length));
}
if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "timestamp") && BSON_ITER_HOLDS_INT64(&iter)) {
key->timestamp = (u64bits)bson_iter_int64(&iter);
}
if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "lifetime") && BSON_ITER_HOLDS_INT32(&iter)) {
key->lifetime = (u32bits)bson_iter_int32(&iter);
}
ret = 0;
}
mongoc_cursor_destroy(cursor);
}
mongoc_collection_destroy(collection);
bson_destroy(&query);
bson_destroy(&fields);
return ret;
}
示例11: mongoc_client_pool_new
mongoc_client_pool_t *
mongoc_client_pool_new (const mongoc_uri_t *uri)
{
mongoc_topology_t *topology;
mongoc_client_pool_t *pool;
const bson_t *b;
bson_iter_t iter;
ENTRY;
BSON_ASSERT (uri);
pool = (mongoc_client_pool_t *)bson_malloc0(sizeof *pool);
mongoc_mutex_init(&pool->mutex);
_mongoc_queue_init(&pool->queue);
pool->uri = mongoc_uri_copy(uri);
pool->min_pool_size = 0;
pool->max_pool_size = 100;
pool->size = 0;
topology = mongoc_topology_new(uri, false);
pool->topology = topology;
b = mongoc_uri_get_options(pool->uri);
if (bson_iter_init_find_case(&iter, b, "minpoolsize")) {
if (BSON_ITER_HOLDS_INT32(&iter)) {
pool->min_pool_size = BSON_MAX(0, bson_iter_int32(&iter));
}
}
if (bson_iter_init_find_case(&iter, b, "maxpoolsize")) {
if (BSON_ITER_HOLDS_INT32(&iter)) {
pool->max_pool_size = BSON_MAX(1, bson_iter_int32(&iter));
}
}
mongoc_counter_client_pools_active_inc();
RETURN(pool);
}
示例12: database_find_blockchain_transaction
int database_find_blockchain_transaction(struct database* db, unsigned char* hash, size_t max_height, struct transaction** tx, size_t* height)
{
mongoc_collection_t* collection = mongoc_client_get_collection(db->client, database_name(db), "transactions");
// Build a query doc
bson_t* query = bson_new();
// Set the hash
BSON_APPEND_BINARY(query, "hash", BSON_SUBTYPE_BINARY, (uint8_t*)hash, 32);
// Force the height to be valid (on the main chain)
bson_t* height_doc = bson_new();
BSON_APPEND_DOCUMENT_BEGIN(query, "height", height_doc);
BSON_APPEND_INT32(height_doc, "$lte", (int)max_height);
BSON_APPEND_INT32(height_doc, "$gte", 0);
bson_append_document_end(query, height_doc);
// Perform find
mongoc_cursor_t* cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
bson_error_t error;
if(cursor == NULL || mongoc_cursor_error(cursor, &error)) {
printf("MongoDB error: %s\n", (cursor == NULL) ? "NULL cursor" : error.message);
return -1;
}
bson_t const* doc;
int found = 0;
while(mongoc_cursor_next(cursor, &doc) != 0) {
if(height != NULL) {
bson_iter_t iter;
if(!bson_iter_init_find(&iter, doc, "height") || !BSON_ITER_HOLDS_INT32(&iter)) {
printf("MongoDB error: tx doesn't have height!\n");
return -1;
}
*height = (size_t)bson_iter_int32(&iter);
}
if(tx != NULL) {
*tx = transaction_from_bson(doc);
}
found = 1;
break;
}
mongoc_cursor_destroy(cursor);
bson_destroy(height_doc);
bson_destroy(query);
mongoc_collection_destroy(collection);
return found;
}
示例13: test_bson_iter_mixed
static void
test_bson_iter_mixed (void)
{
bson_iter_t iter;
bson_decimal128_t iter_value;
bson_decimal128_t value;
bson_t *b;
bson_t *b2;
b = bson_new();
b2 = bson_new();
value.high = 0;
value.low = 1;
assert(bson_append_utf8(b2, "foo", -1, "bar", -1));
assert(bson_append_code(b, "0", -1, "var a = {};"));
assert(bson_append_code_with_scope(b, "1", -1, "var b = {};", b2));
assert(bson_append_int32(b, "2", -1, 1234));
assert(bson_append_int64(b, "3", -1, 4567));
assert(bson_append_time_t(b, "4", -1, 123456));
assert(bson_append_decimal128(b, "5", -1, &value));
assert(bson_iter_init(&iter, b));
assert(bson_iter_next(&iter));
assert(BSON_ITER_HOLDS_CODE(&iter));
assert(bson_iter_next(&iter));
assert(BSON_ITER_HOLDS_CODEWSCOPE(&iter));
assert(bson_iter_next(&iter));
assert(BSON_ITER_HOLDS_INT32(&iter));
assert(bson_iter_next(&iter));
assert(BSON_ITER_HOLDS_INT64(&iter));
assert(bson_iter_next(&iter));
assert(BSON_ITER_HOLDS_DATE_TIME(&iter));
assert(bson_iter_next(&iter));
assert(BSON_ITER_HOLDS_DECIMAL128(&iter));
assert(!bson_iter_next(&iter));
assert(bson_iter_init_find(&iter, b, "3"));
assert(!strcmp(bson_iter_key(&iter), "3"));
assert(bson_iter_int64(&iter) == 4567);
assert(bson_iter_next(&iter));
assert(BSON_ITER_HOLDS_DATE_TIME(&iter));
assert(bson_iter_time_t(&iter) == 123456);
assert(bson_iter_date_time(&iter) == 123456000);
assert(bson_iter_next(&iter));
/* This test uses memcmp because libbson lacks decimal128 comparison. */
bson_iter_decimal128(&iter, &iter_value);
assert(memcmp(&iter_value, &value, sizeof(value)) == 0);
assert(!bson_iter_next(&iter));
bson_destroy(b);
bson_destroy(b2);
}
示例14: sim_parser_connect_id
static gboolean
sim_parser_connect_id (bson_iter_t *piter, const char *key, SimCommand *cmd)
{
g_return_val_if_fail (piter != NULL, FALSE);
g_return_val_if_fail (cmd != NULL, FALSE);
g_return_val_if_fail (key != NULL, FALSE);
gboolean result = FALSE;
if (BSON_ITER_HOLDS_INT32(piter))
{
cmd->id = bson_iter_int32(piter);
result = TRUE;
}
return result;
}
示例15: getCantidadTotalDeBloques_ArchivoDB
/*************************************************************************************************************************
F_SECUNDARIA: Obteniendo CANTIDAD TOTAL DE BLOQUES que conforman un Archivo TESTEADO =)
****************************/
int getCantidadTotalDeBloques_ArchivoDB(const bson_t * documento_X)
//Devuelve un num positivo o Devuelve 0 si hay error
{
bson_iter_t punteroDeBusqueda;
bson_iter_t valorEncontrado;
int CantidadBloques = 0;
if (documento_X != NULL &&
bson_iter_init (&punteroDeBusqueda, documento_X) &&
bson_iter_find_descendant (&punteroDeBusqueda, "cantidadDeBloques", &valorEncontrado) &&
BSON_ITER_HOLDS_INT32 (&valorEncontrado))
{
CantidadBloques = bson_iter_int32 (&valorEncontrado);
}
return CantidadBloques;
}