当前位置: 首页>>代码示例>>C++>>正文


C++ MojObject::type方法代码示例

本文整理汇总了C++中MojObject::type方法的典型用法代码示例。如果您正苦于以下问题:C++ MojObject::type方法的具体用法?C++ MojObject::type怎么用?C++ MojObject::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MojObject的用法示例。


在下文中一共展示了MojObject::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CheckProperty

MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty(
	const MojObject& keyArray, MojObject::ConstArrayIterator keyIter,
	const MojObject& response, const MojObject& op, const MojObject& val,
	MatchMode mode) const
{
	MojObject onion = response;
	for (; keyIter != keyArray.arrayEnd(); ++keyIter) {
		if (onion.type() == MojObject::TypeArray) {
			return CheckProperty(keyArray, keyIter, onion, onion.arrayBegin(),
				op, val, mode);
		} else if (onion.type() == MojObject::TypeObject) {
			MojString keyStr;
			MojErr err = (*keyIter).stringValue(keyStr);
			if (err) {
				throw std::runtime_error("Failed to convert property lookup "
					"key to string");
			}

			MojObject next;
			if (!onion.get(keyStr.data(), next)) {
				return NoProperty;
			}

			onion = next;
		} else {
			return NoProperty;
		}
	}

	return CheckMatch(onion, op, val);

}
开发者ID:ctbrowser,项目名称:activitymanager,代码行数:32,代码来源:MojoWhereMatcher.cpp

示例2: 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");
	}
}
开发者ID:azimut2000,项目名称:activitymanager,代码行数:60,代码来源:ConnectionManagerProxy.cpp

示例3: 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");
	}
}
开发者ID:azimut2000,项目名称:activitymanager,代码行数:59,代码来源:PowerdProxy.cpp

示例4: 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");
	}
}
开发者ID:edwin12345pro,项目名称:activitymanager,代码行数:57,代码来源:PowerdProxy.cpp

示例5: CheckClause

MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckClause(
	const MojObject& clause, const MojObject& response, MatchMode mode) const
{
	LOG_AM_TRACE("Entering function %s", __FUNCTION__);

	if (clause.type() == MojObject::TypeArray) {
		return CheckClauses(clause, response, mode);
	} else if (clause.type() != MojObject::TypeObject) {
		throw std::runtime_error("Clauses must be either an object or array "
			"of objects");
	}

	LOG_AM_DEBUG("Checking clause '%s' against response '%s' (%s)",
		MojoObjectJson(clause).c_str(), MojoObjectJson(response).c_str(),
		(mode == AndMode) ? "and" : "or");

	if (clause.contains(_T("and"))) {
		MojObject andClause;
		clause.get(_T("and"), andClause);

		return CheckClause(andClause, response, AndMode);
	} else if (clause.contains(_T("or"))) {
		MojObject orClause;
		clause.get(_T("or"), orClause);

		return CheckClause(orClause, response, OrMode);
	}

	MojObject prop;
	bool found = clause.get(_T("prop"), prop);
	if (!found) {
		throw std::runtime_error("Clauses must contain \"and\", \"or\", "
			"or a comparison to make");
	}

	MojObject op;
	found = clause.get(_T("op"), op);
	if (!found) {
		throw std::runtime_error("Clauses must specify a comparison operation "
			"to perform");
	}

	MojObject val;
	found = clause.get(_T("val"), val);
	if (!found) {
		throw std::runtime_error("Clauses must specify a value to compare "
			"against");
	}

	MatchResult result = CheckProperty(prop, response, op, val, mode);

	LOG_AM_DEBUG("Where Trigger: Clause %s %s",
		MojoObjectJson(clause).c_str(), (result == Matched) ? "matched" :
	    "did not match");

	return result;
}
开发者ID:ctbrowser,项目名称:activitymanager,代码行数:57,代码来源:MojoWhereMatcher.cpp

示例6: GetObjectValue

bool MojoWhereMatcher::GetObjectValue(const MojObject& key,
	const MojObject& response, MojObject& value) const
{
	if (key.type() == MojObject::TypeString) {
		MojString keyStr;
		MojErr err = key.stringValue(keyStr);
		if (err) {
			throw std::runtime_error("Error attempting to retrieve key name "
				"getting object value");
		}

		if (response.contains(keyStr)) {
			return response.get(keyStr, value);
		} else {
			return false;
		}
	} else if (key.type() == MojObject::TypeArray) {
		MojObject cur = response;
		for (MojObject::ConstArrayIterator iter = key.arrayBegin();
			iter != key.arrayEnd(); ++iter) {
			const MojObject& keyObj = *iter; 

			if (keyObj.type() != MojObject::TypeString) {
				throw std::runtime_error("Non-string found in property "
					"specifiction array");
			}

			MojString keyStr;
			MojErr err = keyObj.stringValue(keyStr);
			if (err) {
				throw std::runtime_error("Failed to access lookup key");
			}

			if (cur.contains(keyStr)) {
				MojObject tmp;
				if (!cur.get(keyStr, tmp)) {
					return false;
				} else {
					cur = tmp;
				}
			} else {
				return false;
			}
		}

		value = cur;
		return true;
	} else {
		throw std::runtime_error("Property specification must be the "
			"property name or array of property names");
	}
}
开发者ID:edwin12345pro,项目名称:activitymanager,代码行数:52,代码来源:MojoMatcher.cpp

