本文整理汇总了C++中wxJSONValue类的典型用法代码示例。如果您正苦于以下问题:C++ wxJSONValue类的具体用法?C++ wxJSONValue怎么用?C++ wxJSONValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了wxJSONValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddReplace
bool eSettings::AddReplace(const wxString& pattern) {
wxJSONValue& replacements = m_jsonRoot[wxT("replaceHistory")];
// Don't add duplicates
if (replacements.Size() > 0) {
const wxJSONValue last = replacements.ItemAt(0);
if (last.AsString() == pattern) return false;
// Check if there should be a duplicate lower down
for (int i = 0; i < replacements.Size(); ++i) {
if (replacements[i].AsString() == pattern) {
replacements.Remove(i);
break;
}
}
}
// Add the new item
replacements.Insert(0, pattern);
// Limit number of items to save
if (replacements.Size() > 20) replacements.Remove(replacements.Size()-1);
return true;
}
示例2: AddFilterCommand
bool eSettings::AddFilterCommand(const wxString& command) {
wxJSONValue& values = m_jsonRoot[wxT("filterCommandHistory")];
// Don't add duplicates
if (values.Size() > 0) {
const wxJSONValue last = values.ItemAt(0);
if (last.AsString() == command) return false;
// Check if there should be a duplicate lower down
for (int i = 0; i < values.Size(); ++i) {
if (values[i].AsString() == command) {
values.Remove(i);
break;
}
}
}
// Add the new item
values.Insert(0, command);
// Limit number of items to save
if (values.Size() > 20) values.Remove(values.Size()-1);
return true;
}
示例3: wxASSERT
wxString eSettings::GetRemoteProfileName(size_t profile_id) const {
const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
wxASSERT((int)profile_id < remotes.Size());
const wxJSONValue profile = remotes.ItemAt(profile_id);
return profile.ItemAt(wxT("name")).AsString();
}
示例4: WriteIndent
//! Write the comment strings, if any.
int
wxJSONWriter::WriteComment( wxOutputStream& os, const wxJSONValue& value, bool indent )
{
// the function returns the last character written which should be
// a LF char or -1 in case of errors
// if nothing is written, returns ZERO
int lastChar = 0;
// only write comments if the style include the WRITE_COMMENTS flag
if ( (m_style & wxJSONWRITER_WRITE_COMMENTS ) == 0 ) {
return lastChar;
}
const wxArrayString cmt = value.GetCommentArray();
int cmtSize = cmt.GetCount();
for ( int i = 0; i < cmtSize; i++ ) {
if ( indent ) {
WriteIndent( os );
}
else {
os.PutC( '\t' );
}
WriteString( os, cmt[i]);
lastChar = cmt[i].Last();
if ( lastChar != '\n' ) {
os.PutC( '\n' );
lastChar = '\n';
}
}
return lastChar;
}
示例5: 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;
}
示例6: GetSettingBool
bool eSettings::GetSettingBool(const wxString& name, bool& value) const {
if (!m_jsonRoot.HasMember(wxT("settings"))) return false;
const wxJSONValue settings = m_jsonRoot.ItemAt(wxT("settings"));
if (!settings.HasMember(name)) return false;
// old bool values may have been stored as ints
const wxJSONValue val = settings.ItemAt(name);
if (val.IsInt()) return (val.AsInt() > 0);
if (!val.IsBool()) return false;
value = val.AsBool();
return true;
}
示例7: 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;
}
示例8: 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;
}
示例9: GetSettingString
bool eSettings::GetSettingString(const wxString& name, wxString& value) const {
if (!m_jsonRoot.HasMember(wxT("settings"))) return false;
const wxJSONValue settings = m_jsonRoot.ItemAt(wxT("settings"));
if (!settings.HasMember(name)) return false;
const wxJSONValue val = settings.ItemAt(name);
if (!val.IsString()) return false;
value = val.AsString();
return true;
}
示例10: 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;
}
示例11: value
void eSettings::AddToRecent(const wxString& key, wxJSONValue& jsonArray, size_t max) {
const wxJSONValue value(key);
// Check if value is already in array
int ndx = -1;
for (int i = 0; i < jsonArray.Size(); ++i) {
if (value.IsSameAs(jsonArray.ItemAt(i))) {
ndx = i;
break;
}
}
if (ndx == 0) return; // No need to do anything if path is already top
if (ndx > 0) jsonArray.Remove(ndx); // remove duplicate entry
// Insert value at top
jsonArray.Insert(0, value);
// Make sure we have no more than max entries
if (jsonArray.Size() > (int)max) jsonArray.Remove(max);
}
示例12: GetSearchCount
size_t eSettings::GetSearchCount() const {
if (!m_jsonRoot.HasMember(wxT("searchHistory"))) return 0;
const wxJSONValue searches = m_jsonRoot.ItemAt(wxT("searchHistory"));
return searches.Size();
}
示例13: WriteStringValue
/*!
This is a recursive function that gets the type of the \c value object and
calls several protected functions depending on the type:
\li \c WriteNullvalue for type NULL
\li \c WriteStringValue() for STRING and CSTRING types
\li \c WriteIntValue for INT types
\li \c WriteUIntValue for UINT types
\li \c WriteBoolValue for BOOL types
\li \c WriteDoubleValue for DOUBLE types
\li \c WriteMemoryBuff for MEMORYBUFF types
If the value is an array or key/value map (types ARRAY and OBJECT), the function
iterates through all JSON value object in the array/map and calls itself for every
item in the container.
*/
int
wxJSONWriter::DoWrite( wxOutputStream& os, const wxJSONValue& value, const wxString* key, bool comma )
{
// note that this function is recursive
// some variables that cannot be allocated in the switch statement
const wxJSONInternalMap* map = 0;
int size;
m_colNo = 1; m_lineNo = 1;
// determine the comment position; it is one of:
//
// wxJSONVALUE_COMMENT_BEFORE
// wxJSONVALUE_COMMENT_AFTER
// wxJSONVALUE_COMMENT_INLINE
//
// or -1 if comments have not to be written
int commentPos = -1;
if ( value.GetCommentCount() > 0 && (m_style & wxJSONWRITER_WRITE_COMMENTS)) {
commentPos = value.GetCommentPos();
if ( ( m_style & wxJSONWRITER_COMMENTS_BEFORE) != 0 ) {
commentPos = wxJSONVALUE_COMMENT_BEFORE;
}
else if ( (m_style & wxJSONWRITER_COMMENTS_AFTER) != 0 ) {
commentPos = wxJSONVALUE_COMMENT_AFTER;
}
}
int lastChar = 0; // check if WriteComment() writes the last LF char
// first write the comment if it is BEFORE
if ( commentPos == wxJSONVALUE_COMMENT_BEFORE ) {
lastChar = WriteComment( os, value, true );
if ( lastChar < 0 ) {
return lastChar;
}
else if ( lastChar != '\n' ) {
WriteSeparator( os );
}
}
lastChar = WriteIndent( os );
if ( lastChar < 0 ) {
return lastChar;
}
// now write the key if it is not NULL
if ( key ) {
lastChar = WriteKey( os, *key );
}
if ( lastChar < 0 ) {
return lastChar;
}
// now write the value
wxJSONInternalMap::const_iterator it; // declare the map object
long int count = 0;
wxJSONType t = value.GetType();
switch ( t ) {
case wxJSONTYPE_INVALID :
WriteInvalid( os );
wxFAIL_MSG( _T("wxJSONWriter::WriteEmpty() cannot be called (not a valid JSON text"));
break;
case wxJSONTYPE_INT :
case wxJSONTYPE_SHORT :
case wxJSONTYPE_LONG :
case wxJSONTYPE_INT64 :
lastChar = WriteIntValue( os, value );
break;
case wxJSONTYPE_UINT :
case wxJSONTYPE_USHORT :
case wxJSONTYPE_ULONG :
case wxJSONTYPE_UINT64 :
lastChar = WriteUIntValue( os, value );
break;
case wxJSONTYPE_NULL :
lastChar = WriteNullValue( os );
break;
case wxJSONTYPE_BOOL :
lastChar = WriteBoolValue( os, value );
break;
//.........这里部分代码省略.........
示例14: GetPageCount
size_t eSettings::GetPageCount() const {
if (!m_jsonRoot.HasMember(wxT("pages"))) return 0;
const wxJSONValue pages = m_jsonRoot.ItemAt(wxT("pages"));
return pages.Size();
}
示例15: GetRecents
void eSettings::GetRecents(const wxJSONValue& jarray, wxArrayString& recents) const {
for (int i = 0; i < jarray.Size(); ++i) {
recents.Add(jarray.ItemAt(i).AsString());
}
}