本文整理汇总了C++中MojObject::boolValue方法的典型用法代码示例。如果您正苦于以下问题:C++ MojObject::boolValue方法的具体用法?C++ MojObject::boolValue怎么用?C++ MojObject::boolValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojObject
的用法示例。
在下文中一共展示了MojObject::boolValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
boost::shared_ptr<Requirement> ConnectionManagerProxy::InstantiateRequirement(
boost::shared_ptr<Activity> activity, const std::string& name,
const MojObject& value)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
LOG_DEBUG("Instantiating [Requirement %s] for [Activity %llu]",
name.c_str(), activity->GetId());
if (name == "internet") {
if ((value.type() == MojObject::TypeBool) && value.boolValue()) {
boost::shared_ptr<ListedRequirement> req =
boost::make_shared<BasicCoreListedRequirement>(
activity, m_internetRequirementCore,
m_internetRequirementCore->IsMet());
m_internetRequirements.push_back(*req);
return req;
} else {
throw std::runtime_error("If an 'internet' requirement is "
"specified, the only legal value is 'true'");
}
} else if (name == "internetConfidence") {
return InstantiateConfidenceRequirement(activity,
m_internetConfidenceCores, m_internetConfidenceRequirements,
value);
} else if (name == "wan") {
if ((value.type() == MojObject::TypeBool) && value.boolValue()) {
boost::shared_ptr<ListedRequirement> req =
boost::make_shared<BasicCoreListedRequirement>(
activity, m_wanRequirementCore,
m_wanRequirementCore->IsMet());
m_wanRequirements.push_back(*req);
return req;
} else {
throw std::runtime_error("If an 'wan' requirement is "
"specified, the only legal value is 'true'");
}
} else if (name == "wanConfidence") {
return InstantiateConfidenceRequirement(activity, m_wanConfidenceCores,
m_wanConfidenceRequirements, value);
} else if (name == "wifi") {
if ((value.type() == MojObject::TypeBool) && value.boolValue()) {
boost::shared_ptr<ListedRequirement> req =
boost::make_shared<BasicCoreListedRequirement>(
activity, m_wifiRequirementCore,
m_wifiRequirementCore->IsMet());
m_wifiRequirements.push_back(*req);
return req;
} else {
throw std::runtime_error("If an 'wifi' requirement is "
"specified, the only legal value is 'true'");
}
} else if (name == "wifiConfidence") {
return InstantiateConfidenceRequirement(activity, m_wifiConfidenceCores,
m_wifiConfidenceRequirements, value);
} else {
LOG_ERROR(MSGID_REQUIREMENT_INSTANTIATE_FAIL , 3, PMLOGKS("Manager",GetName().c_str()),
PMLOGKFV("Activity","%llu",activity->GetId()), PMLOGKS("Requirement",name.c_str()), "");
throw std::runtime_error("Attempt to instantiate unknown requirement");
}
}
示例2: runtime_error
boost::shared_ptr<Requirement> PowerdProxy::InstantiateRequirement(
boost::shared_ptr<Activity> activity, const std::string& name,
const MojObject& value)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
LOG_DEBUG("Instantiating [Requirement %s] for [Activity %llu]",
name.c_str(), activity->GetId());
if (name == "charging") {
if ((value.type() != MojObject::TypeBool) || !value.boolValue()) {
throw std::runtime_error("A \"charging\" requirement must specify "
"'true' if present");
}
boost::shared_ptr<ListedRequirement> req =
boost::make_shared<BasicCoreListedRequirement>(
activity, m_chargingRequirementCore,
m_chargingRequirementCore->IsMet());
m_chargingRequirements.push_back(*req);
return req;
} else if (name == "docked") {
if ((value.type() != MojObject::TypeBool) || !value.boolValue()) {
throw std::runtime_error("A \"docked\" requirement must specify "
"'true' if present");
}
boost::shared_ptr<ListedRequirement> req =
boost::make_shared<BasicCoreListedRequirement>(
activity, m_dockedRequirementCore,
m_dockedRequirementCore->IsMet());
m_dockedRequirements.push_back(*req);
return req;
} else if (name == "battery") {
if ((value.type() != MojObject::TypeInt) ||
(value.intValue() < 0) || (value.intValue() > 100)) {
throw std::runtime_error("A \"battery\" requirement must specify "
"a value between 0 and 100");
}
MojInt64 percent = value.intValue();
boost::shared_ptr<BatteryRequirement> req =
boost::make_shared<BatteryRequirement>(activity, percent,
boost::dynamic_pointer_cast<PowerdProxy,
RequirementManager>(shared_from_this()),
(m_batteryPercent >= percent));
m_batteryRequirements.insert(*req);
return req;
} else {
LOG_ERROR(MSGID_UNKNOW_REQUIREMENT,3,
PMLOGKS("MANAGER",GetName().c_str()),
PMLOGKS("REQUIREMENT",name.c_str()),
PMLOGKFV("Activity","%llu",activity->GetId()),
"does not know how to instantiate ");
throw std::runtime_error("Attempt to instantiate unknown requirement");
}
}
示例3: runtime_error
boost::shared_ptr<Requirement> PowerdProxy::InstantiateRequirement(
boost::shared_ptr<Activity> activity, const std::string& name,
const MojObject& value)
{
MojLogTrace(s_log);
MojLogInfo(s_log, _T("Instantiating [Requirement %s] for [Activity %llu]"),
name.c_str(), activity->GetId());
if (name == "charging") {
if ((value.type() != MojObject::TypeBool) || !value.boolValue()) {
throw std::runtime_error("A \"charging\" requirement must specify "
"'true' if present");
}
boost::shared_ptr<ListedRequirement> req =
boost::make_shared<BasicCoreListedRequirement>(
activity, m_chargingRequirementCore,
m_chargingRequirementCore->IsMet());
m_chargingRequirements.push_back(*req);
return req;
} else if (name == "docked") {
if ((value.type() != MojObject::TypeBool) || !value.boolValue()) {
throw std::runtime_error("A \"docked\" requirement must specify "
"'true' if present");
}
boost::shared_ptr<ListedRequirement> req =
boost::make_shared<BasicCoreListedRequirement>(
activity, m_dockedRequirementCore,
m_dockedRequirementCore->IsMet());
m_dockedRequirements.push_back(*req);
return req;
} else if (name == "battery") {
if ((value.type() != MojObject::TypeInt) ||
(value.intValue() < 0) || (value.intValue() > 100)) {
throw std::runtime_error("A \"battery\" requirement must specify "
"a value between 0 and 100");
}
MojInt64 percent = value.intValue();
boost::shared_ptr<BatteryRequirement> req =
boost::make_shared<BatteryRequirement>(activity, percent,
boost::dynamic_pointer_cast<PowerdProxy,
RequirementManager>(shared_from_this()),
(m_batteryPercent >= percent));
m_batteryRequirements.insert(*req);
return req;
} else {
MojLogError(s_log, _T("[Manager %s] does not know how to instantiate "
"[Requirement %s] for [Activity %llu]"), GetName().c_str(),
name.c_str(), activity->GetId());
throw std::runtime_error("Attempt to instantiate unknown requirement");
}
}
示例4: 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;
}
示例5: runtime_error
boost::shared_ptr<Requirement> TelephonyProxy::InstantiateRequirement(
boost::shared_ptr<Activity> activity, const std::string& name,
const MojObject& value)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
LOG_DEBUG("Instantiating [Requirement %s] for [Activity %llu]",
name.c_str(), activity->GetId());
if (name == "telephony") {
if ((value.type() == MojObject::TypeBool) && value.boolValue()) {
boost::shared_ptr<ListedRequirement> req =
boost::make_shared<BasicCoreListedRequirement>(
activity, m_telephonyRequirementCore,
m_telephonyRequirementCore->IsMet());
m_telephonyRequirements.push_back(*req);
return req;
} else {
throw std::runtime_error("If a 'telephony' requirement is "
"specified, the only legal value is 'true'");
}
} else {
LOG_ERROR(MSGID_TIL_UNKNOWN_REQ, 3, PMLOGKS("MANAGER", GetName().c_str()),
PMLOGKS("REQ",name.c_str()),
PMLOGKFV("ACTIVITY_ID","%llu",activity->GetId()),
"does not know how to instantiate Requirement" );
throw std::runtime_error("Attempt to instantiate unknown requirement");
}
}
示例6: 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("[]"));
//.........这里部分代码省略.........