Example #1
0
static Validator* set_default(Validator *v, jvalue_ref def_value)
{
	ArrayValidator *a = (ArrayValidator *) v;
	j_release(&a->def_value);
	a->def_value = jvalue_copy(def_value);
	return v;
}
Example #2
0
static Validator* set_default(Validator *validator, jvalue_ref def_value)
{
	NumberValidator *v = (NumberValidator *) validator;
	j_release(&v->def_value);
	v->def_value = jvalue_copy(def_value);
	return validator;
}
Example #3
0
JValue::JValue(const JValue& other)
	: m_jval(jvalue_copy(other.m_jval)), m_input(other.m_input)
#if PBNJSON_ZERO_COPY_STL_STR
	, m_children(other.m_children)
#endif
{
}
Example #4
0
JValue::ObjectIterator::ObjectIterator(const ObjectIterator& other)
	: _it(other._it)
	, _parent(jvalue_copy(other._parent))
	, _key_value(other._key_value)
	, _at_end(other._at_end)
{
}
Example #5
0
int dom_object_start(JSAXContextRef ctxt)
{
	DomInfo *data = getDOMContext(ctxt);
	jvalue_ref newParent;
	DomInfo *newChild;

	CHECK_CONDITION_RETURN_VALUE(data == NULL, 0, "object encountered without any context");

	newParent = jobject_create();
	newChild = calloc(1, sizeof(DomInfo));

	if (UNLIKELY(newChild == NULL || !jis_valid(newParent))) {
		PJ_LOG_ERR("PBNJSON_OBJ_CALLOC_ERR", 0, "Failed to allocate space for new object");
		j_release(&newParent);
		free(newChild);
		return 0;
	}
	newChild->m_prev = data;
	newChild->m_optInformation = data->m_optInformation;
	changeDOMContext(ctxt, newChild);

	if (data->m_prev != NULL) {
		if (jis_array(data->m_prev->m_value)) {
			assert(data->m_value == NULL);
			jarray_append(data->m_prev->m_value, jvalue_copy(newParent));
		} else {
			assert(jis_object(data->m_prev->m_value));
			if (UNLIKELY(!jis_string(data->m_value)))
			{
				PJ_LOG_ERR("PBNJSON_OBJ_MISPLACED_CHILD", 0, "improper place for a child object");
				j_release(&newParent);
				return 0;
			}
			jobject_put(data->m_prev->m_value, data->m_value, jvalue_copy(newParent));
		}
	}

	data->m_value = newParent;

	return 1;
}
Example #6
0
JValue::ObjectIterator& JValue::ObjectIterator::operator=(const ObjectIterator &other)
{
	if (this != &other)
	{
		_it = other._it;
		j_release(&_parent);
		_parent = jvalue_copy(other._parent);
		_key_value = other._key_value;
		_at_end = other._at_end;
	}
	return *this;
}
Example #7
0
JValue& JValue::operator=(const JValue& other)
{
	if (m_jval != other.m_jval) {
		j_release(&m_jval);
		m_jval = jvalue_copy(other.m_jval);
		m_input = other.m_input;
#if PBNJSON_ZERO_COPY_STL_STR
		m_children = other.m_children;
#endif
	}
	return *this;
}
Example #8
0
JValue::ObjectIterator::ObjectIterator(jvalue_ref parent)
	: _parent(0)
	, _at_end(false)
{
	_key_value.key = 0;
	_key_value.value = 0;

	if (UNLIKELY(!jobject_iter_init(&_it, parent)))
		throw InvalidType("Can't iterate over non-object");

	_parent = jvalue_copy(parent);
	_at_end = !jobject_iter_next(&_it, &_key_value);
}
Example #9
0
JValue::KeyValue JValue::ObjectIterator::operator*() const
{
	return KeyValue(jvalue_copy(_key_value.key), jvalue_copy(_key_value.value));
}
Example #10
0
JValueArrayElement JValue::operator[](const raw_buffer& key) const
{
	return JValueArrayElement(jvalue_copy(jobject_get(m_jval, key)));
}
Example #11
0
JValueArrayElement JValue::operator[](int index) const
{
	return JValue(jvalue_copy(jarray_get(m_jval, index)));
}