• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ json_incref函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: incref_and_decref

void incref_and_decref()
{
    json_t *obj = json_object();
    json_t *jay = json_string("周杰伦");
    json_object_set_new(obj, "name", jay);

    json_t *albums = json_array();
    json_t *alb1 = json_object();
    json_object_set_new(alb1, "name", json_string("范特西"));
    json_object_set_new(alb1, "year", json_string("2001"));
    json_array_append_new(albums, alb1);
    json_t *alb2 = json_object();
    json_object_set_new(alb2, "name", json_string("八度空间"));
    json_object_set_new(alb2, "year", json_string("2002"));
    json_array_append_new(albums, alb2);
    json_object_set_new(obj, "albums", albums);

    json_t *tmp = json_object_get(obj, "name");
    json_incref(tmp);

    json_t *arr = json_object_get(obj, "albums");
    json_t *ele = json_array_get(arr, 1);
    json_incref(arr);
    json_incref(ele);

    json_decref(obj);
    json_decref(tmp);
    json_decref(ele);
    json_decref(arr);
}
开发者ID:chenrushan,项目名称:code-snippets,代码行数:30,代码来源:json_usage.c


示例2: cfg_get_bool

// Compute the effective value of the root_files configuration and
// return a json reference.  The caller must decref the ref when done
// (we may synthesize this value).   Sets enforcing to indicate whether
// we will only allow watches on the root_files.
// The array returned by this function (if not NULL) is guaranteed to
// list .watchmanconfig as its zeroth element.
json_t *cfg_compute_root_files(bool *enforcing) {
  json_t *ref;

  // This is completely undocumented and will go away soon. Do not document or
  // use!
  bool ignore_watchmanconfig = cfg_get_bool(NULL, "_ignore_watchmanconfig",
                                            false);

  *enforcing = false;

  ref = cfg_get_json(NULL, "enforce_root_files");
  if (ref) {
    if (!json_is_boolean(ref)) {
      w_log(W_LOG_FATAL,
          "Expected config value enforce_root_files to be boolean\n");
    }
    *enforcing = json_is_true(ref);
  }

  ref = cfg_get_json(NULL, "root_files");
  if (ref) {
    if (!is_array_of_strings(ref)) {
      w_log(W_LOG_FATAL,
          "global config root_files must be an array of strings\n");
      *enforcing = false;
      return NULL;
    }
    prepend_watchmanconfig_to_array(ref);

    json_incref(ref);
    return ref;
  }

  // Try legacy root_restrict_files configuration
  ref = cfg_get_json(NULL, "root_restrict_files");
  if (ref) {
    if (!is_array_of_strings(ref)) {
      w_log(W_LOG_FATAL, "deprecated global config root_restrict_files "
          "must be an array of strings\n");
      *enforcing = false;
      return NULL;
    }
    if (!ignore_watchmanconfig) {
      prepend_watchmanconfig_to_array(ref);
    }
    json_incref(ref);
    *enforcing = true;
    return ref;
  }

  // Synthesize our conservative default value.
  // .watchmanconfig MUST be first
  if (!ignore_watchmanconfig) {
    return json_pack("[ssss]", ".watchmanconfig", ".hg", ".git", ".svn");
  } else {
    return json_pack("[sss]", ".hg", ".git", ".svn");
  }
}
开发者ID:exponentjs,项目名称:watchman,代码行数:64,代码来源:cfg.c


示例3: dispatch_command

bool dispatch_command(struct watchman_client *client, json_t *args, int mode)
{
  struct watchman_command_handler_def *def;
  char *errmsg = NULL;
  bool result = false;
  char sample_name[128];

  // Stash a reference to the current command to make it easier to log
  // the command context in some of the error paths
  client->current_command = args;
  json_incref(client->current_command);

  def = lookup(args, &errmsg, mode);

  if (!def) {
    send_error_response(client, "%s", errmsg);
    goto done;
  }

  if (poisoned_reason && (def->flags & CMD_POISON_IMMUNE) == 0) {
    send_error_response(client, "%s", poisoned_reason);
    goto done;
  }

  if (!client->client_is_owner && (def->flags & CMD_ALLOW_ANY_USER) == 0) {
    send_error_response(client, "you must be the process owner to execute '%s'",
                        def->name);
    return false;
  }

  w_log(W_LOG_DBG, "dispatch_command: %s\n", def->name);
  snprintf(sample_name, sizeof(sample_name), "dispatch_command:%s", def->name);
  w_perf_start(&client->perf_sample, sample_name);
  w_perf_set_wall_time_thresh(
      &client->perf_sample,
      cfg_get_double(NULL, "slow_command_log_threshold_seconds", 1.0));

  result = true;
  def->func(client, args);

  if (w_perf_finish(&client->perf_sample)) {
    json_incref(args);
    w_perf_add_meta(&client->perf_sample, "args", args);
    w_perf_log(&client->perf_sample);
  } else {
    w_log(W_LOG_DBG, "dispatch_command: %s (completed)\n", def->name);
  }

done:
  free(errmsg);
  json_decref(client->current_command);
  client->current_command = NULL;
  w_perf_destroy(&client->perf_sample);
  return result;
}
开发者ID:1514louluo,项目名称:watchman,代码行数:55,代码来源:reg.c