示例7: 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");
	}
}
开发者ID:azimut2000,项目名称:activitymanager,代码行数:28,代码来源:TelephonyProxy.cpp

示例8: ValidateOp

void MojoNewWhereMatcher::ValidateOp(const MojObject& op,
	const MojObject& val) const
{
	if (op.type() != MojObject::TypeString) {
		throw std::runtime_error("Operation must be specified as a string "
			"property");
	}

	MojString opStr;
	MojErr err = op.stringValue(opStr);
	if (err) {
		throw std::runtime_error("Failed to convert operation to "
			"string value");
	}

	if ((opStr != "<") && (opStr != "<=") && (opStr != "=") &&
		(opStr != ">=") && (opStr != ">") && (opStr != "!=") &&
		(opStr != "where")) {
		throw std::runtime_error("Operation must be one of '<', '<=', "
			"'=', '>=', '>', '!=', and 'where'");
	}

	if (opStr == "where") {
		ValidateClauses(val);
	}
}
开发者ID:ctbrowser,项目名称:activitymanager,代码行数:26,代码来源:MojoWhereMatcher.cpp

示例9: ValidateKey

void MojoWhereMatcher::ValidateKey(const MojObject& key) const
{
	if (key.type() == MojObject::TypeArray) {
		for (MojObject::ConstArrayIterator iter = key.arrayBegin();
			iter != key.arrayEnd(); ++iter) {
			const MojObject& keyObj = *iter;
			if (keyObj.type() != MojObject::TypeString) {
				throw std::runtime_error("Something other than a string "
					"found in array of property names");
			}
		}
	} else if (key.type() != MojObject::TypeString) {
		throw std::runtime_error("Property keys must be specified as "
			"a property name, or array of property names");
	}
}
开发者ID:edwin12345pro,项目名称:activitymanager,代码行数:16,代码来源:MojoMatcher.cpp

示例10: addClause

MojErr MojDbQuery::addClause(WhereMap& map, const MojChar* propName, CompOp op, const MojObject& val, MojDbCollationStrength coll)
{
	MojAssert(propName);

	// only allow valid ops
    if (!(op >= OpEq && op <= OpSubString))
		MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: invalid query op"));
    // only allow array values for = or % or %% ops
    if (val.type() == MojObject::TypeArray && op != OpEq && op != OpPrefix && op != OpSubString)
		MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: query contains array value for non-eq op"));

	// check to see if the prop is referenced in a prior clause
	WhereMap::Iterator iter;
	MojErr err = map.find(propName, iter);
	MojErrCheck(err);
	if (iter == map.end()) {
		// create new clause
		err = createClause(map, propName, op, val, coll);
		MojErrCheck(err);
	} else {
		// add clause to previously referenced prop.
		err = updateClause(iter.value(), op, val, coll);
		MojErrCheck(err);
	}
	return MojErrNone;
}
开发者ID:feniksa,项目名称:indb8,代码行数:26,代码来源:MojDbQuery.cpp

示例11: handleVal

MojErr MojDbPropExtractor::handleVal(const MojObject& val, KeySet& valsOut, MojSize idx) const
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

	MojAssert(idx < m_prop.size());

	MojErr err = MojErrNone;
	if (idx == m_prop.size() - 1) {
		// if we're at the end of the prop path, use this object as the value
		if (m_tokenizer.get() && val.type() == MojObject::TypeString) {
			MojString text;
			err = val.stringValue(text);
			MojErrCheck(err);
			if (m_tokenizer.get()) {
				err = m_tokenizer->tokenize(text, m_collator.get(), valsOut);
				MojErrCheck(err);
			}
		} else {
			MojDbKey key;
			err = key.assign(val, m_collator.get());
			MojErrCheck(err);
			err = valsOut.put(key);
			MojErrCheck(err);
		}
	} else {
		// otherwise, keep recursing
		err = valsImpl(val, valsOut, idx + 1);
		MojErrCheck(err);
	}
	return MojErrNone;
}
开发者ID:ctbrowser,项目名称:db8,代码行数:31,代码来源:MojDbExtractor.cpp

示例12: fromObjectImpl

MojErr MojDbPropExtractor::fromObjectImpl(const MojObject& obj, const MojDbPropExtractor& defaultConfig, const MojChar* locale)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

	// super
	MojErr err = MojDbExtractor::fromObject(obj, locale);
	MojErrCheck(err);

	// default value
	m_default = defaultConfig.m_default;
	MojObject defaultVal;
	if (obj.get(DefaultKey, defaultVal)) {
		MojObject::Type type = defaultVal.type();
		MojDbKey key;
		if (type == MojObject::TypeArray) {
			// if the value is an array, act on its elements rather than the array object itself
			MojObject::ConstArrayIterator end = defaultVal.arrayEnd();
			for (MojObject::ConstArrayIterator j = defaultVal.arrayBegin(); j != end; ++j) {
				err = key.assign(*j);
				MojErrCheck(err);
				err = m_default.put(key);
				MojErrCheck(err);
			}
		} else {
			err = key.assign(defaultVal);
			MojErrCheck(err);
			err = m_default.put(key);
			MojErrCheck(err);
		}
	}

	// tokenizer
	m_tokenizer = defaultConfig.m_tokenizer;
	MojString tokenize;
	bool found = false;
	err = obj.get(TokenizeKey, tokenize, found);
	MojErrCheck(err);
	if (found) {
		if (tokenize == AllKey || tokenize == DefaultKey) {
			m_tokenizer.reset(new MojDbTextTokenizer);
			MojAllocCheck(m_tokenizer.get());
			err = m_tokenizer->init(locale);
			MojErrCheck(err);
		} else {
			MojErrThrow(MojErrDbInvalidTokenization);
		}
	}

	// collator
	if (m_collation == MojDbCollationInvalid)
		m_collation = defaultConfig.m_collation;
	err = updateLocale(locale);
	MojErrCheck(err);

	// set prop
	err = prop(m_name);
	MojErrCheck(err);

	return MojErrNone;
}
开发者ID:ctbrowser,项目名称:db8,代码行数:60,代码来源:MojDbExtractor.cpp

示例13: 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;
}
开发者ID:webOS-ports,项目名称:db8,代码行数:33,代码来源:MojObjectTest.cpp

示例14: if

MojErr BusClient::BusMethods::ScanRequest(MojServiceMessage* msg, MojObject& payload, ConfigurationMode confmode)
{
	try {
		MojErr err;
		if (payload.type() != MojObject::TypeArray) {
			MojErrThrowMsg(MojErrInternal, "invalid message format");
		}

		m_client.m_msg.reset(msg);

		for (MojObject::ConstArrayIterator it = payload.arrayBegin(); it != payload.arrayEnd(); it++) {
			const MojObject& request = *it;
			MojString locationStr;
			MojString typeStr;
			MojString app;
			BusClient::PackageType type;
			BusClient::PackageLocation location;

			err = request.getRequired("id", app);
			MojErrCheck(err);

			err = request.getRequired("type", typeStr);
			MojErrCheck(err);

			err = request.getRequired("location", locationStr);
			MojErrCheck(err);

			if (typeStr == "app") {
				type = BusClient::Application;
			} else if (typeStr == "service") {
				type = BusClient::Service;
			} else {
				MojErrThrow(MojErrInvalidMsg);
			}

			if (locationStr == "system") {
				location = BusClient::System;
			} else if (locationStr == "third party") {
				location = BusClient::ThirdParty;
			} else {
				MojErrThrow(MojErrInvalidMsg);
			}

			m_client.Scan(confmode, app, type, location);
		}

		m_client.RunNextConfigurator();
	} catch (const std::exception& e) {
		MojErrThrowMsg(MojErrInternal, "%s", e.what());
	} catch (...) {
		MojErrThrowMsg(MojErrInternal, "uncaught exception");
	}

	return MojErrNone;
}
开发者ID:feniksa,项目名称:configurator,代码行数:55,代码来源:BusClient.cpp

示例15: CheckClauses

bool MojoWhereMatcher::CheckClauses(const MojObject& clauses,
	const MojObject& response) const
{
	MojLogTrace(s_log);

	if (clauses.type() == MojObject::TypeObject) {
		return CheckClause(clauses, response);
	} else if (clauses.type() == MojObject::TypeArray) {
		for (MojObject::ConstArrayIterator iter = clauses.arrayBegin();
			iter != clauses.arrayEnd(); ++iter) {
			if (!CheckClause(*iter, response)) {
				return false;
			}
		}
	} else {
		throw std::runtime_error("Clauses must consist of either a single "
			"where clause or array of where clauses");
	}

	return true;
}
开发者ID:edwin12345pro,项目名称:activitymanager,代码行数:21,代码来源:MojoMatcher.cpp


注:本文中的MojObject::type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。