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


C++ Number::property方法代码示例

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


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

示例1: if

bool Number::operator==(Number arg) {
	Number::Type type = arg.property("Type").toInt() ? Number::intType : Number::doubleType;
	QVariant val = arg.property("Number");
	if (mType == Number::intType && type == Number::intType) {
		return mNumber.toInt() == val.toInt();
	} else if (mType == Number::intType && type == Number::doubleType) {
		return mNumber.toInt() == val.toDouble();
	} else if (mType == Number::doubleType && type == Number::intType) {
		return mNumber.toDouble() == val.toInt();
	} else {
		return mNumber.toDouble() == val.toDouble();
	}
}
开发者ID:nfrey,项目名称:qreal,代码行数:13,代码来源:number.cpp

示例2: applyFunction

Number BlockParser::applyFunction(const QString &variable, Number value)
{
	Number result;
	double argument = value.property("Number").toDouble();
	if (variable == "cos")
		result = Number(cos(argument), Number::doubleType);
	else if (variable == "sin")
		result = Number(sin(argument), Number::doubleType);
	else if (variable == "ln")
		result = Number(log(argument), Number::doubleType);
	else if (variable == "exp")
		result = Number(exp(argument), Number::doubleType);
	else if (variable == "sgn")
		result = Number((argument >= 0 ? 1 : -1), Number::intType);
	else if (variable == "acos")
		result = Number(acos(argument), Number::doubleType);
	else if (variable == "asin")
		result = Number(asin(argument), Number::doubleType);
	else if (variable == "atan")
		result = Number(atan(argument), Number::doubleType);
	else if (variable == "sqrt")
		result = Number(sqrt(argument), Number::doubleType);
	else if (variable == "abs")
		result = Number(fabs(argument), Number::doubleType);
	return result;
}
开发者ID:nfrey,项目名称:qreal,代码行数:26,代码来源:blockParser.cpp

示例3:

void Number::operator/=(Number div) {
	Number::Type type = div.property("Type").toInt() ? Number::intType : Number::doubleType;
	QVariant val = div.property("Number");
	if (mType == type) {
		switch (type) {
			case Number::intType:
				mNumber = mNumber.toInt() / val.toInt();
				break;
			case Number::doubleType:
				mNumber = mNumber.toDouble() / val.toDouble();
				break;
		}
	} else {
		mType = Number::doubleType;
		mNumber = mNumber.toDouble() / val.toDouble();
	}
}
开发者ID:nfrey,项目名称:qreal,代码行数:17,代码来源:number.cpp

示例4: parseCommand

void BlockParser::parseCommand(QString stream, int& pos) {
	int typesMismatchIndex = pos;
	QString variable = parseIdentifier(stream, pos);
	if (mReservedVariables.contains(variable)) {
		hasParseErrors = true;
				mErrorReporter->addError(QObject::tr("Using reserved variables %1").arg(variable), mCurrentId);
				return;
	}
	skip(stream, pos);
	if (hasParseErrors || checkForEndOfStream(stream, pos)) {
		return;
	}
	if (!mVariables.contains(variable)) {
		error(unknownIdentifier, QString::number(typesMismatchIndex + 1), "", variable);
	}

	if (isAssignment(stream.at(pos))) {
		pos++;
		Number n = parseExpression(stream, pos);
		if (!hasParseErrors) {
			Number::Type t1 = mVariables[variable].property("Type").toInt() ? Number::intType : Number::doubleType;
			Number::Type t2 = n.property("Type").toInt() ? Number::intType : Number::doubleType;
			if (t1==t2) {
				mVariables[variable] = n;
			} else {
				if (t1 == Number::intType) {
					mVariables[variable].setProperty("Number", n.property("Number").toInt());
					error(typesMismatch, QString::number(typesMismatchIndex + 1), "\'int\'", "\'double\'");
				} else {
					mVariables[variable].setProperty("Number", n.property("Number").toDouble());
				}
			}
		}
	} else {
		error(unexpectedSymbol, QString::number(pos+1), "=", QString(stream.at(pos)));
		return;
	}
	if (!hasParseErrors && checkForColon(stream, pos)) {
		pos++;
	}
}
开发者ID:nfrey,项目名称:qreal,代码行数:41,代码来源:blockParser.cpp

示例5: parseCommand

void ExpressionsParser::parseCommand(QString const &stream, int &pos)
{
	int typesMismatchIndex = pos;
	QString variable = parseIdentifier(stream, pos);
	skip(stream, pos);
	if (hasErrors() || isEndOfStream(stream, pos)) {
		return;
	}
	checkForVariable(variable, typesMismatchIndex);
	if (checkForUsingReservedVariables(variable))
		return;

	if (isAssignment(stream.at(pos))) {
		pos++;
		Number n = parseExpression(stream, pos);
		if (!hasErrors()) {
			bool const containsVariable = mVariables.keys().contains(variable);
			Number::Type const t1 = containsVariable
					? (mVariables[variable].property("Type").toInt() ? Number::intType : Number::doubleType)
					: Number::intType;
			Number::Type const t2 = n.property("Type").toInt() ? Number::intType : Number::doubleType;
			if (!containsVariable || t1 == t2) {
				mVariables[variable] = n;
			} else {
				if (t1 == Number::intType) {
					mVariables[variable].setProperty("Number", n.property("Number").toInt());
					error(typesMismatch, QString::number(typesMismatchIndex + 1), "\'int\'", "\'double\'");
				} else {
					mVariables[variable].setProperty("Number", n.property("Number").toDouble());
				}
			}
		}
	} else {
		error(unexpectedSymbol, QString::number(pos+1), "=", QString(stream.at(pos)));
		return;
	}
	if (!hasErrors() && checkForColon(stream, pos)) {
		pos++;
	}
}
开发者ID:Esenin,项目名称:qreal,代码行数:40,代码来源:expressionsParser.cpp

示例6:

TEST_F(BlockParserTest, parseProcessTest) {
	QString const stream = "var int a, b; double c; a=5; b=3; c=a+b;";
	int pos = 0;

	mParser->parseProcess(stream, pos, Id::rootId());

	QMap<QString, Number>* variables = mParser->getVariables();
	QStringList variableNames = variables->keys();

	ASSERT_EQ(variableNames.size(), 3);
	ASSERT_TRUE(variableNames.contains("a"));
	ASSERT_TRUE(variableNames.contains("b"));
	ASSERT_TRUE(variableNames.contains("c"));

	Number a = variables->value("a");
	Number b = variables->value("b");
	Number c = variables->value("c");

	EXPECT_EQ(a.property("Number").toInt(), 5);
	EXPECT_EQ(b.property("Number").toInt(), 3);
	EXPECT_EQ(c.property("Number").toDouble(), 8);
}
开发者ID:DenisTi,项目名称:qreal,代码行数:22,代码来源:blockParserTest.cpp

示例7: parsePropertyChange

// TODO: refactor this!
void RuleParser::parsePropertyChange(QString const &stream, int &pos,
		QHash<Id, Id> const &mMatch)
{
	QString const name = parseElemName(stream, pos);
	if (hasErrors()) {
		return;
	}

	QString const prop = parseElemProperty(stream, pos);
	if (hasErrors()) {
		return;
	}

	pos++;
	skip(stream, pos);

	if (!checkForEqual(stream, pos)) {
		return;
	}

	pos++;
	skip(stream, pos);

	if (stream.mid(pos, 5) == "cond(") {
		pos += 5;
		skip(stream, pos);

		QString const condName = parseElemName(stream, pos);
		if (hasErrors()) {
			return;
		}

		QString const condProperty = parseElemProperty(stream, pos);
		if (hasErrors()) {
			return;
		}

		checkForClosingBracketAndColon(stream, pos);

		Id const condId = elementByName(condName, mMatch);
		if (condId == Id::rootId()) {
			error(unknownElementName);
			return;
		}

		int position = 0;

		bool value = parseCondition(property(condId, condProperty).toString(),
				position, condId);

		Id const id = elementByName(name, mMatch);
		if (id == Id::rootId()) {
			error(unknownElementName);
			return;
		}

		setProperty(id, prop, QString(value ? "true" : "false"));
		mCurrentId = mRuleId;

		return;
	}

	if (stream.at(pos).toLatin1() == '"') {
		pos++;
		QString const value = stream.mid(pos, stream.indexOf("\"", pos) - pos);
		pos += value.length();

		if (stream.at(pos).toLatin1() != '"') {
			error(unexpectedSymbol, QString::number(pos)
					, "\"", QString(stream.at(pos).toLatin1()));
			return;
		}

		Id const id = elementByName(name, mMatch);
		if (id == Id::rootId()) {
			error(unknownElementName);
			return;
		}

		setProperty(id, prop, value);

		pos++;
		skip(stream, pos);

		if (!checkForColon(stream, pos)) {
			return;
		}
		pos++;

		return;
	}

	if (checkForLogicalConst(stream, pos)) {
		int len = 0;
		QString value = "";

		if (stream.mid(pos, 4) == "true") {
			len = 4;
			value = "true";
//.........这里部分代码省略.........
开发者ID:Esenin,项目名称:qreal,代码行数:101,代码来源:ruleParser.cpp


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