anyKode Marilou
|
Gestion de la ligne de commande et ses arguments.
class CommandLine;
CommandLine.h
L'objet CommandLine est utilisé pour travailler avec les arguments de la ligne de commande d'une application. Les arguments sont utiles pour rendre l'application 'robot indépendant' par exemple ou pour travailler avec différents serveurs.
Les arguments sont enregistrés dans le format "Clé=Valeur"
Argument |
Clé |
Valeur |
/robot:/myrobotphx |
/robot |
/myrobotphx (String) |
/argument:10 |
/argument |
10 (INT) |
/test |
/test |
|
test |
test |
|
L'objet CommandLine doit être initialisée en appelant la fonction ProcessCommandLine.
//Sample from Samples/Devices/LCD #include "Modacpp.h" #include "conio.h" #define DEFAULT_MODASERVER "localhost" #define DEFAULT_PHXNAME "/" using namespace ModaCPP; int main(int argc, char* argv[]) { //take a look at commandline arguments: // /server:[my server ip] // /robot:/myrobot CommandLine::ProcessCommandLine(argc,argv); xkode::lib::String Server; xkode::lib::String Phx; if(CommandLine::ExistsValue("/server")) Server=CommandLine::GetArgumentValue("/server"); else Server=DEFAULT_MODASERVER; if(CommandLine::ExistsValue("/robot")) Phx=CommandLine::GetArgumentValue("/robot"); else Phx=DEFAULT_PHXNAME; //Try connect to MODA server ModaCPP::Connection *connection=new ModaCPP::Connection(true); if(connection->Connect(Server)) { _cprintf("Connection ok to moda server %s\r\n",Server.GetData()); //Find the robot/world ModaCPP::RobotPHX *phx=connection->QueryRobotPHX(Phx); if(phx) { (...) Do something delete phx; } else { _cprintf("phx %s not found\r\n",Phx.GetData()); } } else { _cprintf("Unable to connect to moda server\r\n"); } //Disconnect & delete connection->Disconnect(); delete connection; _getch(); return 0; } Usage: MyApplication.exe /robot:/myrobotphx /server:192.168.1.1 /myargument
Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.
|
What do you think about this topic? Send feedback!
|