Base Module: Steinberg::CommandLine Namespace Reference
Author: Steinberg

Base Module VST 3.8 SDK for developing VST plug-in

Loading...
Searching...
No Matches
Classes | Typedefs | Functions
Steinberg::CommandLine Namespace Reference

Very simple command-line parser. More...

## Classes
class | Description
| The description of one single command-line option. More...
class | Descriptions
| List of command-line option descriptions. More...
class | VariablesMap
| Command-line parsing result. More...

## Typedefs
using | FilesVector = std::vector<std::string>
| type of the list of elements on the command line that are not handled by options parsing

## Functions
bool | parse (int ac, char *av[], const Descriptions &desc, VariablesMap &result, FilesVector *files=nullptr)
| Parse the command - line.
std::ostream & | operator<< (std::ostream &os, const Descriptions &desc)
| Make Descriptions stream able.

## Detailed Description

Very simple command-line parser.

Parses the command-line into a CommandLine::VariablesMap.
The command-line parser uses CommandLine::Descriptions to define the available options.

Example:

#include "base/source/fcommandline.h"
#include <iostream>
int main (int argc, char* argv[])
{
using namespace std;
CommandLine::Descriptions desc;
CommandLine::VariablesMap valueMap;
desc.addOptions ("myTool")
("help", "produce help message")
("opt1", string(), "option 1")
("opt2", string(), "option 2")
;
CommandLine::parse (argc, argv, desc, valueMap);
if (valueMap.hasError () || valueMap.count ("help"))
{
cout << desc << "\n";
return 1;
}
if (valueMap.count ("opt1"))
{
cout << "Value of option 1 " << valueMap["opt1"] << "\n";
}
if (valueMap.count ("opt2"))
{
cout << "Value of option 2 " << valueMap["opt2"] << "\n";
}
return 0;
}
Steinberg::CommandLine::Descriptions
List of command-line option descriptions.
Definition fcommandline.h:137
Steinberg::CommandLine::Descriptions::addOptions
Descriptions & addOptions(const std::string &caption="", std::initializer_list< Description > &&options={})
Sets the command-line tool caption and starts adding Descriptions.
Definition fcommandline.h:265
Steinberg::CommandLine::VariablesMap
Command-line parsing result.
Definition fcommandline.h:89
Steinberg::CommandLine::VariablesMap::hasError
bool hasError() const
Returns true when an error has occurred.
Definition fcommandline.h:96
Steinberg::CommandLine::VariablesMap::count
VariablesMapContainer::size_type count(const VariablesMapContainer::key_type k) const
Returns != 0 if command-line contains option k.
Definition fcommandline.h:184
fcommandline.h
Steinberg::CommandLine::parse
bool parse(int ac, char *av[], const Descriptions &desc, VariablesMap &result, FilesVector *files=nullptr)
Parse the command - line.
Definition fcommandline.h:359

Note
  This is a "header only" implementation.
  If you need the declarations in more than one cpp file, you have to define `SMTG_NO_IMPLEMENTATION` in all but one file.

## Typedef Documentation

## ◆ FilesVector

using FilesVector = std::vector<std::string>

type of the list of elements on the command line that are not handled by options parsing

## Function Documentation

## ◆ parse()

bool parse | ( | int | ac,
|  | char * | av[],
|  | const Descriptions & | desc,
|  | VariablesMap & | result,
|  | FilesVector * | files )

Parse the command - line.

Parameters

  [in] | ac | count of command-line parameters
  [in] | av | command-line as array of strings
  [in] | desc | Descriptions including all allowed options
  [out] | result | the parsing result
  [out] | files | optional list of elements on the command line that are not handled by options parsing

## ◆ operator<<()

std::ostream & operator<< | ( | std::ostream & | os,
|  | const Descriptions & | desc )

Make Descriptions stream able.

Empty

Copyright © Steinberg Media Technologies GmbH. All Rights Reserved. This documentation is under this license.