---
name: "cli.hpp"
section: "3"
platform: "linux"
package: "mlpack-doc"
version: "1.0.10-1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/cli.hpp"
---

# cli.hpp(3)

## NAME

src/mlpack/core/util/cli.hpp -

## SYNOPSIS

### Classes

class **mlpack::CLI**\
 *Parses the command line for parameters and holds user-specified parameters.*  struct **mlpack::ParamData**\
 *Aids in the extensibility of* **CLI** *by focusing potential changes into one structure.*

### Namespaces

 **mlpack**\
 *Linear algebra utility functions, generally performed on matrices or vectors.*   **mlpack::util**\

### Macros

\#define **PARAM**(T, ID, DESC, ALIAS, DEF, REQ)\
 *Define an input parameter.*  #define **PARAM\_DOUBLE**(ID, DESC, ALIAS, DEF)   **PARAM**(double, ID, DESC, ALIAS, DEF, false)\
 *Define a double parameter.*  #define **PARAM\_DOUBLE\_REQ**(ID, DESC, ALIAS)\
 *Define a required double parameter.*  #define **PARAM\_FLAG**(ID, DESC, ALIAS)   PARAM\_FLAG\_INTERNAL(ID, DESC, ALIAS);\
 *Define a flag parameter.*  #define **PARAM\_FLOAT**(ID, DESC, ALIAS, DEF)   **PARAM**(float, ID, DESC, ALIAS, DEF, false)\
 *Define a floating-point parameter.*  #define **PARAM\_FLOAT\_REQ**(ID, DESC, ALIAS)\
 *Define a required floating-point parameter.*  #define **PARAM\_INT**(ID, DESC, ALIAS, DEF)   **PARAM**(int, ID, DESC, ALIAS, DEF, false)\
 *Define an integer parameter.*  #define **PARAM\_INT\_REQ**(ID, DESC, ALIAS)   **PARAM**(int, ID, DESC, ALIAS, 0, true)\
 *Define a required integer parameter.*  #define **PARAM\_STRING**(ID, DESC, ALIAS, DEF)   **PARAM**(std::string, ID, DESC, ALIAS, DEF, false)\
 *Define a string parameter.*  #define **PARAM\_STRING\_REQ**(ID, DESC, ALIAS)\
 *Define a required string parameter.*  #define **PARAM\_VECTOR**(T, ID, DESC, ALIAS)   **PARAM**(std::vector\<T\>, ID, DESC, ALIAS, std::vector\<T\>(), false)\
 *Define a vector parameter.*  #define **PARAM\_VECTOR\_REQ**(T, ID, DESC, ALIAS)\
 *Define a required vector parameter.*  #define **PROGRAM\_INFO**(NAME, DESC)\
 *Document an executable.*  #define **TYPENAME**(x)   (std::string(typeid(x).name()))\
 *The TYPENAME macro is used internally to convert a type into a string.*

## Detailed Description

**Author:**

Matthew Amidon

This file implements the CLI subsystem which is intended to replace FX. This can be used more or less regardless of context. In the future, it might be expanded to include file I/O.

This file is part of MLPACK 1.0.10.

MLPACK is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details (LICENSE.txt).

You should have received a copy of the GNU General Public License along with MLPACK. If not, see http://www.gnu.org/licenses/.

Definition in file **cli.hpp**.

## Macro Definition Documentation

### #define PARAM(T, ID, DESC, ALIAS, DEF, REQ)

**Value:**

```
static mlpack::util::Option<T> \
      JOIN(JOIN(io_option_dummy_object_, __LINE__), opt) (false, DEF, ID,       DESC, ALIAS, REQ);
```

Define an input parameter. Don't use this function; use the other ones above that call it. Note that we are using the **LINE** macro for naming these actual parameters when **COUNTER** does not exist, which is a bit of an ugly hack... but this is the preprocessor, after all. We don't have much choice other than ugliness.

**Parameters:**

*T* Type of the parameter. \
 *ID* Name of the parameter. \
 *DESC* Description of the parameter (1-2 sentences). \
 *ALIAS* Alias for this parameter (one letter). \
 *DEF* Default value of the parameter. \
 *REQ* Whether or not parameter is required (boolean value).

Definition at line 357 of file cli.hpp.

### #define PARAM\_DOUBLE(ID, DESC, ALIAS, DEF) PARAM(double, ID, DESC, ALIAS, DEF, false)

Define a double parameter. The parameter can then be specified on the command line with --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter). \
 *DEF* Default value of the parameter.

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 146 of file cli.hpp.

### #define PARAM\_DOUBLE\_REQ(ID, DESC, ALIAS)

**Value:**

```
PARAM(double, ID, DESC, ALIAS,     0.0f, true)
```

Define a required double parameter. The parameter must then be specified on the command line with --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter).

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 267 of file cli.hpp.

### #define PARAM\_FLAG(ID, DESC, ALIAS) PARAM\_FLAG\_INTERNAL(ID, DESC, ALIAS);

Define a flag parameter.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter).

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 74 of file cli.hpp.

### #define PARAM\_FLOAT(ID, DESC, ALIAS, DEF) PARAM(float, ID, DESC, ALIAS, DEF, false)

Define a floating-point parameter. You should use PARAM\_DOUBLE instead.

The parameter can then be specified on the command line with --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter). \
 *DEF* Default value of the parameter.

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 122 of file cli.hpp.

### #define PARAM\_FLOAT\_REQ(ID, DESC, ALIAS)

**Value:**

```
PARAM(float, ID, DESC, ALIAS, 0.0f,     true)
```

Define a required floating-point parameter. You should probably use a double instead.

The parameter must then be specified on the command line with --ID=value. If ALIAS is equal to DEF\_MOD (which is set using the **PROGRAM\_INFO()** macro), the parameter can be specified with just --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter).

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 244 of file cli.hpp.

### #define PARAM\_INT(ID, DESC, ALIAS, DEF) PARAM(int, ID, DESC, ALIAS, DEF, false)

Define an integer parameter. The parameter can then be specified on the command line with --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter). \
 *DEF* Default value of the parameter.

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 98 of file cli.hpp.

### #define PARAM\_INT\_REQ(ID, DESC, ALIAS) PARAM(int, ID, DESC, ALIAS, 0, true)

Define a required integer parameter. The parameter must then be specified on the command line with --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter).

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 220 of file cli.hpp.

### #define PARAM\_STRING(ID, DESC, ALIAS, DEF) PARAM(std::string, ID, DESC, ALIAS, DEF, false)

Define a string parameter. The parameter can then be specified on the command line with --ID=value. If ALIAS is equal to DEF\_MOD (which is set using the **PROGRAM\_INFO()** macro), the parameter can be specified with just --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter). \
 *DEF* Default value of the parameter.

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 171 of file cli.hpp.

### #define PARAM\_STRING\_REQ(ID, DESC, ALIAS)

**Value:**

```
PARAM(std::string, ID, DESC,     ALIAS, "", true);
```

Define a required string parameter. The parameter must then be specified on the command line with --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter).

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 290 of file cli.hpp.

### #define PARAM\_VECTOR(T, ID, DESC, ALIAS) PARAM(std::vector\<T\>, ID, DESC, ALIAS, std::vector\<T\>(), false)

Define a vector parameter. The parameter can then be specified on the command line with --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter). \
 *DEF* Default value of the parameter.

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 195 of file cli.hpp.

### #define PARAM\_VECTOR\_REQ(T, ID, DESC, ALIAS)

**Value:**

```
PARAM(std::vector<T>, ID, DESC,     ALIAS, std::vector<T>(), true);
```

Define a required vector parameter. The parameter must then be specified on the command line with --ID=value.

**Parameters:**

*ID* Name of the parameter. \
 *DESC* Quick description of the parameter (1-2 sentences). \
 *ALIAS* An alias for the parameter (one letter).

**See also:**

**mlpack::CLI**, **PROGRAM\_INFO()**

**Bug**

The **COUNTER** variable is used in most cases to guarantee a unique global identifier for options declared using the PARAM\_\*() macros. However, not all compilers have this support--most notably, gcc \< 4.3. In that case, the **LINE** macro is used as an attempt to get a unique global identifier, but collisions are still possible, and they produce bizarre error messages. See http://mlpack.org/trac/ticket/74 for more information.

Definition at line 313 of file cli.hpp.

### #define PROGRAM\_INFO(NAME, DESC)

**Value:**

```
static mlpack::util::ProgramDoc     io_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, DESC);
```

Document an executable. Only one instance of this macro should be present in your program! Therefore, use it in the main.cpp (or corresponding executable) in your program.

**See also:**

**mlpack::CLI**, **PARAM\_FLAG()**, **PARAM\_INT()**, **PARAM\_DOUBLE()**, **PARAM\_STRING()**, **PARAM\_VECTOR()**, **PARAM\_INT\_REQ()**, **PARAM\_DOUBLE\_REQ()**, **PARAM\_STRING\_REQ()**, **PARAM\_VECTOR\_REQ()**.

**Parameters:**

*NAME* Short string representing the name of the program. \
 *DESC* Long string describing what the program does and possibly a simple usage example. Newlines should not be used here; this is taken care of by CLI (however, you can explicitly specify newlines to denote new paragraphs).

Definition at line 54 of file cli.hpp.

### #define TYPENAME(x) (std::string(typeid(x).name()))

The TYPENAME macro is used internally to convert a type into a string.

Definition at line 372 of file cli.hpp.

## Author

Generated automatically by Doxygen for MLPACK from the source code.
