本文整理汇总了C++中MojObject::push方法的典型用法代码示例。如果您正苦于以下问题:C++ MojObject::push方法的具体用法?C++ MojObject::push怎么用?C++ MojObject::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojObject
的用法示例。
在下文中一共展示了MojObject::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: includeDeleted
MojErr MojDbQuery::includeDeleted(bool val)
{
if (val) {
MojObject array;
MojErr err = array.push(false);
MojErrCheck(err);
err = array.push(true);
MojErrCheck(err);
// TODO: Move string constants to single location
err = where(DelKey, MojDbQuery::OpEq, array);
MojErrCheck(err);
}
return MojErrNone;
}
示例2: batchPutLargeArrayObj
MojErr MojDbPerfCreateTest::batchPutLargeArrayObj(MojDb& db, const MojChar* kindId, MojUInt64& lgArrayObjTime)
{
timespec startTime;
startTime.tv_nsec = 0;
startTime.tv_sec = 0;
timespec endTime;
endTime.tv_nsec = 0;
endTime.tv_sec = 0;
MojObject objArray;
for (MojUInt64 i = 0; i < numInsert; i++) {
MojObject obj;
MojErr err = obj.putString(MojDb::KindKey, kindId);
MojTestErrCheck(err);
err = createLargeArrayObj(obj, i);
MojTestErrCheck(err);
err = objArray.push(obj);
MojTestErrCheck(err);
}
MojObject::ArrayIterator begin;
MojErr err = objArray.arrayBegin(begin);
MojTestErrCheck(err);
MojObject::ConstArrayIterator end = objArray.arrayEnd();
clock_gettime(CLOCK_REALTIME, &startTime);
err = db.put(begin, end);
MojTestErrCheck(err);
clock_gettime(CLOCK_REALTIME, &endTime);
lgArrayObjTime += timeDiff(startTime, endTime);
totalTestTime += timeDiff(startTime, endTime);
return MojErrNone;
}
示例3: del
MojErr MojDb::del(const MojObject* idsBegin, const MojObject* idsEnd, MojUInt32& countOut, MojObject& arrOut, MojUInt32 flags, MojDbReqRef req)
{
MojAssert(idsBegin || idsBegin == idsEnd);
MojAssert(idsEnd >= idsBegin);
MojLogTrace(s_log);
countOut = 0;
MojErr err = beginReq(req);
MojErrCheck(err);
// do the dels
MojUInt32 count= 0;
for (const MojObject* i = idsBegin; i != idsEnd; ++i) {
MojObject foundObj;
bool found = false;
err = delImpl(*i, found, foundObj, req, flags);
MojErrCheck(err);
if (found) {
count++;
err = arrOut.push(foundObj);
MojErrCheck(err);
}
}
// commit txn
err = req->end();
MojErrCheck(err);
countOut = count;
return MojErrNone;
}
示例4: batchPutLargeArrayObj
MojErr MojDbPerfCreateTest::batchPutLargeArrayObj(MojDb& db, const MojChar* kindId, MojTime& lgArrayObjTime)
{
MojTime startTime;
MojTime endTime;
MojObject objArray;
for (MojUInt64 i = 0; i < numInsert; i++) {
MojObject obj;
MojErr err = obj.putString(MojDb::KindKey, kindId);
MojTestErrCheck(err);
err = createLargeArrayObj(obj, i);
MojTestErrCheck(err);
err = objArray.push(obj);
MojTestErrCheck(err);
}
MojObject::ArrayIterator begin;
MojErr err = objArray.arrayBegin(begin);
MojTestErrCheck(err);
MojObject::ConstArrayIterator end = objArray.arrayEnd();
err = MojGetCurrentTime(startTime);
MojTestErrCheck(err);
err = db.put(begin, end);
MojTestErrCheck(err);
err = MojGetCurrentTime(endTime);
MojTestErrCheck(err);
lgArrayObjTime += (endTime - startTime);
totalTestTime += (endTime - startTime);
return MojErrNone;
}
示例5: updateKind
MojErr MojDbPerfUpdateTest::updateKind(MojDb& db, const MojChar* kindId, const MojChar* kindJson, const MojChar* extraIdxJson, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64))
{
// register all the kinds
MojTime time;
MojErr err = putKinds(db, time);
MojTestErrCheck(err);
// put objects using createFn
MojObject objs;
err = putObjs(db, kindId, numObjectsBeforeUpdateKind, createFn, objs);
MojTestErrCheck(err);
// add an index
MojObject kindObj;
err = kindObj.fromJson(kindJson);
MojTestErrCheck(err);
MojObject indexes;
kindObj.get(_T("indexes"), indexes);
MojTestErrCheck(err);
MojObject extraIdx;
err = extraIdx.fromJson(extraIdxJson);
MojTestErrCheck(err);
indexes.push(extraIdx);
err = kindObj.put(_T("indexes"), indexes);
MojTestErrCheck(err);
MojTime addIndexTime;
MojTime dropIndexTime;
err = timeUpdateKind(db, kindJson, kindObj, addIndexTime, dropIndexTime);
MojTestErrCheck(err);
MojUInt64 addTime = addIndexTime.microsecs();
MojUInt64 dropTime = dropIndexTime.microsecs();
err = MojPrintF("\n -------------------- \n");
MojTestErrCheck(err);
err = MojPrintF(" updating kind %s - adding index %s %llu times took: %llu microsecs\n", kindId, extraIdxJson, numUpdateKindIterations, addTime);
MojTestErrCheck(err);
err = MojPrintF(" time per add/reindex: %llu microsecs\n", (addTime) / (numUpdateKindIterations));
MojTestErrCheck(err);
err = MojPrintF(" updating kind %s - dropping index %s %llu times took: %llu microsecs\n", kindId, extraIdxJson, numUpdateKindIterations, dropTime);
MojTestErrCheck(err);
err = MojPrintF(" time per drop: %llu microsecs", (dropTime) / (numUpdateKindIterations));
MojTestErrCheck(err);
err = MojPrintF("\n\n");
MojTestErrCheck(err);
MojString buf;
err = buf.format("Updating kind %s - adding index %s %llu times,%s,%llu,%llu,%llu,\nUpdating kind %s - dropping index %s %llu times,%s,%llu,%llu,%llu,\n",
kindId, extraIdxJson, numUpdateKindIterations, kindId, addTime, addTime/numUpdateKindIterations, addTime/(1*numUpdateKindIterations),
kindId, extraIdxJson, numUpdateKindIterations, kindId, dropTime, dropTime/numUpdateKindIterations, dropTime/(1*numUpdateKindIterations));
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
return MojErrNone;
}
示例6: PopulatePurgeIds
void MojoDBProxy::PopulatePurgeIds(MojObject& ids)
{
int count = PurgeBatchSize;
while (!m_oldTokens.empty()) {
boost::shared_ptr<MojoDBPersistToken> pt = m_oldTokens.front();
m_oldTokens.pop_front();
ids.push(pt->GetId());
if (--count == 0)
return;
}
}
示例7: SerializeRecipients
void EmailAdapter::SerializeRecipients(const char* type, const EmailAddressListPtr& list, MojObject& recipients)
{
EmailAddressList::const_iterator it;
for(it = list->begin(); it != list->end(); ++it) {
EmailAddressPtr address = *it;
if (!address.get()) {
throw MailException("Unable to serialize email: one of recipients is null", __FILE__, __LINE__);
}
MojObject recipient;
SerializeAddress(type, address, recipient);
MojErr err = recipients.push(recipient);
ErrorToException(err);
}
}
示例8: PushJson
void ResourceContainer::PushJson(MojObject& array) const
{
MojErr errs = MojErrNone;
MojObject rep(MojObject::TypeObject);
MojErr err = ToJson(rep);
MojErrAccumulate(errs, err);
err = array.push(rep);
MojErrAccumulate(errs, err);
if (errs) {
throw std::runtime_error("Unable to convert resource container to "
"JSON object");
}
}
示例9: putObjs
MojErr MojDbPerfUpdateTest::putObjs(MojDb& db, const MojChar* kindId, MojUInt64 numInsert,
MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64), MojObject& objs)
{
for (MojUInt64 i = 0; i < numInsert; i++) {
MojObject obj;
MojErr err = obj.putString(MojDb::KindKey, kindId);
MojTestErrCheck(err);
err = (*this.*createFn)(obj, i);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
err = objs.push(obj);
MojTestErrCheck(err);
}
return MojErrNone;
}
示例10: SerializeParts
void EmailAdapter::SerializeParts(const EmailPartList& partsList, MojObject& partsArrayObj)
{
EmailPartList::const_iterator it;
for(it = partsList.begin(); it != partsList.end(); ++it) {
EmailPartPtr emailPart = *it;
if (!emailPart.get()) {
throw MailException("Unable to serialize email: one of the parts is null", __FILE__, __LINE__);
}
MojObject partObj;
MojErr err;
// Add part information to the part object
err = partObj.putString(Part::TYPE, GetPartTypeAsString(emailPart));
ErrorToException(err);
err = partObj.putString(Part::MIME_TYPE, emailPart->GetMimeType().c_str());
ErrorToException(err);
DatabaseAdapter::PutOptionalString(partObj, Part::PATH, emailPart->GetLocalFilePath());
DatabaseAdapter::PutOptionalString(partObj, Part::NAME, emailPart->GetDisplayName());
DatabaseAdapter::PutOptionalString(partObj, Part::CONTENT_ID, emailPart->GetContentId());
DatabaseAdapter::PutOptionalString(partObj, Part::ENCODING, emailPart->GetEncoding());
DatabaseAdapter::PutOptionalString(partObj, Part::CHARSET, emailPart->GetCharset());
DatabaseAdapter::PutOptionalString(partObj, Part::SECTION, emailPart->GetSection());
if(emailPart->GetEstimatedSize() >= 0) {
err = partObj.put(Part::ESTIMATED_SIZE, emailPart->GetEstimatedSize());
ErrorToException(err);
}
if(emailPart->GetEncodedSize() >= 0) {
err = partObj.put(Part::ENCODED_SIZE, emailPart->GetEncodedSize());
ErrorToException(err);
}
// Add to partsArrayObject
err = partsArrayObj.push(partObj);
ErrorToException(err);
}
}
示例11: HandleHeadersResponse
MojErr SearchFolderCommand::HandleHeadersResponse()
{
CommandTraceFunction();
try {
MojErr err;
MojObject response;
MojObject results;
BOOST_FOREACH(const FetchUpdate& update, m_headersResponseParser->GetUpdates()) {
const boost::shared_ptr<ImapEmail>& email = update.email;
if (email.get() && !email->IsDeleted()) {
MojObject emailObj;
// Set folderId
email->SetFolderId(m_folderId);
ImapEmailAdapter::SerializeToDatabaseObject(*email, emailObj);
err = results.push(emailObj);
ErrorToException(err);
}
}
err = response.put("results", results);
ErrorToException(err);
if (m_searchRequest->GetServiceMessage().get()) {
m_searchRequest->GetServiceMessage()->replySuccess(response);
m_searchRequest->SetServiceMessage(NULL);
}
Done();
} CATCH_AS_FAILURE
return MojErrNone;
}
示例12: findImLoginStateResult
MojErr OnEnabledHandler::findImLoginStateResult(MojObject& payload, MojErr err)
{
MojLogTrace(IMServiceApp::s_log);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogCritical(IMServiceApp::s_log, _T("findImLoginStateResult failed: error %d - %s"), err, error.data());
}
else {
// "results" in result
MojObject results;
payload.get(_T("results"), results);
// check to see if array is empty - normally it will be if this is a newly created account. There should never be more than 1 item here
if (!results.empty()){
IMServiceHandler::logMojObjectJsonString(_T("findImLoginStateResult found existing imLoginState record: %s"), payload);
// if there is a record already, make sure the account id matches.
MojObject loginState;
MojObject::ConstArrayIterator itr = results.arrayBegin();
bool foundOne = false;
while (itr != results.arrayEnd()) {
if (foundOne) {
MojLogError(IMServiceApp::s_log,
_T("findImLoginStateResult: found more than one ImLoginState with same username/serviceName - using the first one"));
break;
}
loginState = *itr;
foundOne = true;
itr++;
}
MojString accountId;
MojErr err = loginState.getRequired("accountId", accountId);
if (err) {
MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: missing accountId in loginState entry"));
}
if (0 != accountId.compare(m_accountId)) {
MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: existing loginState record does not have matching account id. accountId = %s"), accountId.data());
// delete this record
MojObject idsToDelete;
MojString dbId;
err = loginState.getRequired("_id", dbId);
if (err) {
MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: missing dbId in loginState entry"));
}
else {
idsToDelete.push(dbId);
// luna://com.palm.db/del '{"ids":[2]}'
MojLogInfo(IMServiceApp::s_log, _T("findImLoginStateResult: deleting loginState entry id: %s"), dbId.data());
err = m_dbClient.del(this->m_deleteImLoginStateSlot, idsToDelete.arrayBegin(), idsToDelete.arrayEnd());
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: db.del() failed: error %d - %s"), err, error.data());
}
}
}
// if the account id matches, leave the old record and we are done
else return MojErrNone;
}
// no existing record found or the old one was deleted - create a new one
MojLogInfo(IMServiceApp::s_log, _T("findImLoginStateResult: no matching loginState record found for %s, %s. creating a new one"), m_username.data(), m_serviceName.data());
MojObject imLoginState;
imLoginState.putString(_T("_kind"), IM_LOGINSTATE_KIND);
imLoginState.put(_T("accountId"), m_accountId);
imLoginState.put(_T("serviceName"), m_serviceName);
imLoginState.put(_T("username"), m_username);
imLoginState.put(_T("capabilityId"), m_capabilityProviderId);
imLoginState.putString(_T("state"), LOGIN_STATE_OFFLINE);
imLoginState.putInt(_T("availability"), PalmAvailability::ONLINE); //default to online so we automatically login at first
imLoginState.put(_T("config"), m_config);
MojErr err = m_dbClient.put(m_addImLoginStateSlot, imLoginState);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: db.put() failed: error %d - %s"), err, error.data());
}
}
return err;
}
示例13: 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("[]"));
//.........这里部分代码省略.........
示例14: simpleTest
MojErr MojDbSearchTest::simpleTest(MojDb& db)
{
// just foo
MojErr err = check(db, _T("bogus"), _T("[]"));
MojTestErrCheck(err);
err = check(db, _T("f"), _T("[1,2,3,4]"));
MojTestErrCheck(err);
err = check(db, _T("F"), _T("[1,2,3,4]"));
MojTestErrCheck(err);
err = check(db, _T("fo"), _T("[1,2,3,4]"));
MojTestErrCheck(err);
err = check(db, _T("four"), _T("[1,3,4]"));
MojTestErrCheck(err);
err = check(db, _T("score"), _T("[1]"));
MojTestErrCheck(err);
err = check(db, _T("four years"), _T("[1]"));
MojTestErrCheck(err);
err = check(db, _T("Four Years"), _T("[1]"));
MojTestErrCheck(err);
err = check(db, _T("four decades"), _T("[]"));
MojTestErrCheck(err);
err = check(db, _T("fathers forth"), _T("[2,3]"));
MojTestErrCheck(err);
err = check(db, _T("four f"), _T("[1,3,4]"));
MojTestErrCheck(err);
err = check(db, _T("four f fo fou"), _T("[1,3,4]"));
MojTestErrCheck(err);
// bar and foo
err = check(db, _T("f"), _T("[3]"), NULL, 2);
MojTestErrCheck(err);
// order by bar
err = check(db, _T("f"), _T("[4,3,2,1]"), _T("bar"));
MojTestErrCheck(err);
err = check(db, _T("f"), _T("[1,2,3,4]"), _T("bar"), MojObject::Undefined, true);
MojTestErrCheck(err);
err = check(db, _T("f"), _T("[4,3,1,2]"), _T("foo"));
MojTestErrCheck(err);
// array value for bar
MojObject array;
err = array.push(1);
MojErrCheck(err);
err = array.push(2);
MojErrCheck(err);
err = check(db, _T("f"), _T("[4,3]"), _T("bar"), array);
MojTestErrCheck(err);
// limit
MojDbQuery query;
err = initQuery(query, _T("f"));
MojTestErrCheck(err);
query.limit(2);
err = check(db, query, _T("[1,2]"));
MojTestErrCheck(err);
err = initQuery(query, _T("f"), _T("bar"));
MojTestErrCheck(err);
query.limit(2);
err = check(db, query, _T("[4,3]"));
MojTestErrCheck(err);
// accent insensitivity
err = check(db, _T("COTE"), _T("[5,6,7,8,9]"));
MojTestErrCheck(err);
// case-insensitive ordering
err = check(db, _T("a"), _T("[12,13,11]"), _T("foo"));
MojTestErrCheck(err);
// multi-prop
query.clear();
err = query.from(_T("SearchTest:1"));
MojTestErrCheck(err);
MojString val;
err = val.assign(_T("test"));
MojTestErrCheck(err);
err = query.where(_T("multiprop"), MojDbQuery::OpSearch, val, MojDbCollationPrimary);
MojTestErrCheck(err);
err = check(db, query, _T("[14,15]"));
MojTestErrCheck(err);
return MojErrNone;
}
示例15: UpdateSyncState
void SyncStateUpdater::UpdateSyncState(MojSignal<>::SlotRef slot, const SyncState& syncState, bool clearSyncState)
{
m_doneSignal.connect(slot);
MojErr err;
MojObject batchPayload;
MojObject batchOperations;
// Delete old sync state
MojObject delPayload;
MojDbQuery query;
err = query.from(SyncStateAdapter::SYNC_STATE_KIND);
ErrorToException(err);
MojString capabilityProvider;
capabilityProvider.assign(m_capabilityProvider.c_str());
err = query.where(SyncStateAdapter::CAPABILITY_PROVIDER, MojDbQuery::OpEq, capabilityProvider);
ErrorToException(err);
err = query.where(SyncStateAdapter::ACCOUNT_ID, MojDbQuery::OpEq, syncState.GetAccountId());
ErrorToException(err);
err = query.where(SyncStateAdapter::COLLECTION_ID, MojDbQuery::OpEq, syncState.GetCollectionId());
ErrorToException(err);
MojObject queryObj;
err = query.toObject(queryObj);
ErrorToException(err);
err = delPayload.put("query", queryObj);
ErrorToException(err);
MojObject delOperation;
err = delOperation.putString("method", "del");
ErrorToException(err);
err = delOperation.put("params", delPayload);
ErrorToException(err);
err = batchOperations.push(delOperation);
ErrorToException(err);
if(!clearSyncState) { // Store new sync state
MojObject putPayload;
MojObject syncStateObj;
SyncStateAdapter::SerializeToDatabaseObject(syncState, syncStateObj, m_capabilityProvider.c_str(), m_busAddress.c_str());
MojObject objects;
err = objects.push(syncStateObj);
ErrorToException(err);
err = putPayload.put("objects", objects);
ErrorToException(err);
MojObject putOperation;
err = putOperation.putString("method", "put");
ErrorToException(err);
err = putOperation.put("params", putPayload);
ErrorToException(err);
err = batchOperations.push(putOperation);
ErrorToException(err);
}
err = batchPayload.put("operations", batchOperations);
ErrorToException(err);
// Note: batch operations are not atomic, this is just for convenience and performance
m_busClient.SendRequest(m_updateSlot, "com.palm.tempdb", "batch", batchPayload);
}