anyKode Marilou
ContentsIndexHome
PreviousUpNext
CommandLine

Command line arguments management.

C++
class CommandLine;

CommandLine.h

The CommandLine object is used to manage easily user application's command line arguments. Arguments allow application to work with a robot as well as another without changing code. It is also useful for allow application to connect to a specified server or to use several working mode. 

 

Arguments are stored in Key=Value format :

Argument 
Key 
Value 
/robot:/myrobotphx 
/robot 
/myrobotphx (String) 
/argument:10 
/argument 
10 (INT) 
/test 
/test 
 
test 
test 
 

 

The CommandLine object must be initialized with ProcessCommandLine static function.

//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!