本文整理汇总了C++中wxJSONValue类的典型用法代码示例。如果您正苦于以下问题:C++ wxJSONValue类的具体用法?C++ wxJSONValue怎么用?C++ wxJSONValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了wxJSONValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:boulerne,项目名称:e,代码行数:25,代码来源:eSettings.cpp
示例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;
}
开发者ID:boulerne,项目名称:e,代码行数:25,代码来源:eSettings.cpp
示例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();
}
开发者ID:boulerne,项目名称:e,代码行数:7,代码来源:eSettings.cpp
示例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;
}
开发者ID:CarCode,项目名称:Cocoa-OCPN,代码行数:32,代码来源:jsonwriter.cpp
示例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;
}
开发者ID:hihihippp,项目名称:kiku,代码行数:41,代码来源:jsonwriter.cpp
示例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;
}
开发者ID:boulerne,项目名称:e,代码行数:15,代码来源:eSettings.cpp
示例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;
}
开发者ID:CarCode,项目名称:Cocoa-OCPN,代码行数:27,代码来源:jsonwriter.cpp
示例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;
}
开发者ID:CarCode,项目名称:Cocoa-OCPN,代码行数:55,代码来源:jsonwriter.cpp
示例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;
}
开发者ID:boulerne,项目名称:e,代码行数:12,代码来源:eSettings.cpp
示例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;
}
开发者ID:GimpoByte,项目名称:nextgismanager,代码行数:54,代码来源:jsonwriter.cpp
示例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);
}
开发者ID:boulerne,项目名称:e,代码行数:22,代码来源:eSettings.cpp
示例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();
}
开发者ID:boulerne,项目名称:e,代码行数:6,代码来源:eSettings.cpp
示例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;
//.........这里部分代码省略.........
开发者ID:CarCode,项目名称:Cocoa-OCPN,代码行数:101,代码来源:jsonwriter.cpp
示例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();
}
开发者ID:boulerne,项目名称:e,代码行数:6,代码来源:eSettings.cpp
示例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());
}
}
开发者ID:boulerne,项目名称:e,代码行数:5,代码来源:eSettings.cpp
示例16: GetRemoteProfileCount
size_t eSettings::GetRemoteProfileCount() const {
if (!m_jsonRoot.HasMember(wxT("remoteProfiles"))) return 0;
const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
return remotes.Size();
}
开发者ID:boulerne,项目名称:e,代码行数:6,代码来源:eSettings.cpp
示例17: GetFilterCommand
wxString eSettings::GetFilterCommand(size_t ndx) const {
const wxJSONValue values = m_jsonRoot.ItemAt(wxT("filterCommandHistory"));
wxASSERT((int)ndx < values.Size());
return values.ItemAt(ndx).AsString();
}
开发者ID:boulerne,项目名称:e,代码行数:6,代码来源:eSettings.cpp
示例18: GetFilterCommandHistoryCount
size_t eSettings::GetFilterCommandHistoryCount() const {
if (!m_jsonRoot.HasMember(wxT("filterCommandHistory"))) return 0;
const wxJSONValue values = m_jsonRoot.ItemAt(wxT("filterCommandHistory"));
return values.Size();
}
开发者ID:boulerne,项目名称:e,代码行数:6,代码来源:eSettings.cpp
示例19: reUrl
const RemoteProfile* eSettings::GetRemoteProfileFromUrl(const wxString& url, bool withDir) {
// Split url up in elements
wxRegEx reUrl(wxT("([[:alpha:]]+)://(([^:@]*):([^:@]*)@)?([^/]+)(.*)"));
if (!reUrl.Matches(url)) return NULL; // invalid url
const wxString protocol = reUrl.GetMatch(url, 1);
const wxString username = reUrl.GetMatch(url, 3);
const wxString pwd = reUrl.GetMatch(url, 4);
const wxString address = reUrl.GetMatch(url, 5);
const wxString dir = reUrl.GetMatch(url, 6);
const wxString sDir = StripSlashes(dir);
// See if we can find a matching profile in cache
for (auto_vector<RemoteProfile>::iterator p = m_tempRemotes.begin(); p != m_tempRemotes.end(); ++p) {
RemoteProfile* rp = (*p);
if (rp->IsActive() && rp->m_address == address && rp->m_protocol == protocol) {
if (!username.empty() && rp->m_username != username) continue;
if (withDir && StripSlashes(rp->m_dir) != sDir) continue;
if (!pwd.empty() && rp->m_pwd != pwd) {
rp->m_pwd = pwd; // Password may have changed
if (!rp->IsTemp()) SaveRemoteProfile(rp);
}
return rp;
}
}
// See if we can find a matching profile in settings
const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
const int profile_count = remotes.Size();
for (int i = 0; i < profile_count; ++i) {
const wxJSONValue profile = remotes.ItemAt(i);
if (profile.ItemAt(wxT("address")).AsString() != address) continue;
// Ftp is default protocol
wxString prot = profile.ItemAt(wxT("protocol")).AsString();
if (prot.empty()) prot = wxT("ftp");
if (prot != protocol) continue; // ftp is default
if (!username.empty() && profile.ItemAt(wxT("username")).AsString() != username) continue;
RemoteProfile* rp = DoGetRemoteProfile(i);
if (withDir && StripSlashes(rp->m_dir) != sDir) continue;
// Password may have changed
if (!pwd.empty() && rp->m_pwd != pwd) {
rp->m_pwd = pwd;
SaveRemoteProfile(rp);
}
return rp;
}
// Add new temp profile
auto_ptr<RemoteProfile> newRp(new RemoteProfile());
newRp->m_protocol = protocol;
newRp->m_name = address;
newRp->m_address = address;
newRp->m_dir = dir;
newRp->m_username = username;
newRp->m_pwd = pwd;
m_tempRemotes.push_back(newRp);
return m_tempRemotes.back();
}
开发者ID:boulerne,项目名称:e,代码行数:63,代码来源:eSettings.cpp
示例20: GetReplace
wxString eSettings::GetReplace(size_t ndx) const {
const wxJSONValue replacements = m_jsonRoot.ItemAt(wxT("replaceHistory"));
wxASSERT((int)ndx < replacements.Size());
return replacements.ItemAt(ndx).AsString();
}
开发者ID:boulerne,项目名称:e,代码行数:6,代码来源:eSettings.cpp
注:本文中的wxJSONValue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论