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


C++ Expression::addError方法代码示例

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


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

示例1: operator

//TODO complex values as matrix entries too
//TODO support endomorphisms over Rn too
Expression EigenvectorsCommand::operator()(const QList< Analitza::Expression >& args)
{
    Expression ret;
    
    QStringList errors;
    const Eigen::MatrixXcd eigeninfo = executeEigenSolver(args, true, errors);
    
    if (!errors.isEmpty()) {
        ret.addError(errors.first());
        
        return ret;
    }
    const int neigenvectors = eigeninfo.rows();
    
    QScopedPointer<Analitza::List> list(new Analitza::List);
    
    for (int j = 0; j < neigenvectors; ++j) {
        const Eigen::VectorXcd col = eigeninfo.col(j);
        QScopedPointer<Analitza::Vector> eigenvector(new Analitza::Vector(neigenvectors));
        
        for (int i = 0; i < neigenvectors; ++i) {
            const std::complex<double> eigenvalue = col(i);
            const double realpart = eigenvalue.real();
            const double imagpart = eigenvalue.imag();
            
            if (std::isnan(realpart) || std::isnan(imagpart)) {
                ret.addError(QCoreApplication::tr("Returned eigenvalue is NaN", "NaN means Not a Number, is an invalid float number"));
                return ret;
            } else if (std::isinf(realpart) || std::isinf(imagpart)) {
                ret.addError(QCoreApplication::tr("Returned eigenvalue is too big"));
                return ret;
            } else {
                bool isonlyreal = true;
                
                if (std::isnormal(imagpart)) {
                    isonlyreal = false;
                }
                
                Analitza::Cn * eigenvalueobj = 0;
                
                if (isonlyreal) {
                    eigenvalueobj = new Analitza::Cn(realpart);
                } else {
                    eigenvalueobj = new Analitza::Cn(realpart, imagpart);
                }
                
                eigenvector->appendBranch(eigenvalueobj);
            }
        }
        
        list->appendBranch(eigenvector.take());
    }
    
    ret.setTree(list.take());
    
    return ret;
}
开发者ID:KDE,项目名称:analitza,代码行数:59,代码来源:eigencommands.cpp

示例2: operator

Expression VectorCommand::operator()(const QList< Analitza::Expression >& args)
{
    Expression ret;

    const int nargs = args.size();

    switch(nargs) {
    case 0: {
        ret.addError(QCoreApplication::tr("Invalid parameter count for '%1'").arg(VectorCommand::id));
    }
    break;
    case 1: {
        const Analitza::Object *arg = args.first().tree();

        //TODO vector(5) := vector{0,0,0,0,0}
        if (arg->type() == Analitza::Object::list) {
            const Analitza::List *list = static_cast<const Analitza::List*>(arg);
            const int n = list->size();

            Analitza::Vector *vector = new Analitza::Vector(n);

            for (int i = 0; i < n; ++i)
                vector->appendBranch(list->at(i)->copy());

            ret.setTree(vector);
        } else {
            ret.addError(QCoreApplication::tr("Invalid parameter type for '%1', was expected a list").arg(VectorCommand::id));
        }
    }
    break;
    case 2: {
        const Analitza::Object *arg = args.first().tree();

        if (arg->type() == Analitza::Object::value) {
            const Analitza::Cn *lengthobj = static_cast<const Analitza::Cn*>(args.first().tree());

            if (lengthobj->isInteger() && lengthobj->value() > 0) {
                ret.setTree(new Analitza::Vector(lengthobj->intValue(), static_cast<const Analitza::Cn*>(args.last().tree())));
            }
            else {
                ret.addError(QCoreApplication::tr("Vector size must be some integer value greater to zero"));
            }
        } else {
            ret.addError(QCoreApplication::tr("Vector size must be some integer value greater to zero"));
        }
    }
    break;
    default:
        ret.addError(QCoreApplication::tr("Invalid parameter count for '%1'").arg(VectorCommand::id));
        break;
    }

    return ret;
}
开发者ID:KDE,项目名称:analitza,代码行数:54,代码来源:vectorcommands.cpp

示例3: operator

Expression RangeCommand::operator()(const QList< Analitza::Expression >& args)
{
    Expression ret;
    
    const int nargs = args.size();
    
    double a = 1;
    double b = 0;
    double h = 1;
    
    switch(nargs) {
        case 0: {
            ret.addError(QCoreApplication::tr("Invalid parameter count for '%1'").arg(RangeCommand::id));
            
            return ret;
        }    break;
        case 1: {
            b = static_cast<const Analitza::Cn*>(args.first().tree())->value();
        }    break;
        case 2: {
            a = static_cast<const Analitza::Cn*>(args.first().tree())->value();
            b = static_cast<const Analitza::Cn*>(args.last().tree())->value();
        }    break;
        case 3: {
            a = static_cast<const Analitza::Cn*>(args.at(0).tree())->value();
            b = static_cast<const Analitza::Cn*>(args.at(1).tree())->value();
            h = static_cast<const Analitza::Cn*>(args.at(2).tree())->value();
        }    break;
        default:
            ret.addError(QCoreApplication::tr("Invalid parameter count for '%1'").arg(RangeCommand::id));
            
            return ret;
            break;
    }
    
    Analitza::List *seq = new Analitza::List;
        
    for (double x = a; x <= b; x += h)
        seq->appendBranch(new Analitza::Cn(x));
    
    ret.setTree(seq);
    
    return ret;
}
开发者ID:KDE,项目名称:analitza,代码行数:44,代码来源:listcommands.cpp


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