本文整理汇总了C++中ExprResult::isNumeric方法的典型用法代码示例。如果您正苦于以下问题:C++ ExprResult::isNumeric方法的具体用法?C++ ExprResult::isNumeric怎么用?C++ ExprResult::isNumeric使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExprResult
的用法示例。
在下文中一共展示了ExprResult::isNumeric方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eval
ExprResult CondNode::eval()
{
ExprResult result;
ExprResult left = mLeft->eval();
ExprResult right = mRight->eval();
// @TODO Realizar cast automático para string nos casos necessários
if (left.isNumeric() && right.isNumeric())
{
result.setType("bool");
if (left.isInteger())
{
long leftVal = left.getIntegerValue();
if (right.isInteger())
{
long rightVal = right.getIntegerValue();
result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
}
else
{
double rightVal = right.getFloatValue();
result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
}
}
else
{
double leftVal = left.getFloatValue();
if (right.isInteger())
{
long rightVal = right.getIntegerValue();
result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
}
else
{
double rightVal = right.getFloatValue();
result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
}
}
}
else if (left.getType() == "string" && right.getType() == "string")
{
result.setType("bool");
std::string leftVal = ((StringVal*)left.getValue())->getValue();
std::string rightVal = ((StringVal*)right.getValue())->getValue();
result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
}
if (result.getType() == "void")
{
Log::fatal("Tipos incompatíveis para comparação");
}
return result;
}
示例2: eval
/* @TODO Implementar melhor, copy paste de SumNode com poucas diferenças */
ExprResult ModNode::eval()
{
ExprResult result;
ExprResult left = mLeft->eval();
ExprResult right = mRight->eval();
if (left.isNumeric() && right.isNumeric())
{
if (left.isInteger())
{
long leftValue = left.getIntegerValue();
long resultValue;
if (right.isInteger())
{
long rightValue = right.getIntegerValue();
resultValue = leftValue % rightValue;
result.setValue("long", resultValue);
}
else if (right.isFloat())
{
long rightValue = (long)right.getFloatValue();
resultValue = leftValue % rightValue;
result.setValue("long", resultValue);
}
}
else if (left.isFloat())
{
long leftValue = (long)left.getFloatValue();
long resultValue;
if (right.isInteger())
{
long rightValue = right.getIntegerValue();
resultValue = leftValue % rightValue;
}
else if (right.isFloat())
{
long rightValue = (long)right.getFloatValue();
resultValue = leftValue % rightValue;
}
result.setValue("long", resultValue);
}
}
// Nenhuma operação pode ser realizada
if (result.getType() == "void")
{
Log::fatal("Uso de módulo com valores não numéricos");
}
return result;
}
示例3: eval
ExprResult SumNode::eval()
{
ExprResult result;
ExprResult left = mLeft->eval();
ExprResult right = mRight->eval();
if (left.isNumeric() && right.isNumeric())
{
if (left.isInteger())
{
long leftValue = left.getIntegerValue();
if (right.isInteger())
{
long rightValue = right.getIntegerValue();
long resultValue = leftValue + rightValue;
result.setValue(result.getLargerType(left, right), resultValue);
}
else if (right.isFloat())
{
double rightValue = right.getFloatValue();
double resultValue = leftValue + rightValue;
result.setValue(result.getLargerType(left, right), resultValue);
}
}
else if (left.isFloat())
{
double leftValue = left.getFloatValue();
double resultValue = leftValue;
if (right.isInteger())
{
long rightValue = right.getIntegerValue();
resultValue += rightValue;
}
else if (right.isFloat())
{
double rightValue = right.getFloatValue();
resultValue += rightValue;
}
result.setValue(result.getLargerType(left, right), resultValue);
}
}
// Nenhuma operação pode ser realizada
if (result.getType() == "void")
{
Log::fatal("Uso de soma com valores não numéricos");
}
return result;
}