ArgScript::Line class

This class represents a line of ArgScript data.

A line is made up by a keyword, multiple or none arguments, and multiple or none options. For example: "keyword argument1 argument2 -option1 -option2 optionArgument". All the elements in a line are separated by whitespaces; string literals that require whitespaces can be surrounded by "" or (). The first element is always considered the keyword; the words that follow it are arguments. If a word is preceded by '-', it is considered an option (for example, the option "-scale 1.2"). Options can be followed by arguments; if an option does not have any argument, it is considered a 'flag'.

Public static variables

static const size_t kMaxInt

Public static functions

static auto GetEnum(const char* valueString, const EnumValue* pEnum) -> int
Gets the integer value that corresponds to the given string in the specified enum.
static auto GetOptionalEnum(const char* valueString, const EnumValue* pEnum, int& dst) -> bool
Gets the integer value that corresponds to the given string in the specified enum.

Constructors, destructors, conversion operators

Line()
Line(const char* text)

Public functions

void FromString(const char* text)
Separates the given text into the arguments and options that form the line.
void RemoveKeyword()
Removes the keyword (the first argument) from this line.
auto GetArguments(size_t count) const -> Arguments
Gets the specified number of arguments from this line.
auto GetArgumentsRange(size_t* dstCount, size_t nMin, size_t nMax = kMaxInt) const -> Arguments
Gets the arguments from this line, which must be in the specified range.
auto GetArgumentsCount() const -> size_t
Gets the number of arguments this line contains.
auto GetArgumentAt(size_t index) const -> const char*
Gets the argument at the given index.
auto GetOption(const char* optionName, size_t count) const -> Arguments
Gets the specified number of arguments from an option with the given name.
auto GetOptionRange(const char* optionName, size_t* dstCount, size_t nMin, size_t nMax = kMaxInt) const -> Arguments
Gets the arguments from an option with the given name, which must be in the specified range.
auto HasFlag(const char* flagName) const -> bool
Tells whether the line contains the given flag or not.

Protected variables

vector<char> mBuffer
vector<char*> mArguments
vector<LineOption> mOptions
size_t mFirstArgIndex
size_t mArgumentCount

Function documentation

static int ArgScript::Line::GetEnum(const char* valueString, const EnumValue* pEnum)

Gets the integer value that corresponds to the given string in the specified enum.

Parameters
valueString The string value of the enumeration.
pEnum An array of pair<const char*, int> objects where the values will be checked.
Returns The integer value assigned to that enumeration.

If the enum does not have any value assigned to that string, an exception will be thrown.

static bool ArgScript::Line::GetOptionalEnum(const char* valueString, const EnumValue* pEnum, int& dst)

Gets the integer value that corresponds to the given string in the specified enum.

Parameters
valueString The string value of the enumeration.
pEnum An array of pair<const char*, int> objects where the values will be checked.
dst The integer where the value will be set. If no value is found, it won't be modified.
Returns Whether a value was found or not.

This method does not throw an exception if the enumeration does not have any value assigned to that string.

void ArgScript::Line::FromString(const char* text)

Separates the given text into the arguments and options that form the line.

By default, the keyword is considered as an argument; use the RemoveKeyword() method to change it.

Arguments ArgScript::Line::GetArguments(size_t count) const

Gets the specified number of arguments from this line.

Parameters
count The number of arguments this line must have.
Returns An array of char* strings.

This does not include the keyword. If the number of arguments is not equal to the one required, an exception will be thrown.

Arguments ArgScript::Line::GetArgumentsRange(size_t* dstCount, size_t nMin, size_t nMax = kMaxInt) const

Gets the arguments from this line, which must be in the specified range.

Parameters
dstCount The destination size_t where the number of arguments got will be written, or nullptr.
nMin The minimum number of arguments this line can have.
nMax The maximum number of arguments this line can have.
Returns An array of char* strings.

This does not include the keyword. If the number of arguments is less than nMin, or greater than nMax, an exception will be thrown. The number of arguments is returned in the parameter dstCount. Usage example:

size_t count;
auto args = line.GetArgumentsRange(&count, 1, kMaxInt);

size_t ArgScript::Line::GetArgumentsCount() const

Gets the number of arguments this line contains.

This does not include the keyword.

const char* ArgScript::Line::GetArgumentAt(size_t index) const

Gets the argument at the given index.

Parameters
index The index of the argument.

Arguments ArgScript::Line::GetOption(const char* optionName, size_t count) const

Gets the specified number of arguments from an option with the given name.

Parameters
optionName The name of the option. In the line, it must be prefixed with a '-'.
count The number of arguments this line must have.
Returns An array of char* strings.

Options are optional values, which are set prefixing the option name with a '-', for example '-scale 2'. This does not include the keyword. If the number of arguments is not equal to the one required, an exception will be thrown.

Arguments ArgScript::Line::GetOptionRange(const char* optionName, size_t* dstCount, size_t nMin, size_t nMax = kMaxInt) const

Gets the arguments from an option with the given name, which must be in the specified range.

Parameters
optionName The name of the option. In the line, it must be prefixed with a '-'.
dstCount The destination size_t where the number of arguments got will be written, or nullptr.
nMin The minimum number of arguments this line can have.
nMax The maximum number of arguments this line can have.
Returns An array of char* strings.

Options are optional values, which are set prefixing the option name with a '-', for example '-scale 2'. This does not include the keyword. If the number of arguments is less than nMin, or greater than nMax, an exception will be thrown. The number of arguments is returned in the parameter dstCount. Usage example:

size_t count;
auto args = line.GetOptionRange("option", &count, 1, kMaxInt);

bool ArgScript::Line::HasFlag(const char* flagName) const

Tells whether the line contains the given flag or not.

Parameters
flagName The name of the flag. In the line, it must be prefixed with a '-'.

A flag is an option with no values.