statementprocessor.cpp

来自「机器人开源项目orocos的源代码」· C++ 代码 · 共 361 行 · 第 1/2 页

CPP
361
字号
            DataSource<double>* dsd = DataSource<double>::narrow(ds);            if (dsd) {                Logger::log() << dsd->get() ;                return;            }            DataSource<char>* dsc = DataSource<char>::narrow(ds);            if (dsc) {                Logger::log() <<'\''<< dsc->get()<<'\'' ;                return;            }            DataSource<PropertyBag>* dspbag = DataSource<PropertyBag>::narrow(ds);            if (dspbag) {                PropertyBag bag( dspbag->get() );                if (!recurse) {                    int siz = bag.getProperties().size();                    Logger::log()  << siz <<" Properties";                } else {                    if ( ! bag.empty() ) {                        Logger::log()  <<Logger::nl;                        for( PropertyBag::iterator it= bag.getProperties().begin(); it!=bag.getProperties().end(); ++it) {                            Logger::log()  <<(*it)->getType()<<" "<< (*it)->getName();                            DataSourceBase::shared_ptr propds = (*it)->getDataSource();                            this->printResult( propds.get(), false );                            Logger::log()  <<" ("<<(*it)->getDescription()<<')' << Logger::nl;                        }                    } else {                        Logger::log()  <<"(empty PropertyBag)";                    }                }                return;            }            // Leave void  as last since any DS is convertible to void !            DataSource<void>* dsvd = DataSource<void>::narrow(ds);            if (dsvd) {                dsvd->get();                Logger::log() << "(void)" ;                return;            }            if (ds) {                ds->evaluate();                Logger::log() << "( result type '"+ds->getType()+"' not known to TaskBrowser )" ;            }	        }    };    StatementProcessor::StatementProcessor(TaskContext* tc)        : d ( new D() )    {        d->tc = tc;    }    StatementProcessor::~StatementProcessor() {        delete d;    }        void StatementProcessor::checkFinished() {        Logger::In in("StatementProcessor");        d->checkFinished();    }        DispatchInterface::shared_ptr StatementProcessor::getCommand(int cnr) {        Logger::In in("StatementProcessor");        return d->getCommand(cnr);    }        int StatementProcessor::execute(const std::string& comm)    {        Logger::In in("StatementProcessor");        d->checkFinished();        TaskContext* taskcontext = d->tc;        // Minor hack : also check if it was an attribute of current TC, for example,         // if both the object and attribute with that name exist. the if        // statement after this one would return and not give the expr parser        // time to evaluate 'comm'.         if ( taskcontext->attributes()->getValue( comm ) ) {                d->printResult( taskcontext->attributes()->getValue( comm )->getDataSource().get(), true );                return 0;        }                            Parser _parser;        std::pair< CommandInterface*, ConditionInterface*> comcon;        DispatchInterface* command;        ConditionInterface* condition;        Logger::log() <<Logger::Debug << "Trying ValueChange...";        try {            // Check if it was a method or datasource :            DataSourceBase::shared_ptr ds = _parser.parseValueChange( comm, taskcontext );            // methods and DS'es are processed immediately.            if ( ds.get() != 0 ) {                Logger::log() << "ok" << Logger::endl;                d->printResult( ds.get(), false );                return 0; // done here            } else                Logger::log() <<Logger::Debug << "no"<<Logger::endl;        } catch ( fatal_semantic_parse_exception& pe ) { // incorr args, ...            // way to fatal,  must be reported immediately            Logger::log() << Logger::Debug << "fatal_semantic_parse_exception: ";            Logger::log() << Logger::Error << pe.what() <<Logger::nl;            return -1;        } catch ( syntactic_parse_exception& pe ) { // wrong content after = sign etc..            // syntactic errors must be reported immediately            Logger::log() << Logger::Error << "syntactic_parse_exception: ";            Logger::log() << Logger::Error << pe.what() <<Logger::nl;            return -1;        } catch ( parse_exception_parser_fail &pe )            {                // ignore, try next parser                Logger::log() << Logger::Debug << "Ignoring ValueChange exception :"<<Logger::nl;                Logger::log() << Logger::Debug << pe.what() <<Logger::nl;        } catch ( parse_exception& pe ) {             // syntactic errors must be reported immediately            Logger::log() << Logger::Error << "parse_exception :";            Logger::log() << Logger::Error << pe.what() <<Logger::nl;            return -1;        }        Logger::log() << Logger::Debug << "Trying Expression..."<<Logger::nl;        try {            // Check if it was a method or datasource :            DataSourceBase::shared_ptr ds = _parser.parseExpression( comm, taskcontext );            // methods and DS'es are processed immediately.            if ( ds.get() != 0 ) {                d->printResult( ds.get(), true );                return 0; // done here            } else                Logger::log() << Logger::Error << "returned zero !"<<Logger::nl;        } catch ( syntactic_parse_exception& pe ) { // missing brace etc            // syntactic errors must be reported immediately            Logger::log() << Logger::Error << "syntactic_parse_exception :";            Logger::log() << Logger::Error << pe.what() <<Logger::nl;            return -1;        } catch ( fatal_semantic_parse_exception& pe ) { // incorr args, ...            // way to fatal,  must be reported immediately            Logger::log() << Logger::Error << "fatal_semantic_parse_exception :";            Logger::log() << Logger::Error << pe.what() <<Logger::nl;            return -1;        } catch ( parse_exception_parser_fail &pe ) {                // ignore, try next parser                Logger::log() << Logger::Debug << "Ignoring Expression exception :"<<Logger::nl;                Logger::log() << Logger::Debug << pe.what() <<Logger::nl;        } catch ( parse_exception& pe ) {             // ignore, try next parser            Logger::log() << Logger::Debug << "Ignoring Expression parse_exception :"<<Logger::nl;            Logger::log() << Logger::Debug << pe.what() <<Logger::nl;        }        Logger::log() << Logger::Debug << "Trying Command...";        try {            comcon = _parser.parseCommand( comm, taskcontext, true ); // create a dispatch command.            assert( dynamic_cast<DispatchInterface*>(comcon.first) );            command = dynamic_cast<DispatchInterface*>(comcon.first);            condition = comcon.second;        } catch ( parse_exception& pe ) {            Logger::log() << Logger::Debug << "CommandParser parse_exception :"<<Logger::nl;            Logger::log() << Logger::Error << pe.what() <<Logger::nl;            return -1;        } catch (...) {            Logger::log() << Logger::Error << "Illegal Input."<<Logger::nl;            return -1;        }                        if ( command == 0 ) { // this should not be reached            Logger::log() << Logger::Error << "Uncaught : Illegal command."<<Logger::nl;            return -1;        }        return d->add( command, condition, comm);    }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?