本文整理汇总了C++中MojObject::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ MojObject::empty方法的具体用法?C++ MojObject::empty怎么用?C++ MojObject::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojObject
的用法示例。
在下文中一共展示了MojObject::empty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getAccountConfigResult
MojErr OnEnabledHandler::getAccountConfigResult(MojObject& payload, MojErr err)
{
MojLogTrace(IMServiceApp::s_log);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogCritical(IMServiceApp::s_log, "getAccountConfig failed: error %d - %s", err, error.data());
}
else
{
MojObject results;
payload.get("results", results);
if (!results.empty())
{
m_config = *results.arrayBegin();
}
}
if (m_enable) {
err = accountEnabled();
} else {
err = accountDisabled();
}
return err;
}
示例2: findBuddyResult
/*
* Result of query for buddy with given username and serviceName
*
* If the buddy is found, we can send no matter what. If buddy is not found, we need to check if this service allows sending IM messages
* to non buddies (gtalk does not allow this, aol does)
*/
MojErr SendOneMessageHandler::findBuddyResult(MojObject& result, MojErr findErr)
{
if (findErr) {
MojString error;
MojErrToString(findErr, error);
MojLogError(IMServiceApp::s_log, _T("findBuddyResult: error %d - %s"), findErr, error.data());
// not much we can do here...
failMessage(ERROR_SEND_GENERIC_ERROR);
} else {
// log the results
MojString mojStringJson;
result.toJson(mojStringJson);
MojLogDebug(IMServiceApp::s_log, _T("findBuddyResult result: %s"), mojStringJson.data());
// "results" in result
MojObject results;
result.get(_T("results"), results);
// check to see if array is empty - there should really always be 0 or 1 item here
if (!results.empty()){
// buddy is on the list - send to the transport
MojLogInfo(IMServiceApp::s_log, _T("findBuddyResult - user is on buddy list. No need to check account template."));
sendToTransport();
}
else {
MojLogInfo(IMServiceApp::s_log, _T("findBuddyResult - no buddy found. Need to check account template if this is allowed"));
// check palm://com.palm.service.accounts/listAccountTemplates {"capability":"MESSAGING"} to get a list of account templates that support messaging.
// If the account template includes "chatWithNonBuddies":false, it should fail to send.
MojLogInfo(IMServiceApp::s_log, "Issuing listAccountTemplates request to com.palm.service.accounts");
// parameters: {“capability”:”MESSAGING”}
MojObject params;
params.putString("capability", "MESSAGING");
// Get a request object from the service
MojRefCountedPtr<MojServiceRequest> req;
MojErr err = m_service->createRequest(req);
if (!err) {
err = req->send(m_listAccountSlot, "com.palm.service.accounts", "listAccountTemplates", params);
}
if (err) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("findBuddyResult failed to send request to accounts: error %d - %s"), err, error.data());
// not much we can do here...don't leave message still pending
failMessage(ERROR_SEND_GENERIC_ERROR);
}
}
}
return MojErrNone;
}
示例3: 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;
}
示例4: getAccountInfoResult
MojErr OnEnabledHandler::getAccountInfoResult(MojObject& payload, MojErr resultErr)
{
MojLogTrace(IMServiceApp::s_log);
IMServiceHandler::logMojObjectJsonString(_T("OnEnabledHandler::getAccountInfoResult payload: %s"), payload);
if (resultErr != MojErrNone) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler getAccountInfo result error %d"), resultErr);
return resultErr;
}
MojObject result;
MojErr err = payload.getRequired("result", result);
if (err != MojErrNone || result.empty()) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult result empty or error %d"), err);
return err;
}
err = result.getRequired("_id", m_accountId);
if (err != MojErrNone || m_accountId.empty()) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult accountId empty or error %d"), err);
return err;
}
err = result.getRequired("username", m_username);
if (err != MojErrNone || m_username.empty()) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult username empty or error %d"), err);
return err;
}
{
MojObject capabilities;
MojObject messagingObject;
result.get("capabilityProviders", capabilities);
getMessagingCapabilityObject(capabilities, messagingObject);
err = messagingObject.getRequired("serviceName", m_serviceName);
if (m_serviceName.empty()) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult serviceName empty"));
return err;
}
}
if (m_enable)
{
MojDbQuery query;
query.from("com.palm.config.libpurple:1");
query.where("accountId", MojDbQuery::OpEq, m_accountId);
query.limit(1);
err = m_dbClient.find(m_getAccountConfigSlot, query);
}
else
{
err = accountDisabled();
}
return err;
}
示例5: getAccountInfoResult
MojErr OnEnabledHandler::getAccountInfoResult(MojObject& payload, MojErr resultErr)
{
MojLogTrace(IMServiceApp::s_log);
IMServiceHandler::logMojObjectJsonString(_T("OnEnabledHandler::getAccountInfoResult payload: %s"), payload);
if (resultErr != MojErrNone) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler getAccountInfo result error %d"), resultErr);
return resultErr;
}
MojObject result;
MojErr err = payload.getRequired("result", result);
if (err != MojErrNone || result.empty()) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult result empty or error %d"), err);
return err;
}
MojString accountId;
err = result.getRequired("_id", accountId);
if (err != MojErrNone || accountId.empty()) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult accountId empty or error %d"), err);
return err;
}
MojString username;
err = result.getRequired("username", username);
if (err != MojErrNone || username.empty()) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult username empty or error %d"), err);
return err;
}
MojString serviceName;
getServiceNameFromCapabilityId(serviceName);
if (serviceName.empty()) {
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult serviceName empty"));
return err;
}
if (m_enable) {
err = accountEnabled(accountId, serviceName, username);
} else {
err = accountDisabled(accountId, serviceName, username);
}
return err;
}
示例6: readAccountIdFromResults
/*
* Parse the account id from the results object for the accountId query
* saved in m_accountId member variable
*
*/
MojErr SendOneMessageHandler::readAccountIdFromResults(MojObject& result)
{
// log the results
MojString mojStringJson;
result.toJson(mojStringJson);
MojLogDebug(IMServiceApp::s_log, _T("readAccountIdFromResults result: %s"), mojStringJson.data());
// "results" in result
MojObject results;
result.get(_T("results"), results);
// check to see if array is empty - there should really always be 1 item here
if (!results.empty()){
// get the db id of the buddy
MojObject loginState;
MojObject::ConstArrayIterator itr = results.arrayBegin();
bool foundOne = false;
while (itr != results.arrayEnd()) {
if (foundOne) {
MojLogError(IMServiceApp::s_log,
_T("readAccountIdFromResults: found more than one ImLoginState with same username/serviceName - using the first one"));
break;
}
loginState = *itr;
foundOne = true;
itr++;
}
// create the DB object
MojErr err = loginState.getRequired("accountId", m_accountId);
if (err) {
MojLogError(IMServiceApp::s_log, _T("readAccountIdFromResults: missing accountId in loginState entry"));
}
MojLogInfo(IMServiceApp::s_log, _T("readAccountIdFromResults - accountId: %s. "), m_accountId.data());
}
else {
MojLogError(IMServiceApp::s_log, _T("readAccountIdFromResults: no matching loginState record found for %s"), m_serviceName.data());
}
return MojErrNone;
}
示例7: listAccountResult
/*
* Result callback for the listAccountsTemplate
*
* result list form:
* {
"templateId": "com.palm.aol",
"loc_name": "AOL",
"validator": "palm://com.palm.imaccountvalidator/checkCredentials",
"capabilityProviders": [
{
"capability": "MESSAGING",
"capabilitySubtype": "IM",
"id": "com.palm.aol.aim",
"loc_name": "AIM",
"loc_shortName": "AIM",
"icon": {
"loc_32x32": "/usr/palm/public/accounts/com.palm.aol/images/aim32x32.png",
"loc_48x48": "/usr/palm/public/accounts/com.palm.aol/images/aim48x48.png",
"splitter": "/usr/palm/public/accounts/com.palm.aol/images/aim_transport_splitter.png"
},
"implementation": "palm://com.palm.imlibpurple/",
"onEnabled": "palm://com.palm.imlibpurple/onEnabled",
"serviceName": "type_aim",
"dbkinds": {
"immessage": "com.palm.immessage.libpurple",
"imcommand": "com.palm.imcommand.libpurple"
}
}
]
},
*/
MojErr SendOneMessageHandler::listAccountResult(MojObject& result, MojErr err)
{
if (err) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("listAccountTemplates failed. error %d - %s"), err, error.data());
// not much we can do here...don't leave message pending
failMessage(ERROR_SEND_GENERIC_ERROR);
}
else {
IMServiceHandler::logMojObjectJsonString(_T("listAccountTemplates success: %s"), result);
// if the flag is not there, assume we can send to a non buddy
// if we got here, the message is going to a non buddy
bool nonBuddyChatOK = true;
// find the template and provider for our service and look for "chatWithNonBuddies":false
// "results" in result
MojObject results;
result.get(_T("results"), results);
// check to see if array is empty - should not be...
if (!results.empty()){
// find the messaging capability object
MojObject capability;
MojObject accountTemplate;
MojString serviceName;
bool found = false;
bool foundService = false;
MojObject::ConstArrayIterator templItr = results.arrayBegin();
while (templItr != results.arrayEnd()) {
accountTemplate = *templItr;
IMServiceHandler::logMojObjectJsonString(_T("listAccountTemplates template: %s"), accountTemplate);
// now find the capabilityProviders array
MojObject providersArray;
found = accountTemplate.get(XPORT_CAPABILITY_PROVIDERS, providersArray);
if (found) {
MojObject::ConstArrayIterator capItr = providersArray.arrayBegin();
while (capItr != providersArray.arrayEnd()) {
capability = *capItr;
IMServiceHandler::logMojObjectJsonString(_T("listAccountTemplates capability: %s"), capability);
// find the one for our service
capability.get(XPORT_SERVICE_TYPE, serviceName, found);
if (found) {
MojLogInfo(IMServiceApp::s_log, _T("listAccountTemplates - capability service %s. "), serviceName.data());
if (0 == serviceName.compare(m_serviceName)) {
foundService = true;
found = capability.get("chatWithNonBuddies", nonBuddyChatOK);
MojLogInfo(IMServiceApp::s_log, _T("listAccountTemplates - found service %s. found %d, chatWithNonBuddies %d"), m_serviceName.data(), found, nonBuddyChatOK);
break;
}
}
else MojLogError(IMServiceApp::s_log, _T("error: no service name in capability provider"));
capItr++;
}
}
else MojLogError(IMServiceApp::s_log, _T("error: no provider array in templateId"));
if (foundService)
break;
templItr++;
}
}
if (nonBuddyChatOK){
// send to the transport
//.........这里部分代码省略.........
示例8: 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;
}
示例9: 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("[]"));
//.........这里部分代码省略.........
示例10: fromObject
MojErr MojDbQuery::fromObject(const MojObject& obj)
{
// TODO: validate against query schema
bool found;
MojErr err;
MojObject array;
MojString str;
// distinct
found = false;
err = obj.get(DistinctKey, str, found);
MojErrCheck(err);
if (found) {
err = distinct(str);
MojErrCheck(err);
// if "distinct" is set, force "distinct" column into "select".
err = select(str);
MojErrCheck(err);
// order
err = order(str);
MojErrCheck(err);
} else {
// select
if (obj.get(SelectKey, array)) {
if(array.empty()) {
MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: select clause but no selected properties"));
}
MojObject prop;
MojSize i = 0;
while (array.at(i++, prop)) {
MojErr err = prop.stringValue(str);
MojErrCheck(err);
err = select(str);
MojErrCheck(err);
}
}
// order
found = false;
err = obj.get(OrderByKey, str, found);
MojErrCheck(err);
if (found) {
err = order(str);
MojErrCheck(err);
}
}
// from
err = obj.getRequired(FromKey, str);
MojErrCheck(err);
err = from(str);
MojErrCheck(err);
// where
if (obj.get(WhereKey, array)) {
err = addClauses(m_whereClauses, array);
MojErrCheck(err);
}
// filter
if (obj.get(FilterKey, array)) {
err = addClauses(m_filterClauses, array);
MojErrCheck(err);
}
// desc
bool descVal;
if (obj.get(DescKey, descVal)) {
desc(descVal);
}
// limit
MojInt64 lim;
if (obj.get(LimitKey, lim)) {
if (lim < 0)
MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: negative query limit"));
} else {
lim = LimitDefault;
}
limit((MojUInt32) lim);
// page
MojObject pageObj;
if (obj.get(PageKey, pageObj)) {
Page pagec;
err = pagec.fromObject(pageObj);
MojErrCheck(err);
page(pagec);
}
bool incDel = false;
if (obj.get(IncludeDeletedKey, incDel) && incDel) {
err = includeDeleted();
MojErrCheck(err);
}
return MojErrNone;
}