本文整理汇总了C++中MojString::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ MojString::assign方法的具体用法?C++ MojString::assign怎么用?C++ MojString::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojString
的用法示例。
在下文中一共展示了MojString::assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getBestConnection
void ConnectionState::getBestConnection(MojString& connectionType, MojString& ipAddress)
{
if (ConnectionState::m_connState->m_wifiConnected)
{
connectionType.assign("wifi");
ipAddress = ConnectionState::m_connState->m_wifiIpAddress;
}
else
{
connectionType.assign("wan");
ipAddress = ConnectionState::m_connState->m_wanIpAddress;
}
}
示例2: addBuiltinProps
MojErr MojDbIndex::addBuiltinProps()
{
LOG_TRACE("Entering function %s", __FUNCTION__);
MojString idStr;
MojErr err = idStr.assign(MojDb::IdKey);
MojErrCheck(err);
if (m_propNames.find(idStr) == MojInvalidSize) {
MojObject idProp;
err = idProp.put(NameKey, idStr);
MojErrCheck(err);
err = addProp(idProp);
MojErrCheck(err);
}
if (m_includeDeleted && m_propNames.front() != MojDb::DelKey) {
MojObject delProp;
err = delProp.putString(NameKey, MojDb::DelKey);
MojErrCheck(err);
err = delProp.putBool(DefaultKey, false);
MojErrCheck(err);
err = addProp(delProp, true);
MojErrCheck(err);
MojAssert(m_propNames.front() == MojDb::DelKey);
}
m_idIndex = m_propNames.find(idStr);
MojAssert(m_idIndex != MojInvalidSize);
m_idIndex++; // account for prefix
return MojErrNone;
}
示例3: assertContainsText
MojErr MojDbIndexTest::assertContainsText(TestIndex& ti, MojObject id, const MojChar* str)
{
MojString strObj;
MojErr err = strObj.assign(str);
MojErrCheck(err);
MojRefCountedPtr<MojDbTextCollator> collator(new MojDbTextCollator);
MojAllocCheck(collator.get());
err = collator->init(_T("en_US"), MojDbCollationPrimary);
MojTestErrCheck(err);
MojDbKey key;
err = collator->sortKey(strObj, key);
MojTestErrCheck(err);
MojObjectWriter writer;
err = id.visit(writer);
MojTestErrCheck(err);
const MojByte* idData = NULL;
MojSize idSize = 0;
err = writer.buf().data(idData, idSize);
MojTestErrCheck(err);
err = key.byteVec().append(idData, idData + idSize);
MojTestErrCheck(err);
err = assertContains(ti, id, key);
MojTestErrCheck(err);
return MojErrNone;
}
示例4: testEnforce
MojErr MojDbQuotaTest::testEnforce(MojDb& db)
{
// set quota size to current usage
MojInt64 quotaUsage1 = 0;
MojErr err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojObject obj;
err = obj.putString(_T("owner"), _T("com.foo.bar"));
MojErrCheck(err);
err = obj.putInt(_T("size"), quotaUsage1);
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
err = put(db, MojTestKind1Objects[3]);
MojTestErrExpected(err, MojErrDbQuotaExceeded);
// make sure we can delete the kind
MojString kindStr;
err = kindStr.assign(_T("Test:1"));
MojTestErrCheck(err);
bool found = false;
err = db.delKind(kindStr, found);
MojTestErrCheck(err);
MojTestAssert(found);
return MojErrNone;
}
示例5: testKindPermissions
MojErr MojDbPermissionTest::testKindPermissions(MojDb& db)
{
MojObject kind;
MojErr err = kind.fromJson(MojTestKind1);
MojTestErrCheck(err);
// new kind, mismatched owner and caller
MojDbReq req(false);
err = req.domain(_T("com.bar"));
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, req);
MojTestErrExpected(err, MojErrDbPermissionDenied);
// new kind, matched owner and caller
err = req.domain(_T("com.foo"));
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, req);
MojTestErrCheck(err);
// existing kind, matched owner and caller
err = db.putKind(kind, MojDb::FlagNone, req);
MojTestErrCheck(err);
// existing kind, mismatched owner and caller
err = req.domain(_T("com.bar"));
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, req);
MojTestErrExpected(err, MojErrDbPermissionDenied);
// delKind, mismatched owner and caller
MojString id;
err = id.assign(_T("PermissionTest:1"));
MojTestErrCheck(err);
bool found = false;
err = db.delKind(id, found, MojDb::FlagNone, req);
MojTestErrExpected(err, MojErrDbPermissionDenied);
return MojErrNone;
}
示例6: createClause
MojErr MojDbQuery::createClause(WhereMap& map, const MojChar* propName, CompOp op, MojObject val, MojDbCollationStrength coll)
{
// construct the clause
MojErr err = MojErrNone;
WhereClause clause;
switch (op) {
case OpLessThan:
case OpLessThanEq:
// less-than ops define upper bound
err = clause.setUpper(op, val, coll);
MojErrCheck(err);
break;
default:
// everything else is stored as lower bound
err = clause.setLower(op, val, coll);
MojErrCheck(err);
break;
}
// add clause to map
MojString str;
err = str.assign(propName);
MojErrCheck(err);
err = map.put(str, clause);
MojErrCheck(err);
return MojErrNone;
}
示例7: InfoToJson
MojErr ContainerManager::InfoToJson(MojObject& rep) const
{
MojObject containers(MojObject::TypeArray);
std::for_each(m_containers.begin(), m_containers.end(),
boost::bind(&ResourceContainer::PushJson,
boost::bind(&ContainerMap::value_type::second, _1),
boost::ref(containers)));
MojErr err = rep.put(_T("containers"), containers);
MojErrCheck(err);
MojObject entityMap(MojObject::TypeArray);
for (EntityContainerMap::const_iterator iter = m_entityContainers.begin();
iter != m_entityContainers.end(); ++iter) {
MojObject mapping(MojObject::TypeObject);
MojString containerName;
err = containerName.assign(iter->second->GetName().c_str());
MojErrCheck(err);
err = mapping.put(iter->first->GetName().c_str(), containerName);
MojErrCheck(err);
err = entityMap.push(mapping);
MojErrCheck(err);
}
err = rep.put(_T("entityMap"), entityMap);
MojErrCheck(err);
return MojErrNone;
}
示例8: CallbackInfo
MojErr MojService::CategoryHandler::addMethod(const MojChar* methodName, Callback callback, bool pub, const MojChar* schemaJson)
{
MojAssert(methodName && callback);
MojString str;
MojErr err = str.assign(methodName);
MojErrCheck(err);
MojRefCountedPtr<MojSchema> schema;
if (schemaJson) {
MojObject schemaObj;
err = schemaObj.fromJson(schemaJson);
MojErrCheck(err);
// add implicit $activity property
MojObject properties;
schemaObj.get(MojSchema::PropertiesKey, properties);
MojObject activityProp;
err = activityProp.putBool(MojSchema::OptionalKey, true);
MojErrCheck(err);
err = properties.put(_T("$activity"), activityProp);
MojErrCheck(err);
err = schemaObj.put(MojSchema::PropertiesKey, properties);
MojErrCheck(err);
schema.reset(new MojSchema);
MojAllocCheck(schema.get());
err = schema->fromObject(schemaObj);
MojErrCheck(err);
}
MojAssert(!m_callbackMap.contains(str));
err = m_callbackMap.put(str, CallbackInfo(callback, schema.get(), pub));
MojErrCheck(err);
return MojErrNone;
}
示例9: 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;
}
示例10: updateLocale
MojErr MojDb::updateLocale(const MojChar* locale, MojDbReqRef req)
{
MojAssert(locale);
MojLogTrace(s_log);
MojErr err = beginReq(req, true);
MojErrCheck(err);
MojString oldLocale;
err = getLocale(oldLocale, req);
MojErrCheck(err);
MojString newLocale;
err = newLocale.assign(locale);
MojErrCheck(err);
MojErr updateErr = err = updateLocaleImpl(oldLocale, newLocale, req);
MojErrCatchAll(err) {
err = req->abort();
MojErrCheck(err);
err = m_kindEngine.close();
MojErrCheck(err);
MojDbReq openReq;
err = beginReq(openReq, true);
MojErrCheck(err);
err = m_kindEngine.open(this, openReq);
MojErrCheck(err);
err = openReq.end();
MojErrCheck(err);
MojErrThrow(updateErr);
}
return MojErrNone;
}
示例11: MojAssertNoErr
TEST_F(QuotaTest, enforce)
{
MojObject obj;
// put quota
MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );
// make kind2 inherit from kind1
MojAssertNoErr( obj.fromJson(MojTestKind2Str3) );
MojExpectNoErr( db.putKind(obj) );
//// end of prerequisites form prev tests
// set quota size to current usage
MojInt64 quotaUsage1 = 0;
EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
MojAssertNoErr( obj.putString(_T("owner"), _T("com.foo.bar")) );
MojAssertNoErr( obj.putInt(_T("size"), quotaUsage1) );
MojExpectNoErr( db.putQuotas(&obj, &obj + 1) );
MojAssertNoErr( obj.fromJson(MojTestKind1Objects[3]) );
EXPECT_EQ( MojErrDbQuotaExceeded, db.put(obj) );
// Try to delete the kind
MojString kindStr;
MojAssertNoErr( kindStr.assign(_T("Test:1")) );
bool found = false;
EXPECT_EQ( MojErrDbKindHasSubKinds, db.delKind(kindStr, found) )
<< "The delete should be failure, because it contain sub kind \"Test2:1\"";
EXPECT_FALSE( found );
}
示例12: informQuotaSubscribers
MojErr MojDbQuotaEngine::informQuotaSubscribers(const MojString& kindId)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
MojErr err;
MojInt64 sizeOut;
MojInt64 usageOut;
MojDbKind* kind = NULL;
MojString owner;
err = owner.assign("");
MojErrCheck(err);
if(m_db->kindEngine()->isExist(kindId.data(), kind))
owner = kind->owner();
if((kind == NULL) || owner.empty())
return MojErrNone;
//ignore if quota not exist
QuotaMap::ConstIterator iter = m_quotas.find(owner.data());
if (iter == m_quotas.end())
return MojErrNone;
err = quotaUsage(owner.data(), sizeOut, usageOut);
MojErrCheck(err);
err = m_db->getQuotaAlert().notifySubscriber(owner.data(), usageOut, sizeOut);
MojErrCheck(err);
return MojErrNone;
}
示例13: testEnforce
MojErr MojDbQuotaTest::testEnforce(MojDb& db)
{
// set quota size to current usage
MojInt64 quotaUsage1 = 0;
MojErr err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojObject obj;
err = obj.putString(_T("owner"), _T("com.foo.bar"));
MojErrCheck(err);
err = obj.putInt(_T("size"), quotaUsage1);
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
err = put(db, MojTestKind1Objects[3]);
MojTestErrExpected(err, MojErrDbQuotaExceeded);
// Try to delete the kind
MojString kindStr;
err = kindStr.assign(_T("Test:1"));
MojTestErrCheck(err);
bool found = false;
err = db.delKind(kindStr, found);
//The delete should be failure, because it contain sub kind "Test2:1"
MojTestErrExpected(err,MojErrDbKindHasSubKinds);
MojTestAssert(!found);
return MojErrNone;
}
示例14: UpdateSendStatus
void SmtpSendMailCommand::UpdateSendStatus()
{
try {
MojObject sendStatus;
MojObject visible;
MojErr err;
bool update = false;
if (m_error.errorCode == 0) {
MojLogInfo(m_log, "updating send status to SENT successfully");
err = sendStatus.put(EmailSchema::SendStatus::SENT, true);
ErrorToException(err);
err = visible.put(EmailSchema::Flags::VISIBLE, false);
ErrorToException(err);
update = true;
} else if (m_error.errorOnEmail) {
MojLogInfo(m_log, "updating send status on email to indicate error");
MojString str;
str.assign(m_error.errorText.c_str());
err = sendStatus.put(EmailSchema::SendStatus::LAST_ERROR, str);
ErrorToException(err);
// FIXME: Should we store an actual error code?
err = sendStatus.put(EmailSchema::SendStatus::FATAL_ERROR, true);
ErrorToException(err);
update = true;
}
// account errors are not handled in sent status: message
// status will not be changed in those cases.
if (update) {
MojString idJson;
m_emailId.toJson(idJson);
MojLogInfo(m_log, "updating send status for email %s", idJson.data());
m_session.GetDatabaseInterface().UpdateSendStatus(m_updateSendStatusSlot, m_emailId, sendStatus, visible);
} else {
// Finish up now
Done();
}
} catch (std::exception & e) {
// Error updating status, just give up.
MojLogInfo(m_log, "Exception %s hit trying to update send status, bailing", e.what());
Done();
} catch (...) {
// Error updating status, just give up.
MojLogInfo(m_log, "Unknown exception hit trying to update send status, bailing");
Done();
}
}
示例15: putTest
MojErr MojObjectTest::putTest(MojObject& obj)
{
MojString str;
MojObject obj2;
MojObject array1;
MojObject str2;
MojObject bool2(false);
MojObject int2(-260000000000LL);
MojObject MojDecimal2(MojDecimal(2.34));
MojErr err = str.assign(_T("howdy"));
MojTestErrCheck(err);
str2 = str;
err = obj2.put(_T("nested"), str);
MojTestErrCheck(err);
err = obj.put(_T("object"), obj2);
MojTestErrCheck(err);
err = obj.put(_T("string"), str2);
MojTestErrCheck(err);
err = obj.put(_T("bool1"), true);
MojTestErrCheck(err);
err = obj.put(_T("bool2"), bool2);
MojTestErrCheck(err);
err = obj.put(_T("int1"), 50);
MojTestErrCheck(err);
err = obj.put(_T("int2"), int2);
MojTestErrCheck(err);
err = obj.put(_T("MojDecimal1"), MojDecimal(0.1));
MojTestErrCheck(err);
err = obj.put(_T("MojDecimal2"), MojDecimal2);
MojTestErrCheck(err);
err = obj.put(_T("null"), MojObject(MojObject::TypeNull));
MojTestErrCheck(err);
// array
err = array1.push(MojObject(MojObject::TypeObject));
MojTestErrCheck(err);
err = array1.push(MojObject(MojObject::TypeArray));
MojTestErrCheck(err);
err = array1.push(str2);
MojTestErrCheck(err);
err = array1.push(true);
MojTestErrCheck(err);
err = array1.setAt(3, false);
MojTestErrCheck(err);
err = array1.push(MojDecimal(3, 140000));
MojTestErrCheck(err);
err = array1.push(100);
MojTestErrCheck(err);
err = array1.push(MojObject(MojObject::TypeNull));
MojTestErrCheck(err);
err = array1.setAt(7, 4);
MojTestErrCheck(err);
err = obj.put(_T("array"), array1);
MojTestErrCheck(err);
return MojErrNone;
}