/** Creates a pointer to a command of the given name. If the name is not registered in the list so far, it throws an UnknownCommandException. \throws UnknownCommandException */ std::shared_ptr<Command> CreateCommand(const std::string& name) { Command* pointer = nullptr; auto it = factory.find(name); if (it != factory.end()) pointer = it->second(); if (pointer != nullptr) { return std::shared_ptr<Command>(pointer); } else throw UnknownCommandException(name); }
void Console::execute( const std::string& line ) { std::clog << ">"; pushLine( line ); std::string::size_type pos = line.find( ' ' ); std::string cmd = std::string( line.begin(), pos != std::string::npos ? line.begin() + pos : line.end() ); auto find = std::find_if( m_cmds.begin(), m_cmds.end(), std::bind( &con::Command::operator==, std::placeholders::_1, cmd ) ); try { if ( find == m_cmds.end() ) throw UnknownCommandException(); (**find)( *this, parseArguments( pos != std::string::npos ? std::string( line.begin() + pos + 1, line.end() ) : "" ) ); } catch ( std::exception& err ) { *this << con::setcerr << err.what() << con::endl; } }