// Copyright 2007-2010 Baptiste Lepilleur
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
#if !defined(JSON_IS_AMALGAMATION)
# include <json/value.h>
# include <json/writer.h>
# ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
# include "json_batchallocator.h"
# endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <iostream>
#include <utility>
#include <stdexcept>
#include <cstring>
#include <cassert>
#ifdef JSON_USE_CPPTL
# include <cpptl/conststring.h>
#endif
#include <cstddef> // size_t
#define JSON_ASSERT_UNREACHABLE assert( false )
#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw
#define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message );
#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) JSON_FAIL_MESSAGE( message )
namespace Json {
const Value Value::null;
const Int Value::minInt = Int( ~(UInt(-1)/2) );
const Int Value::maxInt = Int( UInt(-1)/2 );
const UInt Value::maxUInt = UInt(-1);
const Int64 Value::minInt64 = Int64( ~(UInt64(-1)/2) );
const Int64 Value::maxInt64 = Int64( UInt64(-1)/2 );
const UInt64 Value::maxUInt64 = UInt64(-1);
const LargestInt Value::minLargestInt = LargestInt( ~(LargestUInt(-1)/2) );
const LargestInt Value::maxLargestInt = LargestInt( LargestUInt(-1)/2 );
const LargestUInt Value::maxLargestUInt = LargestUInt(-1);
/// Unknown size marker
static const unsigned int unknown = (unsigned)-1;
/** Duplicates the specified string value.
* @param value Pointer to the string to duplicate. Must be zero-terminated if
* length is "unknown".
* @param length Length of the value. if equals to unknown, then it will be
* computed using strlen(value).
* @return Pointer on the duplicate instance of string.
*/
static inline char *
duplicateStringValue( const char *value,
unsigned int length = unknown )
{
if ( length == unknown )
length = (unsigned int)strlen(value);
char *newString = static_cast<char *>( malloc( length + 1 ) );
JSON_ASSERT_MESSAGE( newString != 0, "Failed to allocate string value buffer" );
memcpy( newString, value, length );
newString[length] = 0;
return newString;
}
/** Free the string duplicated by duplicateStringValue().
*/
static inline void
releaseStringValue( char *value )
{
if ( value )
free( value );
}
} // namespace Json
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// ValueInternals...
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
#if !defined(JSON_IS_AMALGAMATION)
# ifdef JSON_VALUE_USE_INTERNAL_MAP
# include "json_internalarray.inl"
# include "json_internalmap.inl"
# endif // JSON_VALUE_USE_INTERNAL_MAP
# include "json_valueiterator.inl"
#endif // if !defined(JSON_IS_AMALGAMATION)
namespace Json {
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class Value::CommentInfo
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
Value::CommentInfo::CommentInfo()
: comment_( 0 )
{
}
Value::CommentInfo::~CommentInfo()
{
if ( comment_ )
releaseStringValue( comment_ );
}
void
Value::CommentInfo::setComment( const char *text )
{
if ( comment_ )
releaseStringValue( comment_ );
JSON_ASSERT( text != 0 );
JSON_ASSERT_MESSAGE( text[0]=='\0' || text[0]=='/', "Comments must start with /");
// It seems that /**/ style comments are acceptable as well.
comment_ = duplicateStringValue( text );
}
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class Value::CZString
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
# ifndef JSON_VALUE_USE_INTERNAL_MAP
// Notes: index_ indicates if the string was allocated when
// a string is stored.
Value::CZString::CZString( ArrayIndex index )
: cstr_( 0 )
, index_( index )
{
}
Value::CZString::CZString( const char *cstr, DuplicationPolicy allocate )
: cstr_( allocate == duplicate ? duplicateStringValue(cstr)
: cstr )
, index_( allocate )
{
}
Value::CZString::CZString( const CZString &other )
: cstr_( other.index_ != noDuplication && other.cstr_ != 0
? duplicateStringValue( other.cstr_ )
: other.cstr_ )
, index_( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate)
: other.index_ )
{
}
Value::CZString::~CZString()
{
if ( cstr_ && index_ == duplicate )
releaseStringValue( const_cast<char *>( cstr_ ) );
}
void
Value::CZString::swap( CZString &other )
{
std::swap( cstr_, other.cstr_ );
std::swap( index_, other.index_ );
}
Value::CZString &
Value::CZString::operator =( const CZString &other )
{
CZString temp( other );
swap( temp );
return *this;
}
bool
Value::CZString::operator<( const CZString &other ) const
{
if ( cstr_ )
return strcmp( cstr_, other.cstr_ ) < 0;
return index_ < other.index_;
}
bool
Value::CZString::operator==( const CZString &other ) const
{
if ( cstr_ )
return strcmp( cstr_, other.cstr_ ) == 0;
return index_ == other.index_;
}
ArrayIndex
Value::CZString::index() const
{
return index_;
}
const char *
Value::CZString::c_str() const
{
return cstr_;
}
bool
Value::CZString::isStaticString() const
{
return index_ == noDuplication;
}
#endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class Value::Value
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
/*! \internal Default constructor initialization must be equivalent to:
* memset( this, 0, sizeof(Value) )
* This optimization is used in ValueInternalMap fast allocator.
*/
Value::Value( ValueType type )
: type_( type )
, allocated_( 0 )
, comments_( 0 )
# ifdef JSON_VALUE_USE_INTERNAL_MAP
, itemIsUsed_( 0 )
#endif
{
switch ( type )
{
case nullValue:
break;
case intValue:
case uintValue:
value_.int_ = 0;
break;
case realValue:
value_.real_ = 0.0;
break;
case stringValue:
value_.string_ = 0;
break;
#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
value_.map_ = new ObjectValues();
break;
#else
case arrayValue:
value_.array_ = arrayAllocator()->newArray();
break;
case objectValue:
value_.map_ = mapAllocator()->newMap();
break;
#endif
case booleanValue:
value_.bool_ = false;
break;
default:
JSON_ASSERT_UNREACHABLE;
}
}
#if defined(JSON_HAS_INT64)
Value::Value( UInt value )
: type_( uintValue )
, comments_( 0 )
# ifdef JSON_VALUE_
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
VC++要使用JSON来解析数据,这个源码工程进行编译链接就可以得到一个静态链接库json.lib,只需要将这个lib文件拷贝到你的工程目录下,并将\include\json复制到工程目录下,然后将这些头文件加到工程中去就可以了。 #pragma comment(lib, "json_mtd.lib") #include "json/json.h"
资源推荐
资源详情
资源评论
收起资源包目录
Cjson.rar (76个子文件)
Cjson
makefiles
vs71
jsoncpp.VC.db 29.63MB
jsontest.vcxproj 5KB
lib_json.vcproj 6KB
test_lib_json.vcxproj 5KB
jsontest.vcproj 3KB
.vs
jsoncpp
v14
.suo 20KB
lib_json.vcxproj 8KB
UpgradeLog.htm 75KB
test_lib_json.vcproj 3KB
jsoncpp.sln 2KB
src
test_lib_json
sconscript 252B
main.cpp 13KB
jsontest.cpp 13KB
jsontest.h 9KB
jsontestrunner
sconscript 236B
main.cpp 7KB
lib_json
json_internalarray.inl 13KB
json_reader.cpp 21KB
json_tool.h 2KB
json_value.cpp 41KB
json_batchallocator.h 4KB
json_internalmap.inl 16KB
sconscript 154B
json_valueiterator.inl 7KB
json_writer.cpp 20KB
build
vs71
debug
test_lib_json
vc140.pdb 604KB
vc140.idb 899KB
test_lib_json.log 11KB
test_lib_json.ilk 3.4MB
test_lib_json.exe 1.61MB
test_lib_json.tlog
CL.read.1.tlog 84KB
link.read.1.tlog 8KB
test_lib_json.lastbuildstate 227B
link.write.1.tlog 2KB
CL.write.1.tlog 3KB
link.command.1.tlog 4KB
CL.command.1.tlog 3KB
main.obj 350KB
test_lib_json.pdb 8.71MB
jsontest.obj 559KB
jsontest
vc140.pdb 524KB
vc140.idb 563KB
jsontest.pdb 9.18MB
jsontest.exe 1.71MB
jsontest.tlog
CL.read.1.tlog 17KB
link.read.1.tlog 4KB
link.write.1.tlog 770B
CL.write.1.tlog 570B
jsontest.lastbuildstate 227B
link.command.1.tlog 3KB
CL.command.1.tlog 2KB
jsontest.log 211B
jsontest.ilk 3.61MB
main.obj 498KB
lib_json
lib_json.tlog
CL.read.1.tlog 51KB
Lib-link.read.1.tlog 1KB
CL.write.1.tlog 2KB
lib.command.1.tlog 2KB
CL.command.1.tlog 5KB
lib_json.lastbuildstate 227B
Lib-link.write.1.tlog 640B
lib_json.idb 659KB
json_reader.obj 626KB
json_vc71_libmtd.lib 2.8MB
json_writer.obj 737KB
lib_json.pdb 604KB
json_value.obj 1.07MB
lib_json.log 1KB
include
json
reader.h 7KB
forwards.h 1001B
autolink.h 664B
json.h 426B
config.h 3KB
features.h 2KB
value.h 35KB
writer.h 7KB
共 76 条
- 1
资源评论
vision_sky
- 粉丝: 23
- 资源: 164
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功