[brlcad-commits] SF.net SVN: brlcad:[35331]
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <ra...@us...> - 2009-07-28 02:33:00
|
Revision: 35331 http://brlcad.svn.sourceforge.net/brlcad/?rev=35331&view=rev Author: ralith Date: 2009-07-28 02:32:50 +0000 (Tue, 28 Jul 2009) Log Message: ----------- Switched to QString(List)s, leading to significant simplification. Modified Paths: -------------- rt^3/trunk/src/g3d/Command.cxx rt^3/trunk/src/g3d/Command.h rt^3/trunk/src/g3d/CommandInterpreter.cxx rt^3/trunk/src/g3d/CommandInterpreter.h rt^3/trunk/src/g3d/Commands.h rt^3/trunk/src/g3d/GedCommands.h Modified: rt^3/trunk/src/g3d/Command.cxx =================================================================== --- rt^3/trunk/src/g3d/Command.cxx 2009-07-28 01:29:55 UTC (rev 35330) +++ rt^3/trunk/src/g3d/Command.cxx 2009-07-28 02:32:50 UTC (rev 35331) @@ -26,7 +26,7 @@ * Implementation of Command base class. */ -#include <vector> +#include <QStringList> #include "Command.h" @@ -64,7 +64,7 @@ return _extraDescription; } -const std::vector<QString>& Command::getArgumentNames() const +const QStringList Command::getArgumentNames() const { return _argNames; } Modified: rt^3/trunk/src/g3d/Command.h =================================================================== --- rt^3/trunk/src/g3d/Command.h 2009-07-28 01:29:55 UTC (rev 35330) +++ rt^3/trunk/src/g3d/Command.h 2009-07-28 02:32:50 UTC (rev 35331) @@ -30,8 +30,7 @@ #define __G3D_COMMAND_H__ -#include <QString> -#include <vector> +#include <QStringList> /** @@ -81,7 +80,7 @@ virtual ~Command() { } /** Execute the command (to be implemented by the real commands) */ - virtual QString execute(std::vector<QString>& args) = 0; + virtual QString execute(QStringList& args) = 0; /** The name of the command */ const QString& getName() const; @@ -90,7 +89,7 @@ /** Get a extra description of the command */ const QString& getExtraDescription() const; /** Get the name of the arguments */ - const std::vector<QString>& getArgumentNames() const; + const QStringList getArgumentNames() const; /** Get the syntax */ QString getSyntax() const; @@ -102,7 +101,7 @@ /** Extra description */ QString _extraDescription; /** The names of the arguments */ - std::vector<QString> _argNames; + QStringList _argNames; }; #endif Modified: rt^3/trunk/src/g3d/CommandInterpreter.cxx =================================================================== --- rt^3/trunk/src/g3d/CommandInterpreter.cxx 2009-07-28 01:29:55 UTC (rev 35330) +++ rt^3/trunk/src/g3d/CommandInterpreter.cxx 2009-07-28 02:32:50 UTC (rev 35331) @@ -28,8 +28,9 @@ */ #include <vector> -#include <string> +#include <QStringList> + #include "CommandInterpreter.h" #include "Logger.h" @@ -76,8 +77,7 @@ ++it) { const QString& commandName = it->first; // push back all commands which match the input - int comparison = commandName.toStdString().compare(0, input.length(), input.toStdString()); - if (comparison == 0) { + if (commandName.startsWith(input)) { // Logger::logDEBUG(" - matches '%s'", input.c_str()); candidates.push_back(commandName); } else { @@ -134,21 +134,16 @@ void CommandInterpreter::execute(QString commandLine) { // try to parse the command line into arguments - std::vector<QString> args; - parseCommandLine(commandLine, args); + QStringList args = parseCommandLine(commandLine); QString output; - if (args.size() == 0) { - output.append("Error: Cannot parse command line (too long?)"); - return; - } // extract the command name QString commandName = args[0]; - args.erase(args.begin()); + args.removeAt(0); if (commandName == "help") { // help meta command - if (args.size() == 0) { + if (args.empty()) { // general help emit commandDone(help()); } else { @@ -232,47 +227,9 @@ } } -// TODO: Rewrite to not use std::string -void CommandInterpreter::parseCommandLine(const QString& cL, std::vector<QString>& args) +QStringList CommandInterpreter::parseCommandLine(const QString& cL) { - std::string commandLine(cL.toStdString()); - // trim tail - { - std::string::size_type pos = commandLine.find_last_not_of(' '); - if (pos != std::string::npos) { - // Logger::logDEBUG("trimming tail of: '%s'", commandLine.c_str()); - commandLine = commandLine.substr(0, pos+1); - // Logger::logDEBUG(" - result: '%s'", commandLine.c_str()); - } - } - - // tokenize the string into arguments - while (commandLine.length() > 0) { - // trim front - if (commandLine[0] == ' ') { - std::string::size_type pos = commandLine.find_first_not_of(' '); - if (pos != std::string::npos) { - // Logger::logDEBUG("trimming front of: '%s'", commandLine.c_str()); - commandLine = commandLine.substr(pos); - // Logger::logDEBUG(" - result: '%s'", commandLine.c_str()); - } - } - // Logger::logDEBUG("commandLine: '%s'", commandLine.c_str()); - - std::string::size_type pos = commandLine.find_first_of(' '); - if (pos != std::string::npos) { - const QString& newArg = QString(commandLine.substr(0, pos).c_str()); - args.push_back(newArg); - commandLine = commandLine.substr(pos+1, commandLine.length()-pos); - // Logger::logDEBUG(" -arg recognized: '%s'", newArg.c_str()); - // Logger::logDEBUG(" -rest : '%s'", commandLine.c_str()); - } else { - // no spaces left, last argument - args.push_back(QString(commandLine.c_str())); - // Logger::logDEBUG(" -LAST arg recognized: '%s'", commandLine.c_str()); - commandLine.clear(); - } - } + return cL.trimmed().split(" ", QString::SkipEmptyParts); } Modified: rt^3/trunk/src/g3d/CommandInterpreter.h =================================================================== --- rt^3/trunk/src/g3d/CommandInterpreter.h 2009-07-28 01:29:55 UTC (rev 35330) +++ rt^3/trunk/src/g3d/CommandInterpreter.h 2009-07-28 02:32:50 UTC (rev 35331) @@ -105,7 +105,7 @@ Command* findCommand(const QString& commandName) const; /** Parse command line, putting each piece into the list of * arguments */ - void parseCommandLine(const QString& cL, std::vector<QString>& args); + QStringList parseCommandLine(const QString& cL); }; #endif Modified: rt^3/trunk/src/g3d/Commands.h =================================================================== --- rt^3/trunk/src/g3d/Commands.h 2009-07-28 01:29:55 UTC (rev 35330) +++ rt^3/trunk/src/g3d/Commands.h 2009-07-28 02:32:50 UTC (rev 35331) @@ -46,8 +46,8 @@ Command("quit", "Quit the application", "") { } - virtual QString execute(std::vector<QString>& args) { - if (args.size() > 0) { + virtual QString execute(QStringList &args) { + if (args.length() > 0) { return CommandMessages::NO_ARGUMENTS; } else { // TODO @@ -73,8 +73,8 @@ _argNames.push_back("level"); } - virtual QString execute(std::vector<QString>& args) { - if (args.size() != 1) { + virtual QString execute(QStringList &args) { + if (args.length() != 1) { return CommandMessages::ONE_ARGUMENT; } else { @@ -112,14 +112,14 @@ "Set the polygon mode", "Argument is [solid|wireframe|points] (initial chars are enough)") { - _argNames.push_back("mode"); + _argNames += ("mode"); // setting wireframe by default Application::instance().setPolygonMode(Ogre::PM_WIREFRAME); } - virtual QString execute(std::vector<QString>& args) { - if (args.size() != 1) { + virtual QString execute(QStringList &args) { + if (args.length() != 1) { return CommandMessages::ONE_ARGUMENT; return; } else { @@ -153,8 +153,8 @@ _argNames.push_back("type"); } - virtual QString execute(std::vector<QString>& args) { - if (args.size() != 1) { + virtual QString execute(QStringList &args) { + if (args.length() != 1) { output.appendLine(CommandMessages::ONE_ARGUMENT); return; } else { @@ -181,13 +181,13 @@ Command("cyclecam", "Cycle the camera mode", "") { } - virtual QString execute(std::vector<QString>& args) { - if (args.size() > 0) { - output.appendLine(CommandMessages::NO_ARGUMENTS); + virtual QString execute(QStringList &args) { + if (!args.empty()) { + return CommandMessages::NO_ARGUMENTS; } else { CameraManager::instance().cycleCameraMode(); } - return "" + return ""; } }; Modified: rt^3/trunk/src/g3d/GedCommands.h =================================================================== --- rt^3/trunk/src/g3d/GedCommands.h 2009-07-28 01:29:55 UTC (rev 35330) +++ rt^3/trunk/src/g3d/GedCommands.h 2009-07-28 02:32:50 UTC (rev 35331) @@ -52,11 +52,11 @@ _argNames.push_back("filename"); } - virtual QString execute(std::vector<QString>& args) { + virtual QString execute(QStringList &args) { ged* g = GedData::instance().getGED(); int result = 0; - if (args.size() != 1) { + if (args.length() != 1) { return CommandMessages::ONE_ARGUMENT; } else { const char* argv[] = { _name.toStdString().c_str(), args[1].toStdString().c_str() }; @@ -83,11 +83,11 @@ { } - virtual QString execute(std::vector<QString>& args) { + virtual QString execute(QStringList &args) { ged* g = GedData::instance().getGED(); int result = 0; - if (args.size() != 0) { + if (args.length() != 0) { return CommandMessages::NO_ARGUMENTS; } else { const char* argv[] = { _name.toStdString().c_str() }; @@ -115,14 +115,14 @@ _argNames.push_back("type"); } - virtual QString execute(std::vector<QString>& args) { + virtual QString execute(QStringList &args) { ged* g = GedData::instance().getGED(); int result = 0; - if (args.size() > 1) { + if (args.length() > 1) { return CommandMessages::ZERO_OR_ONE_ARGUMENTS; } else { - if (args.size() == 1) { + if (args.length() == 1) { QString type; if (args[0][0] == 'p') { type = "p"; @@ -164,14 +164,14 @@ _argNames.push_back("title"); } - virtual QString execute(std::vector<QString>& args) { + virtual QString execute(QStringList &args) { ged* g = GedData::instance().getGED(); int result = 0; - if (args.size() > 1) { + if (args.length() > 1) { return CommandMessages::ZERO_OR_ONE_ARGUMENTS; } else { - if (args.size() == 1) { + if (args.length() == 1) { const char* argv[] = { _name.toStdString().c_str(), args[1].toStdString().c_str() }; int argc = sizeof(argv)/sizeof(const char*); result = ged_title(g, argc, argv); @@ -201,8 +201,8 @@ { } - virtual QString execute(std::vector<QString>& args) { - if (args.size() != 0) { + virtual QString execute(QStringList &args) { + if (args.length() != 0) { return CommandMessages::NO_ARGUMENTS; } else { ged* g = GedData::instance().getGED(); @@ -230,11 +230,11 @@ { } - virtual QString execute(std::vector<QString>& args) { + virtual QString execute(QStringList &args) { ged* g = GedData::instance().getGED(); int result = 0; - if (args.size() != 0) { + if (args.length() != 0) { return CommandMessages::NO_ARGUMENTS; } else { return treatGEDResult(result, bu_vls_addr(&g->ged_result_str)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |