コード例 #1
0
ファイル: jsonpull.c プロジェクト: anandthakker/tippecanoe
static json_object *add_object(json_pull *j, json_type type) {
	json_object *c = j->container;
	json_object *o = fabricate_object(c, type);

	if (c != NULL) {
		if (c->type == JSON_ARRAY) {
			if (c->expect == JSON_ITEM) {
				if (SIZE_FOR(c->length + 1) != SIZE_FOR(c->length)) {
					c->array = realloc(c->array, SIZE_FOR(c->length + 1) * sizeof(json_object *));
				}

				c->array[c->length++] = o;
				c->expect = JSON_COMMA;
			} else {
				j->error = "Expected a comma, not a list item";
				free(o);
				return NULL;
			}
		} else if (c->type == JSON_HASH) {
			if (c->expect == JSON_VALUE) {
				c->values[c->length - 1] = o;
				c->expect = JSON_COMMA;
			} else if (c->expect == JSON_KEY) {
				if (type != JSON_STRING) {
					j->error = "Hash key is not a string";
					free(o);
					return NULL;
				}

				if (SIZE_FOR(c->length + 1) != SIZE_FOR(c->length)) {
					c->keys = realloc(c->keys, SIZE_FOR(c->length + 1) * sizeof(json_object *));
					c->values = realloc(c->values, SIZE_FOR(c->length + 1) * sizeof(json_object *));
				}

				c->keys[c->length] = o;
				c->values[c->length] = NULL;
				c->length++;
				c->expect = JSON_COLON;
			} else {
				j->error = "Expected a comma or colon";
				free(o);
				return NULL;
			}
		}
	} else {
		j->root = o;
	}

	return o;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: CCJY/coliru
tracking_factory::o_ptr tracking_factory::make_tracked_object(id_type id)
{
    auto p = fabricate_object(id);
    _objects[id] = p;
    return p;
}