Etermal
Embeddable Terminal and shell for OpenGL
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
etm::ArgFilter Class Reference

Used to process - or filter, if you will - command arguments. More...

#include <ArgFilter.h>

Classes

class  DefaultErrorHandle
 The default error handle. More...
 
class  ErrorHandle
 Used to determine what happens when there was a problem when processing arguments. More...
 
struct  Filter
 A single filter consisting of a parameter name and its desired parameter type. More...
 

Public Types

enum  datatype { STRING, INT, FLOAT, BOOL }
 Possible datatypes for an argument value. More...
 
typedef std::vector< Filterfilters_t
 Type of filter container.
 
typedef std::map< std::string, std::vector< Filter >::size_type > aliases_t
 Type used to represent a sequence of command aliases.
 

Public Member Functions

 ArgFilter ()
 Construct a new ArgFilter with the default error handle. More...
 
 ArgFilter (ErrorHandle &errorHandle)
 Construct a new ArgFilter with a custom error handle. More...
 
void setErrorHandle (ErrorHandle &errorHandle)
 Sets the error handle. More...
 
ErrorHandlegetErrorHandle ()
 Gets the error handle. More...
 
void setMaxArrayArgs (unsigned int count)
 Sets the maximum number of flagless parameters that can be passed. More...
 
void setUsage (const std::string &usage)
 Sets the string that is printed when the filter fails to parse arguments. More...
 
std::string getUsage ()
 Gets the command usage. More...
 
void addFilter (const std::string &name, datatype type)
 Add another filter, aka command parameter. More...
 
void addAlias (const std::string &name)
 Adds alias for last filter entree. More...
 
bool filter (const std::vector< std::string > &arguments, Args &out, std::string &errMsg)
 Filter/process/parse given arguments. More...
 

Static Public Member Functions

static const char * datatypeToString (datatype val)
 Converts a datatype to its string representation. More...
 
static void setDefaultErrorHandle (ErrorHandle &handle)
 Set the default error handle. More...
 
static ErrorHandlegetDefaultErrorHandle ()
 Get the default error handle. More...
 
static DefaultErrorHandlegetStoreDefaultErrorHandle ()
 Get the original default error handle. More...
 

Detailed Description

Used to process - or filter, if you will - command arguments.

See also
Args
data
Shell

Member Enumeration Documentation

◆ datatype

Possible datatypes for an argument value.

Enumerator
STRING 

String type.

INT 

Integer type.

FLOAT 

Floating point type.

BOOL 

Boolean type.

Constructor & Destructor Documentation

◆ ArgFilter() [1/2]

etm::ArgFilter::ArgFilter ( )

Construct a new ArgFilter with the default error handle.

See also
getDefaultErrorHandle()

◆ ArgFilter() [2/2]

etm::ArgFilter::ArgFilter ( ErrorHandle errorHandle)

Construct a new ArgFilter with a custom error handle.

See also
setErrorHandle(ErrorHandle &errorHandle)

Member Function Documentation

◆ addAlias()

void etm::ArgFilter::addAlias ( const std::string &  name)

Adds alias for last filter entree.

Note
Silently overwrites any pre-existing aliases of the same name.
Parameters
[in]nameThe alias
Exceptions
std::out_of_rangeIf there aren't any filters

◆ addFilter()

void etm::ArgFilter::addFilter ( const std::string &  name,
datatype  type 
)

Add another filter, aka command parameter.

Note
Does not account for filters that have the same name.
Parameters
[in]nameThe name of the parameter. This is what's used to lookup the parameter.
[in]typeThe expected type of the parameter

◆ datatypeToString()

static const char* etm::ArgFilter::datatypeToString ( datatype  val)
static

Converts a datatype to its string representation.

Returns "[invalid enum]" upon failure.

Parameters
[in]valThe datatype
Returns
A c-string representing the datatype.

◆ filter()

bool etm::ArgFilter::filter ( const std::vector< std::string > &  arguments,
Args out,
std::string &  errMsg 
)

Filter/process/parse given arguments.

Note
Assumes that arguments.size() > 0
Parameters
[in]argumentsThe arguments split up into parts
[out]outThe Args object to store data in
[out]errMsgString to dump error messages
Returns
true if encountered an error

◆ getDefaultErrorHandle()

static ErrorHandle& etm::ArgFilter::getDefaultErrorHandle ( )
static

Get the default error handle.

Returns
Reference to the current default error handle
See also
setDefaultErrorHandle(ErrorHandle &handle)

◆ getErrorHandle()

ErrorHandle& etm::ArgFilter::getErrorHandle ( )

Gets the error handle.

Returns
The error handle
See also
setErrorHandle(ErrorHandle &errorHandle)

◆ getStoreDefaultErrorHandle()

static DefaultErrorHandle& etm::ArgFilter::getStoreDefaultErrorHandle ( )
static

Get the original default error handle.

Returns
The error handle
See also
DefaultErrorHandle

◆ getUsage()

std::string etm::ArgFilter::getUsage ( )

Gets the command usage.

Returns
The usage.
See also
setUsage(const std::string &usage)

◆ setDefaultErrorHandle()

static void etm::ArgFilter::setDefaultErrorHandle ( ErrorHandle handle)
static

Set the default error handle.

The default error handle is what's set as the error handle of an ArgFilter if none are provided.

Note
Stores a pointer to handle, so you must keep it allocated.
Parameters
[in]handleReference to the new error handle
See also
getDefaultErrorHandle()

◆ setErrorHandle()

void etm::ArgFilter::setErrorHandle ( ErrorHandle errorHandle)

Sets the error handle.

The error handle is used to process errors when parsing command arguments.

Parameters
[in]errorHandleThe error handle
See also
ArgFilter(ErrorHandle &errorHandle)
getErrorHandle()

◆ setMaxArrayArgs()

void etm::ArgFilter::setMaxArrayArgs ( unsigned int  count)

Sets the maximum number of flagless parameters that can be passed.

Parameters
[in]countThe max, inclusive

◆ setUsage()

void etm::ArgFilter::setUsage ( const std::string &  usage)

Sets the string that is printed when the filter fails to parse arguments.

Parameters
[in]usageThe string to print
See also
getUsage()

The documentation for this class was generated from the following file: