本文整理汇总了C++中wxJSONValue::GetRefData方法的典型用法代码示例。如果您正苦于以下问题:C++ wxJSONValue::GetRefData方法的具体用法?C++ wxJSONValue::GetRefData怎么用?C++ wxJSONValue::GetRefData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wxJSONValue
的用法示例。
在下文中一共展示了wxJSONValue::GetRefData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: integers
/*!
This function is called for every value objects of INT type.
This function uses the \n snprintf function to get the US-ASCII
representation of the integer and simply copy it to the output stream.
Returns -1 on stream errors or ZERO if no errors.
*/
int
wxJSONWriter::WriteIntValue( wxOutputStream& os, const wxJSONValue& value )
{
int r = 0;
char buffer[32]; // need to store 64-bits integers (max 20 digits)
size_t len;
wxJSONRefData* data = value.GetRefData();
wxASSERT( data );
#if defined( wxJSON_64BIT_INT )
// this is for wxW 2.8 Unicode: in order to use the cross-platform
// format specifier, we use the wxString's sprintf() function and then
// convert to UTF-8 before writing to the stream
wxString s;
s.Printf( _T("%") wxLongLongFmtSpec _T("d"),
data->m_value.m_valInt64 );
wxCharBuffer cb = s.ToUTF8();
const char* cbData = cb.data();
len = strlen( cbData );
wxASSERT( len < 32 );
memcpy( buffer, cbData, len );
buffer[len] = 0;
#else
snprintf( buffer, 32, "%ld", data->m_value.m_valLong );
#endif
len = strlen( buffer );
os.Write( buffer, len );
if ( os.GetLastError() != wxSTREAM_NO_ERROR ) {
r = -1;
}
return r;
}
示例2: wxASSERT
/*!
This function is called for every value objects of DOUBLE type.
This function uses the \n snprintf function to get the US-ASCII
representation of the integer and simply copy it to the output stream.
Returns -1 on stream errors or ZERO if no errors.
Note that writing a double to a decimal ASCII representation could
lay to unexpected results depending on the format string used in the
conversion.
See SetDoubleFmtString for details.
*/
int
wxJSONWriter::WriteDoubleValue( wxOutputStream& os, const wxJSONValue& value )
{
int r = 0;
char buffer[32];
wxJSONRefData* data = value.GetRefData();
wxASSERT( data );
snprintf( buffer, 32, m_fmt, data->m_value.m_valDouble );
size_t len = strlen( buffer );
os.Write( buffer, len );
if ( os.GetLastError() != wxSTREAM_NO_ERROR ) {
r = -1;
}
return r;
}
示例3: integers
/*!
This function is called for every value objects of UINT type.
This function uses the \n snprintf function to get the US-ASCII
representation of the integer and simply copy it to the output stream.
The function prepends a \b plus \b sign if the \c wxJSONWRITER_RECOGNIZE_UNSIGNED
flag is set in the \c m_flags data member.
Returns -1 on stream errors or ZERO if no errors.
*/
int
wxJSONWriter::WriteUIntValue( wxOutputStream& os, const wxJSONValue& value )
{
int r = 0; size_t len;
// prepend a plus sign if the style specifies that unsigned integers
// have to be recognized by the JSON reader
if ( m_style & wxJSONWRITER_RECOGNIZE_UNSIGNED ) {
os.PutC( '+' );
}
char buffer[32]; // need to store 64-bits integers (max 20 digits)
wxJSONRefData* data = value.GetRefData();
wxASSERT( data );
#if defined( wxJSON_64BIT_INT )
#if wxCHECK_VERSION(2, 9, 0 ) || !defined( wxJSON_USE_UNICODE )
// this is fine for wxW 2.9 and for wxW 2.8 ANSI
snprintf( buffer, 32, "%" wxLongLongFmtSpec "u",
data->m_value.m_valUInt64 );
#elif wxCHECK_VERSION(3, 0, 0) || !defined( wxJSON_USE_UNICODE )
snprintf( buffer, 32, "%" wxLongLongFmtSpec "u",
data->m_value.m_valUInt64 );
#else
// this is for wxW 2.8 Unicode: in order to use the cross-platform
// format specifier, we use the wxString's sprintf() function and then
// convert to UTF-8 before writing to the stream
wxString s;
s.Printf( _T("%") wxLongLongFmtSpec _T("u"),
data->m_value.m_valInt64 );
wxCharBuffer cb = s.ToUTF8();
const char* cbData = cb.data();
len = strlen( cbData );
wxASSERT( len < 32 );
memcpy( buffer, cbData, len );
buffer[len] = 0;
#endif
#else
snprintf( buffer, 32, "%lu", data->m_value.m_valULong );
#endif
len = strlen( buffer );
os.Write( buffer, len );
if ( os.GetLastError() != wxSTREAM_NO_ERROR ) {
r = -1;
}
return r;
}
示例4: ansiCB
/*!
This function is called for every value objects of DOUBLE type.
This function uses the \n snprintf function to get the US-ASCII
representation of the integer and simply copy it to the output stream.
Returns -1 on stream errors or ZERO if no errors.
Note that writing a double to a decimal ASCII representation could
lay to unexpected results depending on the format string used in the
conversion.
See SetDoubleFmtString for details.
*/
int
wxJSONWriter::WriteDoubleValue( wxOutputStream& os, const wxJSONValue& value )
{
int r = 0;
wxJSONRefData* data = value.GetRefData();
wxASSERT( data );
char* writeBuff = 0;
// the buffer that has to be written is either UTF-8 or ANSI c_str() depending
// on the 'm_noUtf8' flag
wxCharBuffer utf8CB = wxString::FromCDouble(data->m_value.m_valDouble, 10).ToUTF8(); // the UTF-8 buffer
#if !defined(wxJSON_USE_UNICODE)
wxCharBuffer ansiCB(str.c_str()); // the ANSI buffer
if (m_noUtf8)
{
writeBuff = ansiCB.data();
}
else
{
writeBuff = utf8CB.data();
}
#else
writeBuff = utf8CB.data();
#endif
// NOTE: in ANSI builds UTF-8 conversion may fail (see samples/test5.cpp,
// test 7.3) although I do not know why
if (writeBuff == 0)
{
const char* err = "<wxJSONWriter::WriteComment(): error converting the double to UTF-8>";
os.Write(err, strlen(err));
return 0;
}
size_t len = strlen(writeBuff);
os.Write(writeBuff, len);
if (os.GetLastError() != wxSTREAM_NO_ERROR)
{
r = -1;
}
return r;
}