示例4: json_incref

void JsonApi::buildJsonState(json_t *jroot, std::function<void(json_t *)> result_lambda)
{
    json_incref(jroot);
    json_t *jinputs = json_object();
    json_t *joutputs = json_object();
    json_t *jaudio = json_array();

    json_t *jin = json_object_get(jroot, "inputs");
    if (jin && json_is_array(jin))
    {
        uint idx;
        json_t *value;

        json_array_foreach(jin, idx, value)
        {
            string svalue;

            if (!json_is_string(value)) continue;

            svalue = json_string_value(value);
            Input *input = ListeRoom::Instance().get_input(svalue);
            if (input)
            {
                if (input->get_type() == TBOOL)
                    json_object_set_new(jinputs, svalue.c_str(), json_string(input->get_value_bool()?"true":"false"));
                else if (input->get_type() == TINT)
                    json_object_set_new(jinputs, svalue.c_str(), json_string(Utils::to_string(input->get_value_double()).c_str()));
                else if (input->get_type() == TSTRING)
                    json_object_set_new(jinputs, svalue.c_str(), json_string(input->get_value_string().c_str()));
            }
        }
开发者ID:choovin,项目名称:calaos_base,代码行数:31,代码来源:JsonApi.cpp


示例5: data

Json::Json( json_t *rhd ): data(rhd)
{
	if ( data == NULL )
		data = json_null();
	else
		json_incref( data );
}
开发者ID:kibae,项目名称:defer.io,代码行数:7,代码来源:JSON.cpp


示例6: SCOPED_JSON_LOCK

struct ast_json *ast_json_ref(struct ast_json *json)
{
	/* Jansson refcounting is non-atomic; lock it. */
	SCOPED_JSON_LOCK(json);
	json_incref((json_t *)json);
	return json;
}
开发者ID:huangjingpei,项目名称:asterisk,代码行数:7,代码来源:json.c


示例7: send_error_response

void send_error_response(struct watchman_client *client,
    const char *fmt, ...)
{
  char buf[WATCHMAN_NAME_MAX];
  va_list ap;
  json_t *resp = make_response();
  json_t *errstr;

  va_start(ap, fmt);
  vsnprintf(buf, sizeof(buf), fmt, ap);
  va_end(ap);

  errstr = typed_string_to_json(buf, W_STRING_MIXED);
  set_prop(resp, "error", errstr);

  json_incref(errstr);
  w_perf_add_meta(&client->perf_sample, "error", errstr);

  if (client->current_command) {
    char *command = NULL;
    command = json_dumps(client->current_command, 0);
    w_log(W_LOG_ERR, "send_error_response: %s failed: %s\n",
        command, buf);
    free(command);
  } else {
    w_log(W_LOG_ERR, "send_error_response: %s\n", buf);
  }

  send_and_dispose_response(client, resp);
}
开发者ID:arnonhongklay,项目名称:watchman,代码行数:30,代码来源:listener.c


示例8: throw

MltRuntime::MltRuntime(json_t* script_serialed, int give) throw(Exception):
	json_version(0),
	producer_version(0),
	json_serialize(NULL),
	producer(NULL),
	consumer(NULL),
	status(StatusCreated)
{
	if ( !script_serialed || !json_is_object(script_serialed)
			|| !json_object_size(script_serialed)) {
		if ( give && script_serialed ) json_decref(script_serialed);
		throw_error_v(ErrorImplError,"Init MltRuntime with empty json");
	}
	if (give)
		json_serialize = script_serialed;
	else
		json_serialize = json_incref(script_serialed);

	try {
		parse_struct(json_serialize, JsonPath(), uuid_pathmap);
	}
	catch(Exception& e)
	{
		if (give && json_serialize) json_decref(json_serialize);
		throw;
	}
	json_version++;
	pthread_mutex_init(&run_lock,NULL);
}
开发者ID:amongll,项目名称:AVFX,代码行数:29,代码来源:VEditMltRun.cpp


示例9: json_decref

	inline Json &operator=(const Json &from)
	{
		if (json)
			json_decref(json);
		json = json_incref(from.json);
		return *this;
	}
开发者ID:AmesianX,项目名称:obs-studio,代码行数:7,代码来源:win-update-helpers.hpp


示例10: Json

Json Json::get(const std::string& key) const {
   if (isObject()) { 
      return Json(json_incref(json_object_get(m_json, key.c_str())));
   } else { 
      throw std::domain_error("This method only applies to object type");
   }
}
开发者ID:KrugerHeavyIndustries,项目名称:blazer,代码行数:7,代码来源:jsoncpp.cpp


示例11: json_array

json_t *tr_cfg_files_to_json_array(TR_CFG *cfg)
{
  guint ii;
  json_t *jarray = json_array();
  json_t *retval = NULL;

  if (jarray == NULL)
    goto cleanup;

  for (ii=0; ii<cfg->files->len; ii++) {
    ARRAY_APPEND_OR_FAIL(jarray,
                         tr_cfg_file_to_json(
                             &g_array_index(cfg->files, TR_CFG_FILE, ii)));
  }

  /* success */
  retval = jarray;
  json_incref(retval);

cleanup:
  if (jarray)
    json_decref(jarray);

  return retval;
}
开发者ID:janetuk,项目名称:trust_router,代码行数:25,代码来源:tr_config_encoders.c


示例12: jsonToAny

static cxJson jsonToAny(json_t *v)
{
    CX_RETURN(v == NULL,NULL);
    cxJson rv = CX_CREATE(cxJson);
    rv->json = json_incref(v);
    return rv;
}
开发者ID:fuguelike,项目名称:cxEngine,代码行数:7,代码来源:cxJson.c


示例13: Native_json_object_iter_value

//native Handle:json_object_iter_value(Handle:hIter, String:sValueBuffer[], maxlength);
static cell_t Native_json_object_iter_value(IPluginContext *pContext, const cell_t *params) {
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

	// Param 1
    void *iter;
	Handle_t hndlIterator = static_cast<Handle_t>(params[1]);
	if ((err=g_pHandleSys->ReadHandle(hndlIterator, htJanssonIterator, &sec, (void **)&iter)) != HandleError_None)
    {
        pContext->ThrowNativeError("Invalid <JSON Iterator> handle %x (error %d)", hndlIterator, err);
        return BAD_HANDLE;
    }

    json_t *result = json_object_iter_value(iter);

	// Return
	if(result == NULL) {
		return BAD_HANDLE;
	}

	Handle_t hndlResult = g_pHandleSys->CreateHandle(htJanssonObject, result, pContext->GetIdentity(), myself->GetIdentity(), NULL);
	if(hndlResult == BAD_HANDLE) {
		pContext->ThrowNativeError("Could not create handle for iterator element.");
		return BAD_HANDLE;
	}

	// result is a borrowed reference, we don't know what will happen with it
	// so we increase the reference counter, which enforces the developer to
	// CloseHandle() it.
	json_incref(result);

	return hndlResult;
}
开发者ID:alldroll,项目名称:SMJansson,代码行数:36,代码来源:extension.cpp


示例14: json_incref

flux_kvsdir_t *kvsdir_create_fromobj (flux_t *handle, const char *rootref,
                                      const char *key, json_t *treeobj)
{
    flux_kvsdir_t *dir = NULL;

    if (!key || !treeobj || treeobj_validate (treeobj) < 0
                         || !treeobj_is_dir (treeobj)) {
        errno = EINVAL;
        goto error;
    }
    if (!(dir = calloc (1, sizeof (*dir))))
        goto error;

    dir->handle = handle;
    if (rootref) {
        if (!(dir->rootref = strdup (rootref)))
            goto error;
    }
    if (!(dir->key = strdup (key)))
        goto error;
    dir->dirobj = json_incref (treeobj);
    dir->usecount = 1;

    return dir;
error:
    flux_kvsdir_destroy (dir);
    return NULL;
}
开发者ID:flux-framework,项目名称:flux-core,代码行数:28,代码来源:kvs_dir.c


示例15: _cjose_jwe_build_hdr

static bool _cjose_jwe_build_hdr(
        cjose_jwe_t *jwe, 
        cjose_header_t *header,
        cjose_err *err)
{
    // save header object as part of the JWE (and incr. refcount)
    jwe->hdr = header;
    json_incref(jwe->hdr);

    // serialize the header
    char *hdr_str = json_dumps(header, JSON_ENCODE_ANY | JSON_PRESERVE_ORDER);
    if (NULL == hdr_str)
    {
        CJOSE_ERROR(err, CJOSE_ERR_NO_MEMORY);
        return false;
    }

    // copy the serialized header to JWE (hdr_str is owned by header object)
    jwe->part[0].raw = (uint8_t *)strdup(hdr_str);
    if (NULL == jwe->part[0].raw)
    {
        CJOSE_ERROR(err, CJOSE_ERR_NO_MEMORY);
        cjose_get_dealloc()(hdr_str);
        return false;
    }
    jwe->part[0].raw_len = strlen(hdr_str);
    cjose_get_dealloc()(hdr_str);
    
    return true;
}
开发者ID:SolarFury,项目名称:cjose,代码行数:30,代码来源:jwe.c


示例16: Json_new

//## Json Json.new();
static KMETHOD Json_new (KonohaContext *kctx, KonohaStack *sfp)
{
	struct _kJson* json = (struct _kJson *)KLIB new_kObjectDontUseThis(kctx, KGetReturnType(sfp), 0);
	json->obj = json_object();
	json_incref(json->obj);
	KReturn(json);
}
开发者ID:shinpei,项目名称:minikonoha,代码行数:8,代码来源:jansson_glue.c


示例17: Native_json_array_get

//native Handle:json_array_get(Handle:hArray, iIndex);
static cell_t Native_json_array_get(IPluginContext *pContext, const cell_t *params) {
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

	// Param 1
	json_t *object;
	Handle_t hndlObject = static_cast<Handle_t>(params[1]);
	if ((err=g_pHandleSys->ReadHandle(hndlObject, htJanssonObject, &sec, (void **)&object)) != HandleError_None)
    {
        return pContext->ThrowNativeError("Invalid <Array> handle %x (error %d)", hndlObject, err);
    }

	// Param 2
	int iIndex = params[2];
	json_t *result = json_array_get(object, iIndex);
	if(result == NULL) {
		return BAD_HANDLE;
	}

	Handle_t hndlResult = g_pHandleSys->CreateHandle(htJanssonObject, result, pContext->GetIdentity(), myself->GetIdentity(), NULL);
	if(hndlResult == BAD_HANDLE) {
		pContext->ThrowNativeError("Could not create handle for array element.");
		return BAD_HANDLE;
	}

	// result is a borrowed reference, we don't know what will happen with it
	// so we increase the reference counter, which enforces the developer to
	// CloseHandle() it.
	json_incref(result);

	return hndlResult;
}
开发者ID:alldroll,项目名称:SMJansson,代码行数:35,代码来源:extension.cpp


示例18: cfg_get_json

// Compute the effective value of the root_files configuration and
// return a json reference.  The caller must decref the ref when done
// (we may synthesize this value).   Sets enforcing to indicate whether
// we will only allow watches on the root_files.
// The array returned by this function (if not NULL) is guaranteed to
// list .watchmanconfig as its zeroth element.
json_t *cfg_compute_root_files(bool *enforcing) {
  json_t *ref;

  *enforcing = false;

  ref = cfg_get_json(NULL, "enforce_root_files");
  if (ref) {
    if (!json_is_boolean(ref)) {
      w_log(W_LOG_FATAL,
          "Expected config value enforce_root_files to be boolean\n");
    }
    *enforcing = json_is_true(ref);
  }

  ref = cfg_get_json(NULL, "root_files");
  if (ref) {
    if (!is_array_of_strings(ref)) {
      w_log(W_LOG_FATAL,
          "global config root_files must be an array of strings\n");
      *enforcing = false;
      return NULL;
    }
    prepend_watchmanconfig_to_array(ref);

    json_incref(ref);
    return ref;
  }

  // Try legacy root_restrict_files configuration
  ref = cfg_get_json(NULL, "root_restrict_files");
  if (ref) {
    if (!is_array_of_strings(ref)) {
      w_log(W_LOG_FATAL, "deprecated global config root_restrict_files "
          "must be an array of strings\n");
      *enforcing = false;
      return NULL;
    }
    prepend_watchmanconfig_to_array(ref);
    json_incref(ref);
    *enforcing = true;
    return ref;
  }

  // Synthesize our conservative default value.
  // .watchmanconfig MUST be first
  return json_pack("[ssss]", ".watchmanconfig", ".hg", ".git", ".svn");
}
开发者ID:arnonhongklay,项目名称:watchman,代码行数:53,代码来源:cfg.c


示例19: SetJsonBuf

static void SetJsonBuf(struct JsonBuf *jsonbuf, json_t *json)
{
	json_incref(json);
	if(jsonbuf->jsonobj != NULL) {
		json_decref(jsonbuf->jsonobj);
	}
	jsonbuf->jsonobj = json;
}
开发者ID:stadaki,项目名称:konoha3,代码行数:8,代码来源:Jansson.c


示例20: json_decref

void JSON::operator=(JSON const &o) {
	if(json) {
		json_decref(json);
	}
	if(o.json) {
		json = json_incref(o.json);
	}
}
开发者ID:dazeus,项目名称:dazeus-core,代码行数:8,代码来源:jsonwrap.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ json_integer函数代码示例发布时间:2022-05-30
下一篇:
C++ json_find_first_label函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap