本文整理汇总了C++中MojObject::size方法的典型用法代码示例。如果您正苦于以下问题:C++ MojObject::size方法的具体用法?C++ MojObject::size怎么用?C++ MojObject::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojObject
的用法示例。
在下文中一共展示了MojObject::size方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emptyTest
MojErr MojObjectTest::emptyTest(MojObject& obj)
{
MojObject obj2;
MojString str1;
MojString str2;
bool found = false;
MojTestAssert(obj.size() == 0);
MojTestAssert(obj.empty());
MojTestAssert(obj.boolValue() == false);
MojTestAssert(obj.intValue() == 0);
MojTestAssert(obj.decimalValue() == MojDecimal());
MojTestAssert(obj.begin() == obj.end());
MojTestAssert(!obj.contains(_T("hello")));
MojTestAssert(!obj.get(_T("hi"), obj2));
MojErr err = obj.del(_T("hello"), found);
MojTestErrCheck(err);
obj2.assign(obj);
MojTestAssert(obj2.type() == obj.type());
MojTestAssert(obj2 == obj);
MojTestAssert(!(obj2 != obj));
err = obj.stringValue(str1);
MojTestErrCheck(err);
err = obj2.stringValue(str2);
MojTestErrCheck(err);
MojTestAssert(str1 == str2);
return MojErrNone;
}
示例2: GetPopAccountResponse
MojErr AccountFinderCommand::GetPopAccountResponse(MojObject& response, MojErr err)
{
CommandTraceFunction();
try {
// check database result first
ErrorToException(err);
MojObject results;
err = response.getRequired(_T("results"), results);
ErrorToException(err);
if (results.size() > 0) {
MojObject transportObj;
if (results.at(0, transportObj)) {
PopAccountAdapter::GetPopAccount(m_accountObj, transportObj, *(m_account.get()));
}
}
MojLogInfo(m_log, "Setting account to pop client");
m_client.SetAccount(m_account);
Complete();
} catch (const std::exception& ex) {
Failure(ex);
} catch (...) {
Failure(MailException("unknown exception", __FILE__, __LINE__));
}
return MojErrNone;
}
示例3: check
MojErr MojDbTextTokenizerTest::check(const MojChar* text, const MojChar* tokens)
{
// tokenize string
MojString textStr;
MojErr err = textStr.assign(text);
MojTestErrCheck(err);
MojSet<MojDbKey> set;
MojRefCountedPtr<MojDbTextTokenizer> tokenizer(new MojDbTextTokenizer);
MojAllocCheck(tokenizer.get());
err = tokenizer->init(_T("en_US"));
MojTestErrCheck(err);
err = tokenizer->tokenize(textStr, NULL, set);
MojTestErrCheck(err);
// check that tokens match
MojObject obj;
err = obj.fromJson(tokens);
MojTestErrCheck(err);
MojSize objSize = obj.size();
MojSize setSize = set.size();
MojTestAssert(objSize == setSize);
for (MojObject::ConstArrayIterator i = obj.arrayBegin(); i != obj.arrayEnd(); ++i) {
MojDbKey key;
err = key.assign(*i);
MojTestErrCheck(err);
MojTestAssert(set.contains(key));
}
return MojErrNone;
}
示例4: check
MojErr MojDbDistinctTest::check(MojDb& db, const MojDbQuery& query, MojDbCursor& cursor, const MojChar* queryString, const MojChar* expectedIdsJson)
{
MojErr err = db.find(query, cursor);
MojTestErrCheck(err);
MojObjectBuilder builder;
err = builder.beginArray();
MojTestErrCheck(err);
err = cursor.visit(builder);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
err = builder.endArray();
MojTestErrCheck(err);
MojObject results = builder.object();
MojString json;
err = results.toJson(json);
MojTestErrCheck(err);
MojObject expected;
err = expected.fromJson(expectedIdsJson);
MojTestErrCheck(err);
// size check
MojTestAssert(expected.size() == results.size());
// value check
MojObject::ConstArrayIterator j = results.arrayBegin();
for (MojObject::ConstArrayIterator i = expected.arrayBegin();
i != expected.arrayEnd(); ++i, ++j) {
MojObject value;
err = j->getRequired(queryString, value);
MojTestErrCheck(err);
MojTestAssert(*i == value);
}
return MojErrNone;
}
示例5: check
MojErr MojDbSearchTest::check(MojDb& db, const MojDbQuery& query, const MojChar* expectedIdsJson)
{
MojString str;
MojDbSearchCursor cursor(str);
MojErr err = db.find(query, cursor);
MojTestErrCheck(err);
MojObjectBuilder builder;
err = builder.beginArray();
MojTestErrCheck(err);
err = cursor.visit(builder);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
err = builder.endArray();
MojTestErrCheck(err);
MojObject results = builder.object();
MojString json;
err = results.toJson(json);
MojTestErrCheck(err);
MojObject expected;
err = expected.fromJson(expectedIdsJson);
MojTestErrCheck(err);
MojTestAssert(expected.size() == results.size());
MojObject::ConstArrayIterator j = results.arrayBegin();
for (MojObject::ConstArrayIterator i = expected.arrayBegin();
i != expected.arrayEnd(); ++i, ++j) {
MojObject id;
err = j->getRequired(MojDb::IdKey, id);
MojTestErrCheck(err);
MojTestAssert(*i == id);
}
return MojErrNone;
}
示例6: UpdateEmailParts
void MojoDatabase::UpdateEmailParts(Signal::SlotRef slot, const MojObject& emailId, const MojObject& parts, bool autoDownload)
{
MojObject email;
MojErr err = email.put(PopEmailAdapter::ID, emailId);
ErrorToException(err);
err = email.put(EmailSchema::PARTS, parts);
ErrorToException(err);
if ((!parts.undefined() && !parts.null() && parts.size() > 0) || !autoDownload) {
err = email.put(PopEmailAdapter::DOWNLOADED, true);
ErrorToException(err);
}
MojLogDebug(PopClient::s_log, "Updating email '%s' with parts: '%s'", AsJsonString(emailId).c_str(), AsJsonString(parts).c_str());
err = m_dbClient.merge(slot, email);
ErrorToException(err);
}
示例7: GetAccountResponse
MojErr PopAccountUpdateCommand::GetAccountResponse(MojObject& response, MojErr err)
{
try {
ErrorToException(err);
MojObject results;
err = response.getRequired(_T("results"), results);
ErrorToException(err);
if (results.size() > 0 && results.at(0, m_transportObj)) {
GetPassword();
}
} catch (const std::exception& ex) {
Failure(ex);
} catch (...) {
Failure(MailException("unknown exception", __FILE__, __LINE__));
}
return MojErrNone;
}
示例8: GetDraftsResponse
MojErr CheckDraftsCommand::GetDraftsResponse(MojObject& response, MojErr err)
{
CommandTraceFunction();
try {
ErrorToException(err);
MojObject results;
err = response.getRequired("results", results);
ErrorToException(err);
if(results.size() > 0) {
// There's at least one draft.
// Ask client to fire up a session to upload it.
m_client.UploadDrafts(m_activity);
Complete();
} else {
// TODO: If there's no drafts folder, or we're using Gmail, we can just delete the emails right now
Complete();
}
} CATCH_AS_FAILURE
return MojErrNone;
}
示例9: GetEmailResponse
MojErr SmtpSendMailCommand::GetEmailResponse(MojObject& response, MojErr err)
{
try {
ResponseToException(response, err);
MojString json;
response.toJson(json);
MojLogInfo(m_log, "got Email response");
MojLogDebug(m_log, "Response: %s", json.data());
// check the database result first
ErrorToException(err);
MojObject results;
err = response.getRequired(_T("results"), results);
ErrorToException(err);
if(results.size() == 0) {
throw MailException("email not found", __FILE__, __LINE__);
}
// There should only be one email for a given id
assert(results.size() == 1);
MojObject emailObj;
bool hasObject = results.at(0, emailObj);
if(!hasObject) {
throw MailException("error getting email from results", __FILE__, __LINE__);
}
EmailAdapter::ParseDatabaseObject(emailObj, m_email);
m_toAddress.clear();
if (m_email.GetTo()) {
for (EmailAddressList::iterator i = m_email.GetTo()->begin();
i != m_email.GetTo()->end();
i++)
m_toAddress.push_back((*i)->GetAddress());
}
if (m_email.GetCc()) {
for (EmailAddressList::iterator i = m_email.GetCc()->begin();
i != m_email.GetCc()->end();
i++)
m_toAddress.push_back((*i)->GetAddress());
}
if (m_email.GetBcc()) {
for (EmailAddressList::iterator i = m_email.GetBcc()->begin();
i != m_email.GetBcc()->end();
i++)
m_toAddress.push_back((*i)->GetAddress());
}
m_toIdx = 0;
// FIXME: Subscribe to file cache to pin cache contents
CalculateEmailSize();
} catch (const std::exception& e) {
HandleException(e, __func__, __FILE__, __LINE__);
} catch (...) {
HandleUnknownException();
}
return MojErrNone;
}
示例10: typeTest
MojErr MojObjectTest::typeTest()
{
MojObject obj;
MojObject obj2;
MojString str1;
MojString str2;
MojHashMap<MojObject, MojObject> map;
// null
MojTestAssert(obj.type() == MojObject::TypeUndefined);
MojTestAssert(obj.size() == 0);
MojTestAssert(obj.empty());
MojTestAssert(obj.boolValue() == false);
MojTestAssert(obj.intValue() == 0);
MojTestAssert(obj.decimalValue() == MojDecimal());
MojErr err = obj.stringValue(str1);
MojTestErrCheck(err);
MojTestAssert(str1 == _T("null"));
err = map.put(obj, obj);
MojTestErrCheck(err);
MojTestAssert(map.contains(obj));
MojTestAssert(obj == obj2);
MojTestAssert(obj.compare(obj2) == 0);
err = obj.coerce(MojObject::TypeNull);
MojTestErrCheck(err);
MojTestAssert(obj.type() == MojObject::TypeNull);
err = obj.coerce(MojObject::TypeString);
MojTestErrCheck(err);
MojTestAssert(obj == str1);
err = obj.coerce(MojObject::TypeBool);
MojTestErrCheck(err);
MojTestAssert(obj == true);
err = obj.coerce(MojObject::TypeInt);
MojTestErrCheck(err);
MojTestAssert(obj == 1);
err = obj.coerce(MojObject::TypeDecimal);
MojTestErrCheck(err);
MojTestAssert(obj.type() == MojObject::TypeDecimal && obj == MojDecimal(1, 0));
err = obj.coerce(MojObject::TypeObject);
MojTestErrCheck(err);
MojTestAssert(obj.type() == MojObject::TypeObject);
err = obj.coerce(MojObject::TypeArray);
MojTestErrCheck(err);
MojTestAssert(obj.type() == MojObject::TypeArray);
// object
err = obj.put(_T("hello"), 5);
MojTestErrCheck(err);
MojTestAssert(obj.type() == MojObject::TypeObject);
MojTestAssert(obj.size() == 1);
MojTestAssert(!obj.empty());
MojTestAssert(obj.boolValue() == true);
MojTestAssert(obj.intValue() == 0);
MojTestAssert(obj.decimalValue() == MojDecimal());
err = obj.stringValue(str1);
MojTestErrCheck(err);
MojTestAssert(str1 == _T("{\"hello\":5}"));
err = map.put(obj, obj);
MojTestErrCheck(err);
MojTestAssert(map.contains(obj));
obj.clear(MojObject::TypeObject);
MojTestAssert(obj.type() == MojObject::TypeObject);
MojTestAssert(obj.size() == 0);
MojTestAssert(obj.empty());
MojTestAssert(obj.boolValue() == false);
MojTestAssert(obj.intValue() == 0);
MojTestAssert(obj.decimalValue() == MojDecimal());
err = obj.stringValue(str1);
MojTestErrCheck(err);
MojTestAssert(str1 == _T("{}"));
// array
for (int i = 0; i < 1000; ++i) {
err = obj.push(i);
MojTestErrCheck(err);
}
MojTestAssert(obj.type() == MojObject::TypeArray);
MojTestAssert(obj.size() == 1000);
MojTestAssert(!obj.empty());
MojTestAssert(obj.boolValue() == true);
MojTestAssert(obj.intValue() == 0);
MojTestAssert(obj.decimalValue() == MojDecimal());
for (int i = 0; i < 1000; ++i) {
MojTestAssert(obj.at(i, obj2));
MojTestAssert(obj2 == i);
}
MojTestAssert(!obj.at(1000, obj2));
err = obj.setAt(1001, 1001);
MojTestErrCheck(err);
MojTestAssert(obj.size() == 1002);
MojTestAssert(obj.at(1000, obj2));
MojTestAssert(obj2.type() == MojObject::TypeUndefined);
obj.clear(MojObject::TypeArray);
MojTestAssert(obj.size() == 0);
MojTestAssert(obj.empty());
MojTestAssert(obj.boolValue() == false);
MojTestAssert(obj.intValue() == 0);
MojTestAssert(obj.decimalValue() == MojDecimal());
err = obj.stringValue(str1);
MojTestErrCheck(err);
MojTestAssert(str1 == _T("[]"));
//.........这里部分代码省略.........
示例11: getTest
MojErr MojObjectTest::getTest(const MojObject& obj)
{
MojObject obj2;
MojObject obj3;
MojObject array1;
MojString str1;
MojSize size;
size = obj.size();
MojTestAssert(size == 10);
MojTestAssert(obj.get(_T("object"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeObject);
MojTestAssert(obj2.get(_T("nested"), obj3));
MojErr err = obj3.stringValue(str1);
MojTestErrCheck(err);
MojTestAssert(str1 == _T("howdy"));
MojTestAssert(obj.get(_T("string"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeString);
err = obj2.stringValue(str1);
MojTestErrCheck(err);
MojTestAssert(str1 == _T("howdy"));
MojTestAssert(obj.get(_T("bool1"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeBool);
MojTestAssert(obj2 == true);
MojTestAssert(obj2 != false);
MojTestAssert(obj.get(_T("bool2"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeBool);
MojTestAssert(obj2 == false);
MojTestAssert(obj2 != true);
MojTestAssert(obj.get(_T("MojDecimal1"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeDecimal);
MojTestAssert(obj2 == MojDecimal(0, 100000));
MojTestAssert(obj2 != MojDecimal(2.34));
MojTestAssert(obj.get(_T("MojDecimal2"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeDecimal);
MojTestAssert(obj2 == MojDecimal(2.34));
MojTestAssert(obj2 != MojDecimal(0.1));
MojTestAssert(obj.get(_T("int1"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeInt);
MojTestAssert(obj2 == 50);
MojTestAssert(obj2 != -260000000000LL);
MojTestAssert(obj.get(_T("int2"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeInt);
MojTestAssert(obj2 == -260000000000LL);
MojTestAssert(obj2 != 50);
MojTestAssert(obj.get(_T("null"), obj2));
MojTestAssert(obj2.type() == MojObject::TypeNull);
// array
MojTestAssert(obj.get(_T("array"), array1));
MojTestAssert(array1.type() == MojObject::TypeArray);
MojTestAssert(array1.size() == 8);
MojTestAssert(array1.at(0, obj2));
MojTestAssert(obj2.type() == MojObject::TypeObject);
MojTestAssert(obj2.empty());
MojTestAssert(array1.at(1, obj2));
MojTestAssert(obj2.type() == MojObject::TypeArray);
MojTestAssert(obj2.empty());
MojTestAssert(array1.at(2, obj2));
MojTestAssert(obj2.type() == MojObject::TypeString);
err = obj2.stringValue(str1);
MojTestErrCheck(err);
MojTestAssert(str1 == _T("howdy"));
MojTestAssert(array1.at(3, obj2));
MojTestAssert(obj2.type() == MojObject::TypeBool);
MojTestAssert(obj2 == false);
MojTestAssert(array1.at(4, obj2));
MojTestAssert(obj2.type() == MojObject::TypeDecimal);
MojTestAssert(obj2 == MojDecimal(3.14));
MojTestAssert(array1.at(5, obj2));
MojTestAssert(obj2.type() == MojObject::TypeInt);
MojTestAssert(obj2 == 100);
MojTestAssert(array1.at(6, obj2));
MojTestAssert(obj2.type() == MojObject::TypeNull);
MojTestAssert(array1.at(7, obj2));
MojTestAssert(obj2.type() == MojObject::TypeInt);
MojTestAssert(obj2 == 4);
MojTestAssert(!array1.at(8, obj2));
return MojErrNone;
}
示例12: GetDeletedEmailsResponse
MojErr ReconcileEmailsCommand::GetDeletedEmailsResponse(MojObject& response, MojErr err)
{
try {
MojLogDebug(m_log, "Got local deleted emails response: %s", AsJsonString(response).c_str());
// Check database response
ErrorToException(err);
MojObject results;
err = response.getRequired("results", results);
ErrorToException(err);
if(results.size() > 0) {
MojLogInfo(m_log, "Got %d local deleted emails", results.size());
}
MojObject::ArrayIterator it;
err = results.arrayBegin(it);
ErrorToException(err);
// Read email properties: _id, UID, flags
// If you need additional properties, modify the database query
for (; it != results.arrayEnd(); ++it) {
MojObject& emailObj = *it;
MojObject id;
err = emailObj.getRequired(PopEmailAdapter::ID, id);
ErrorToException(err);
MojString uid;
err = emailObj.getRequired(PopEmailAdapter::SERVER_UID, uid);
ErrorToException(err);
std::string uidStr(uid);
m_localDeletedEmailUids.push_back(LocalDeletedEmailInfo(id, uidStr));
ReconcileInfoPtr infoPtr = m_reconcileUidMap[uidStr];
if (infoPtr.get()) {
m_reconcileUidMap.erase(std::string(uid));
UidMap::MessageInfo info = infoPtr->GetMessageInfo();
int msgNum = info.GetMessageNumber();
m_reconcileMsgNumMap.erase(msgNum);
}
}
bool hasMore = DatabaseAdapter::GetNextPage(response, m_localEmailsPage);
if(hasMore) {
// Get next batch of emails
MojLogDebug(m_log, "getting another batch of local deleted emails");
GetLocalDeletedEmails();
} else {
MojLogDebug(m_log, "Got old emails cache");
GetUidCache();
}
} catch(const std::exception& e) {
MojLogError(m_log, "Failed to sync folder: %s", e.what());
Failure(e);
} catch(...) {
MojLogError(m_log, "Uncaught exception %s", __PRETTY_FUNCTION__);
MailException exc("Unable to get deleted emails", __FILE__, __LINE__);
Failure(exc);
}
return MojErrNone;
}