本文整理汇总了C++中JSON_ASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ JSON_ASSERT函数的具体用法?C++ JSON_ASSERT怎么用?C++ JSON_ASSERT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSON_ASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JSON_ASSERT
void
Value::resize ( UInt newSize )
{
JSON_ASSERT ( type_ == nullValue || type_ == arrayValue );
if ( type_ == nullValue )
*this = Value ( arrayValue );
#ifndef JSON_VALUE_USE_INTERNAL_MAP
UInt oldSize = size ();
if ( newSize == 0 )
clear ();
else if ( newSize > oldSize )
(*this)[ newSize - 1 ];
else
{
for ( UInt index = newSize; index < oldSize; ++index )
value_.map_->erase ( index );
assert ( size () == newSize );
}
#else
value_.array_->resize ( newSize );
#endif
}
示例2: JSON_ASSERT
Value
Value::removeMember( const char* key )
{
JSON_ASSERT( type_ == nullValue || type_ == objectValue );
if ( type_ == nullValue )
return null;
#ifndef JSON_VALUE_USE_INTERNAL_MAP
CZString actualKey( key, CZString::noDuplication );
ObjectValues::iterator it = value_.map_->find( actualKey );
if ( it == value_.map_->end() )
return null;
Value old(it->second);
value_.map_->erase(it);
return old;
#else
Value *value = value_.map_->find( key );
if (value){
Value old(*value);
value_.map_.remove( key );
return old;
} else {
return null;
}
#endif
}
示例3: ungetc
void ungetc()
{
if (m_last_ch != -1)
{
JSON_ASSERT(!m_ungot);
m_ungot = true;
}
}
示例4: valueToString
std::string valueToString( UInt value )
{
char buffer[32];
char *current = buffer + sizeof(buffer);
uintToString( value, current );
JSON_ASSERT( current >= buffer );
return current;
}
示例5: JSON_ASSERT
Json& Json::Add(const std::string& key, const Json& value){
if(key.size() > 0 && value._kind != kNull){
if(_kind != kObject)
JSON_ASSERT("json of object expected");
((Object*) _data)->insert(make_pair(key, new Json(value)));
}
return *this;
}
示例6: valueAllocator
void Value::CommentInfo::setComment(const char *text) {
if (comment_)
valueAllocator()->releaseStringValue(comment_);
JSON_ASSERT(text);
JSON_ASSERT_MESSAGE(text[0] == '\0' || text[0] == '/', "Comments must start with /");
// It seems that /**/ style comments are acceptable as well.
comment_ = valueAllocator()->duplicateStringValue(text);
}
示例7: myrealloc
void * JSONMemory::json_realloc(void * ptr, size_t siz){
if (myrealloc){
#ifdef JSON_DEBUG //in debug mode, see if the malloc was successful
void * result = myrealloc(ptr, siz);
JSON_ASSERT(result, JSON_TEXT("out of memory"));
return result;
#else
return myrealloc(ptr, (unsigned long)siz);
#endif
}
#ifdef JSON_DEBUG //in debug mode, see if the malloc was successful
void * result = realloc(ptr, siz);
JSON_ASSERT(result, JSON_TEXT("out of memory"));
return result;
#else
return realloc(ptr, siz);
#endif
}
示例8: JSON_CHECK_INTERNAL
JSONNode::json_iterator JSONNode::find_nocase(const json_string & name_t){
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, JSON_TEXT("finding a non-iteratable node"));
makeUniqueInternal();
if (JSONNode ** res = internal -> at_nocase(name_t)){
return ptr_to_json_iterator(res);
}
return end();
}
示例9: NextChar
Json* Json::Parser::ParseFalse(){
std::string sbool;
for(int i = 0; i < 4; i++)
sbool += NextChar();
if(sbool != "false"){
JSON_ASSERT("expect \"false\" ");
return NULL;
}
else return new Json(false, kFalse);
}
示例10: JSON_ASSERT
void Value::setComment(String comment, CommentPlacement placement) {
if (!comment.empty() && (comment.back() == '\n')) {
// Always discard trailing newline, to aid indentation.
comment.pop_back();
}
JSON_ASSERT(!comment.empty());
JSON_ASSERT_MESSAGE(
comment[0] == '\0' || comment[0] == '/',
"in Json::Value::setComment(): Comments must start with /");
comments_.set(placement, std::move(comment));
}
示例11: JSON_ASSERT
bool Value::CZString::operator==(const CZString& other) const {
if (!cstr_) return index_ == other.index_;
//return strcmp(cstr_, other.cstr_) == 0;
// Assume both are strings.
unsigned this_len = this->storage_.length_;
unsigned other_len = other.storage_.length_;
if (this_len != other_len) return false;
JSON_ASSERT(this->cstr_ && other.cstr_);
int comp = memcmp(this->cstr_, other.cstr_, this_len);
return comp == 0;
}
示例12: releaseStringValue
void Value::CommentInfo::setComment(const char* text, size_t len) {
if (comment_) {
releaseStringValue(comment_, 0u);
comment_ = 0;
}
JSON_ASSERT(text != 0);
JSON_ASSERT_MESSAGE(
text[0] == '\0' || text[0] == '/',
"in Json::Value::setComment(): Comments must start with /");
// It seems that /**/ style comments are acceptable as well.
comment_ = duplicateStringValue(text, len);
}
示例13: watchman_watch_list
struct watchman_watch_list *
watchman_watch_list(struct watchman_connection *conn,
struct watchman_error *error)
{
struct watchman_watch_list *res = NULL;
struct watchman_watch_list *result = NULL;
if (watchman_send_simple_command(conn, error, "watch-list", NULL)) {
return NULL;
}
json_t *obj = watchman_read(conn, error);
if (!obj) {
return NULL;
}
JSON_ASSERT(json_is_object, obj, "Got bogus value from watch-list %s");
json_t *roots = json_object_get(obj, "roots");
JSON_ASSERT(json_is_array, roots, "Got bogus value from watch-list %s");
res = malloc(sizeof(*res));
int nr = json_array_size(roots);
res->nr = 0;
res->roots = calloc(nr, sizeof(*res->roots));
int i;
for (i = 0; i < nr; ++i) {
json_t *root = json_array_get(roots, i);
JSON_ASSERT(json_is_string, root,
"Got non-string root from watch-list %s");
res->nr++;
res->roots[i] = strdup(json_string_value(root));
}
result = res;
res = NULL;
done:
if (res) {
watchman_free_watch_list(res);
}
json_decref(obj);
return result;
}
示例14: while
char Json::Parser::NextChar(bool skip){
while (true)
{
read_pos++;
if(read_pos >= buf.size()) JSON_ASSERT("unexpected end of input");
ch = buf[read_pos];
if (skip && (' ' == ch || '\t' == ch || '\n' == ch || '\r' == ch)) { ; }
else break;
}
return ch;
}
示例15: type
bool Value::operator<(const Value& other) const {
int typeDelta = type() - other.type();
if (typeDelta)
return typeDelta < 0 ? true : false;
switch (type()) {
case nullValue:
return false;
case intValue:
return value_.int_ < other.value_.int_;
case uintValue:
return value_.uint_ < other.value_.uint_;
case realValue:
return value_.real_ < other.value_.real_;
case booleanValue:
return value_.bool_ < other.value_.bool_;
case stringValue: {
if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) {
if (other.value_.string_)
return true;
else
return false;
}
unsigned this_len;
unsigned other_len;
char const* this_str;
char const* other_str;
decodePrefixedString(this->isAllocated(), this->value_.string_, &this_len,
&this_str);
decodePrefixedString(other.isAllocated(), other.value_.string_, &other_len,
&other_str);
unsigned min_len = std::min<unsigned>(this_len, other_len);
JSON_ASSERT(this_str && other_str);
int comp = memcmp(this_str, other_str, min_len);
if (comp < 0)
return true;
if (comp > 0)
return false;
return (this_len < other_len);
}
case arrayValue:
case objectValue: {
int delta = int(value_.map_->size() - other.value_.map_->size());
if (delta)
return delta < 0;
return (*value_.map_) < (*other.value_.map_);
}
default:
JSON_ASSERT_UNREACHABLE;
}
return false; // unreachable
}