Command Line
Attention
Tracktable’s C++ interface does currently have
command line factories available however they have not been
integrated into Tracktable’s main components. This means,
for example, that you will not be able to call Tracktable’s
C++ AssembleTrajectories function directly from the
command line. However, these factories can be integrated into
other programs utilizing Tracktable’s C++ interface to enable
a command line interface for that program
Enabling Command Line Factories
The C++ interface contains multiple command line factories that allow for easy integration
of command line parameters for a compiled program. All of the command line factories are
wrapped thinly wrapped boost::program_options. The provided factories are as follows:
The
CommandLineFactoryclass generates the basichelpCLI input that will output the provided help text for the given program. This factory also allows for user-generated options to be added to a program’s CLI. This can include, for example, options such asinput,outputandtolerance.The
PointReaderFromCommandLineis a derived class fromCommandLineFactorythat inlcudes all of the various options that are specific for initializing and usingtracktable::PointReaderfrom the command line.The
AssemblerFromCommandLineis a derived class fromCommandLineFactorythat inlcudes all of the various options that are specific for initializing and usingtracktable::AssembleTrajectoriesfrom the command line.
Adding command line factories with custom options and initializing exisitng factories is as simple as:
1#include <tracktable/CommandLineFactories/AssemblerFromCommandLine.h>
2#include <tracktable/CommandLineFactories/PointReaderFromCommandLine.h>
3
4boost::program_options::options_description commandLineOptions;
5commandLineOptions.add_options()("help", "Print help");
6
7// Create command line factories
8tracktable::PointReaderFromCommandLine<PointT> readerFactory;
9tracktable::AssemblerFromCommandLine<TrajectoryT> assemblerFactory;
10// Add options from the factories
11readerFactory.addOptions(commandLineOptions);
12assemblerFactory.addOptions(commandLineOptions);
13
14// And a command line option for output
15commandLineOptions.add_options()("output", bpo::value<std::string>()->default_value("-"),
16 "file to write to (use '-' for stdout), overridden by 'separate-kmls'");
17
18/** Boost program options using a variable map to tie everything together.
19 * one parse will have a single variable map. We need to let the factories know
20 * about this variable map so they can pull information out of it */
21auto vm = std::make_shared<boost::program_options::variables_map>();
22readerFactory.setVariables(vm);
23assemblerFactory.setVariables(vm);
Once the factories are initialized and the custom options are added the command line needs to be parsed
1// Parse the command lines, don't forget the 'notify' after
2try {
3 // We use this try/catch to automatically display help when an unknown option is used
4 boost::program_options::store(
5 boost::program_options::command_line_parser(_argc, _argv).options(commandLineOptions).run(), *vm);
6 boost::program_options::notify(*vm);
7} catch (boost::program_options::error e) {
8 std::cerr << e.what();
9 std::cerr << helpmsg << "\n\n";
10 std::cerr << commandLineOptions << std::endl;
11 return 1;
12}
13/** Parsing will give an error of an incorrect option is used, but it won't
14 * display the help unless we tell it too */
15if (vm->count("help") != 0) {
16 std::cerr << helpmsg << "\n\n";
17 std::cerr << commandLineOptions << std::endl;
18 return 1;
19}
After the inputs are parsed then the program can perform any necessary operations on the data or values being passed into the program.
Once the program is compiled into an executable it can be run identically to other command line programs.
$ ./assemble --input=/data/flights.tsv --output=/data/flights.trj
Note
This command is specific to Linux and Mac. Windows machines will have a different command line call.