Ejemplo n.º 1
0
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);
	}
}
Ejemplo n.º 2
0
MojoWhereMatcher::MojoWhereMatcher(const MojObject& where)
	: m_where(where)
{
	ValidateClauses(m_where);
}
Ejemplo n.º 3
0
void MojoNewWhereMatcher::ValidateClause(const MojObject& clause) const
{
	LOG_AM_TRACE("Entering function %s", __FUNCTION__);
	LOG_AM_DEBUG("Validating where clause \"%s\"",
		MojoObjectJson(clause).c_str());

	bool found = false;

	if (clause.contains(_T("and"))) {
		found = true;

		MojObject andClauses;
		clause.get(_T("and"), andClauses);
		ValidateClauses(andClauses);
	}

	if (clause.contains(_T("or"))) {
		if (found) {
			throw std::runtime_error("Only one of \"and\", \"or\", or a valid "
				"clause including \"prop\", \"op\", and a \"val\"ue to "
				"compare against must be present in a clause");
		}

		found = true;

		MojObject orClauses;
		clause.get(_T("or"), orClauses);
		ValidateClauses(orClauses);
	}

	if (!clause.contains(_T("prop"))) {
		if (!found) {
			throw std::runtime_error("Each where clause must contain \"or\", "
				"\"and\", or a \"prop\"erty to compare against");
		} else {
			return;
		}
	} else if (found) {
		throw std::runtime_error("Only one of \"and\", \"or\", or a valid "
			"clause including \"prop\", \"op\", and a \"val\"ue to "
			"compare against must be present in a clause");
	}

	MojObject prop;
	clause.get(_T("prop"), prop);
	ValidateKey(prop);

	if (!clause.contains(_T("val"))) {
		throw std::runtime_error("Each where clause must contain a value to "
			"test against");
	}

	MojObject val;
	clause.get(_T("val"), val);

	if (!clause.contains(_T("op"))) {
		throw std::runtime_error("Each where clause must contain a test "
			"operation to perform");
	}

	MojObject op;
	clause.get(_T("op"), op);
	ValidateOp(op, val);
}