Lector v1.0.0
C++ library for parsing command line arguments.
Classes | Typedefs | Enumerations | Functions | Variables
lector Namespace Reference

The Lector library's namespace. More...

Classes

struct  AreUnique
 Data structure that validates at compilation time that a specified variadic list of types are unique. Base data structure that contains an empty list of types and returns true.
 
struct  AreUnique< FirstType, RemainingTypes... >
 Data structure that validates at compilation time that a specified variadic list of types are unique. Recursively compares a first type against the remaining variadic list of types.
 
class  Argument
 A command line argument, including its label, value type, keys, description, importance, default value, and parsed value. More...
 
class  Arguments
 A collection of command line arguments that can be parsed from argc and argv. More...
 
struct  FindArgumentByLabel
 Type trait used to extract a command line argument from a collection of command line arguments, using only its Label.
 
struct  FindArgumentByLabel< Label, ::lector::Argument< Label, Type >, OtherArgumentTypes... >
 Type trait specialization used to extract a command line argument from a collection of command line arguments, using its Label, its type, and the types of the remaining command line arguments in the collection.
 
struct  FindArgumentByLabel< Label, ::lector::Argument< OtherLabel, OtherType >, RemainingArgumentTypes... >
 Type trait specialization used to extract a command line argument from a collection of command line arguments, using its Label and the types of the remaining command line arguments in the collection.
 

Typedefs

template<typename Type >
using Name = ::std::pair< Type, ::std::string_view >
 The canonical printed name for a value of a specified type.
 
template<typename Type >
using Spelling = ::std::pair<::std::string_view, Type >
 A possible spelling for a value of a specified type.
 

Enumerations

enum class  Importance : ::std::int8_t {
  Optional = 0 ,
  Required = 1
}
 Importance of a command line argument. More...
 

Functions

::std::size_t code_points (const ::std::string_view text)
 Counts and returns the number of UTF-8 code points in a string of text. The number of UTF-8 code points is a useful approximation of the number of graphemes in the string.
 
::std::string combine_and_left_align (const ::std::string_view first_column_text, const ::std::size_t first_column_width, const ::std::string_view second_column_text, const ::std::size_t second_column_width)
 Combines two strings of text, each representing a column, into a single vector of strings that contains one line per string of text, with the lines formatted such that the two columns are left-aligned and spaced a short distance apart.
 
::std::string join_and_left_align (const ::std::vector<::std::string > &lines)
 Joins a vector of strings where each string corresponds to a line of text into a single string of text, with newline characters inserted between the lines, and the lines left-aligned.
 
::std::size_t longest_word_length (const ::std::string_view text)
 Computes and returns the length of the longest word in a string of text. The length of a word is measured by its number of UTF-8 code points.
 
template<typename Type >
::std::optional< Type > parse (::std::string_view text)
 Parses a string of text into a value of a specific type. If the type is an enumeration type, it must define a specialization of the lector::Spellings constant for its type.
 
template<>
::std::optional< bool > parse (const ::std::string_view text)
 Parses a string of text into a boolean value. For example, the string of text "true" returns the boolean value true.
 
template<>
::std::optional<::std::uint8_t > parse (const ::std::string_view text)
 Parses a string of text into an 8-bit natural number. For example, the string of text "42" returns the number 42.
 
template<>
::std::optional<::std::uint16_t > parse (const ::std::string_view text)
 Parses a string of text into a 16-bit natural number. For example, the string of text "42" returns the number 42.
 
template<>
::std::optional<::std::uint32_t > parse (const ::std::string_view text)
 Parses a string of text into a 32-bit natural number. For example, the string of text "42" returns the number 42.
 
template<>
::std::optional<::std::uint64_t > parse (const ::std::string_view text)
 Parses a string of text into a 64-bit natural number. For example, the string of text "42" returns the number 42.
 
template<>
::std::optional<::std::int8_t > parse (const ::std::string_view text)
 Parses a string of text into an 8-bit integer number. For example, the string of text "42" returns the number 42.
 
template<>
::std::optional<::std::int16_t > parse (const ::std::string_view text)
 Parses a string of text into a 16-bit integer number. For example, the string of text "42" returns the number 42.
 
template<>
::std::optional<::std::int32_t > parse (const ::std::string_view text)
 Parses a string of text into a 32-bit integer number. For example, the string of text "42" returns the number 42.
 
template<>
::std::optional<::std::int64_t > parse (const ::std::string_view text)
 Parses a string of text into a 64-bit integer number. For example, the string of text "42" returns the number 42.
 
template<>
::std::optional< float > parse (const ::std::string_view text)
 Parses a string of text into a single-precision floating-point number. For example, the string of text "3.14" returns the number 3.14.
 
template<>
::std::optional< double > parse (const ::std::string_view text)
 Parses a string of text into a double-precision floating-point number. For example, the string of text "3.14" returns the number 3.14.
 
template<>
::std::optional< long double > parse (const ::std::string_view text)
 Parses a string of text into an extended-precision floating-point number. For example, the string of text "3.14" returns the number 3.14.
 
template<>
::std::optional<::std::string > parse (const ::std::string_view text)
 Parses a string view into a string of text.
 
template<>
::std::optional<::std::string_view > parse (const ::std::string_view text)
 Returns a string of text as-is.
 
template<>
::std::optional<::std::filesystem::path > parse (const ::std::string_view text)
 Parses a string of text into a filesystem path.
 
template<typename EnumerationType >
constexpr ::std::optional< EnumerationType > parse_enumeration (const ::std::string_view text)
 Parses a string of text into an enumeration value. The enumeration type must define a specialization of the lector::Spellings constant for its type.
 
template<>
::std::string print (const ::std::filesystem::path &value)
 Prints a filesystem path as a string of text.
 
template<>
::std::string print (const ::std::int16_t &value)
 Prints a 16-bit integer number as a string of text.
 
template<>
::std::string print (const ::std::int32_t &value)
 Prints a 32-bit integer number as a string of text.
 
template<>
::std::string print (const ::std::int64_t &value)
 Prints a 64-bit integer number as a string of text.
 
template<>
::std::string print (const ::std::int8_t &value)
 Prints an 8-bit integer number as a string of text.
 
template<>
::std::string print (const ::std::string &value)
 Returns a string of text as-is.
 
template<>
::std::string print (const ::std::string_view &value)
 Prints a string view as a string of text.
 
template<>
::std::string print (const ::std::uint16_t &value)
 Prints a 16-bit natural number as a string of text.
 
template<>
::std::string print (const ::std::uint32_t &value)
 Prints a 32-bit natural number as a string of text.
 
template<>
::std::string print (const ::std::uint64_t &value)
 Prints a 64-bit natural number as a string of text.
 
template<>
::std::string print (const ::std::uint8_t &value)
 Prints an 8-bit natural number as a string of text.
 
template<>
::std::string print (const bool &value)
 Prints a boolean value as a string of text.
 
template<>
::std::string print (const double &value)
 Prints a double-precision floating-point number as a string of text.
 
template<>
::std::string print (const float &value)
 Prints a single-precision floating-point number as a string of text.
 
template<>
::std::string print (const long double &value)
 Prints an extended-precision floating-point number as a string of text.
 
template<typename Type >
::std::string print (const Type &value)
 Prints a value of a specific type as a string of text.
 
template<typename EnumerationType >
constexpr ::std::string_view print_enumeration (const EnumerationType value)
 Prints a value of a specified enumeration type as a string of text. The enumeration type must define a specialization of the lector::Names constant for its type.
 
::std::vector<::std::string > wrap (const ::std::string_view text, const ::std::size_t line_length)
 Wraps a string of text to a line length and returns the result as a vector of strings that contains one string per line.
 
::std::string wrap_and_left_align (const ::std::string_view text, const ::std::size_t line_length)
 Left-aligns and wraps a string of text to a line length.
 

Variables

template<typename Type >
constexpr ::std::array<::lector::Name< Type >, 0UL > Names {}
 Map of canonical printed names to their corresponding values of a specified type.
 
template<typename Type >
constexpr ::std::array<::lector::Spelling< Type >, 0UL > Spellings {}
 Map of spellings to their corresponding values of a specified type.
 

Detailed Description

The Lector library's namespace.

Typedef Documentation

◆ Name

template<typename Type >
using lector::Name = typedef ::std::pair<Type, ::std::string_view>

The canonical printed name for a value of a specified type.

Template Parameters
TypeThe type of the value.

◆ Spelling

template<typename Type >
using lector::Spelling = typedef ::std::pair<::std::string_view, Type>

A possible spelling for a value of a specified type.

Template Parameters
TypeThe type of the value.

Enumeration Type Documentation

◆ Importance

enum class lector::Importance : ::std::int8_t
strong

Importance of a command line argument.

Enumerator
Optional 

The command line argument is optional; it may or may not be provided by the user.

Required 

The command line argument is required; it must be provided by the user.

Function Documentation

◆ code_points()

::std::size_t lector::code_points ( const ::std::string_view  text)

Counts and returns the number of UTF-8 code points in a string of text. The number of UTF-8 code points is a useful approximation of the number of graphemes in the string.

Parameters
[in]textThe string of text whose UTF-8 code points are to be counted.
Returns
The number of UTF-8 code points in the string of text.

◆ combine_and_left_align()

::std::string lector::combine_and_left_align ( const ::std::string_view  first_column_text,
const ::std::size_t  first_column_width,
const ::std::string_view  second_column_text,
const ::std::size_t  second_column_width 
)

Combines two strings of text, each representing a column, into a single vector of strings that contains one line per string of text, with the lines formatted such that the two columns are left-aligned and spaced a short distance apart.

Parameters
[in]first_column_textThe string of text for the first column.
[in]first_column_widthThe desired width of the first column. The actual width may be larger if the string of text contains very long words whose lengths exceed the desired column width.
[in]second_column_textThe string of text for the second column.
[in]second_column_widthThe desired width of the second column. The actual width may be larger if the string of text contains very long words whose lengths exceed the desired column width.
Returns
The vector of strings that contains the combined text.

◆ join_and_left_align()

::std::string lector::join_and_left_align ( const ::std::vector<::std::string > &  lines)

Joins a vector of strings where each string corresponds to a line of text into a single string of text, with newline characters inserted between the lines, and the lines left-aligned.

Parameters
[in]linesVector of strings to be joined and left-aligned.
Returns
The joined and left-aligned string of text.

◆ longest_word_length()

::std::size_t lector::longest_word_length ( const ::std::string_view  text)

Computes and returns the length of the longest word in a string of text. The length of a word is measured by its number of UTF-8 code points.

Parameters
[in]textThe string of text whose longest word length is to be computed.
Returns
The length of the longest word in the string of text.

◆ parse() [1/16]

template<typename Type >
::std::optional< Type > lector::parse ( ::std::string_view  text)

Parses a string of text into a value of a specific type. If the type is an enumeration type, it must define a specialization of the lector::Spellings constant for its type.

Parses a string of text into a value of a specific type. If the type is an enumeration type, it must define a specialization of the lector::Spellings constant for its type; otherwise, the type must be streamable with the >> input stream operator.

Template Parameters
TypeThe type of the value in which to parse the string of text.
Parameters
[in]textThe string of text to parse.
Returns
The parsed value, or std::nullopt if the string of text could not be parsed into a valid value.

◆ parse() [2/16]

template<>
::std::optional< bool > lector::parse ( const ::std::string_view  text)

Parses a string of text into a boolean value. For example, the string of text "true" returns the boolean value true.

Parameters
[in]textThe string of text to parse.
Returns
The parsed boolean value, or std::nullopt if the string of text could not be parsed into a valid boolean value.

◆ parse() [3/16]

template<>
::std::optional<::std::uint8_t > lector::parse ( const ::std::string_view  text)

Parses a string of text into an 8-bit natural number. For example, the string of text "42" returns the number 42.

Parameters
[in]textThe string of text to parse.
Returns
The parsed 8-bit natural number, or std::nullopt if the string of text could not be parsed into a valid 8-bit natural number.

◆ parse() [4/16]

template<>
::std::optional<::std::uint16_t > lector::parse ( const ::std::string_view  text)

Parses a string of text into a 16-bit natural number. For example, the string of text "42" returns the number 42.

Parameters
[in]textThe string of text to parse.
Returns
The parsed 16-bit natural number, or std::nullopt if the string of text could not be parsed into a valid 16-bit natural number.

◆ parse() [5/16]

template<>
::std::optional<::std::uint32_t > lector::parse ( const ::std::string_view  text)

Parses a string of text into a 32-bit natural number. For example, the string of text "42" returns the number 42.

Parameters
[in]textThe string of text to parse.
Returns
The parsed 32-bit natural number, or std::nullopt if the string of text could not be parsed into a valid 32-bit natural number.

◆ parse() [6/16]

template<>
::std::optional<::std::uint64_t > lector::parse ( const ::std::string_view  text)

Parses a string of text into a 64-bit natural number. For example, the string of text "42" returns the number 42.

Parameters
[in]textThe string of text to parse.
Returns
The parsed 64-bit natural number, or std::nullopt if the string of text could not be parsed into a valid 64-bit natural number.

◆ parse() [7/16]

template<>
::std::optional<::std::int8_t > lector::parse ( const ::std::string_view  text)

Parses a string of text into an 8-bit integer number. For example, the string of text "42" returns the number 42.

Parameters
[in]textThe string of text to parse.
Returns
The parsed 8-bit integer number, or std::nullopt if the string of text could not be parsed into a valid 8-bit integer number.

◆ parse() [8/16]

template<>
::std::optional<::std::int16_t > lector::parse ( const ::std::string_view  text)

Parses a string of text into a 16-bit integer number. For example, the string of text "42" returns the number 42.

Parameters
[in]textThe string of text to parse.
Returns
The parsed 16-bit integer number, or std::nullopt if the string of text could not be parsed into a valid 16-bit integer number.

◆ parse() [9/16]

template<>
::std::optional<::std::int32_t > lector::parse ( const ::std::string_view  text)

Parses a string of text into a 32-bit integer number. For example, the string of text "42" returns the number 42.

Parameters
[in]textThe string of text to parse.
Returns
The parsed 32-bit integer number, or std::nullopt if the string of text could not be parsed into a valid 32-bit integer number.

◆ parse() [10/16]

template<>
::std::optional<::std::int64_t > lector::parse ( const ::std::string_view  text)

Parses a string of text into a 64-bit integer number. For example, the string of text "42" returns the number 42.

Parameters
[in]textThe string of text to parse.
Returns
The parsed 64-bit integer number, or std::nullopt if the string of text could not be parsed into a valid 64-bit integer number.

◆ parse() [11/16]

template<>
::std::optional< float > lector::parse ( const ::std::string_view  text)

Parses a string of text into a single-precision floating-point number. For example, the string of text "3.14" returns the number 3.14.

Parameters
[in]textThe string of text to parse.
Returns
The parsed single-precision floating-point number, or std::nullopt if the string of text could not be parsed into a valid single-precision floating-point number.

◆ parse() [12/16]

template<>
::std::optional< double > lector::parse ( const ::std::string_view  text)

Parses a string of text into a double-precision floating-point number. For example, the string of text "3.14" returns the number 3.14.

Parameters
[in]textThe string of text to parse.
Returns
The parsed double-precision floating-point number, or std::nullopt if the string of text could not be parsed into a valid double-precision floating-point number.

◆ parse() [13/16]

template<>
::std::optional< long double > lector::parse ( const ::std::string_view  text)

Parses a string of text into an extended-precision floating-point number. For example, the string of text "3.14" returns the number 3.14.

Parameters
[in]textThe string of text to parse.
Returns
The parsed extended-precision floating-point number, or std::nullopt if the string of text could not be parsed into a valid extended-precision floating-point number.

◆ parse() [14/16]

template<>
::std::optional<::std::string > lector::parse ( const ::std::string_view  text)

Parses a string view into a string of text.

Parameters
[in]textThe string view to parse.
Returns
The parsed string.

◆ parse() [15/16]

template<>
::std::optional<::std::string_view > lector::parse ( const ::std::string_view  text)

Returns a string of text as-is.

Parameters
[in]textThe string of text.
Returns
The string of text.

◆ parse() [16/16]

template<>
::std::optional<::std::filesystem::path > lector::parse ( const ::std::string_view  text)

Parses a string of text into a filesystem path.

Parameters
[in]textThe string of text to parse.
Returns
The parsed filesystem path, or std::nullopt if the string of text could not be parsed into a valid filesystem path.

◆ parse_enumeration()

template<typename EnumerationType >
constexpr ::std::optional< EnumerationType > lector::parse_enumeration ( const ::std::string_view  text)
constexpr

Parses a string of text into an enumeration value. The enumeration type must define a specialization of the lector::Spellings constant for its type.

Template Parameters
EnumerationTypeThe enumeration type.
Parameters
[in]textThe string of text to parse.
Returns
The parsed enumeration value, or std::nullopt if the string of text could not be parsed into a valid enumeration value.

◆ print() [1/16]

template<>
::std::string lector::print ( const ::std::filesystem::path &  value)

Prints a filesystem path as a string of text.

Parameters
[in]valueThe filesystem path to print.
Returns
The filesystem path as a printed string of text.

◆ print() [2/16]

template<>
::std::string lector::print ( const ::std::int16_t &  value)

Prints a 16-bit integer number as a string of text.

Parameters
[in]valueThe 16-bit integer number to print.
Returns
The 16-bit integer number as a printed string of text.

◆ print() [3/16]

template<>
::std::string lector::print ( const ::std::int32_t &  value)

Prints a 32-bit integer number as a string of text.

Parameters
[in]valueThe 32-bit integer number to print.
Returns
The 32-bit integer number as a printed string of text.

◆ print() [4/16]

template<>
::std::string lector::print ( const ::std::int64_t &  value)

Prints a 64-bit integer number as a string of text.

Parameters
[in]valueThe 64-bit integer number to print.
Returns
The 64-bit integer number as a printed string of text.

◆ print() [5/16]

template<>
::std::string lector::print ( const ::std::int8_t &  value)

Prints an 8-bit integer number as a string of text.

Parameters
[in]valueThe 8-bit integer number to print.
Returns
The 8-bit integer number as a printed string of text.

◆ print() [6/16]

template<>
::std::string lector::print ( const ::std::string &  value)

Returns a string of text as-is.

Parameters
[in]valueThe string of text.
Returns
The string of text.

◆ print() [7/16]

template<>
::std::string lector::print ( const ::std::string_view &  value)

Prints a string view as a string of text.

Parameters
[in]valueThe string view to print.
Returns
The string view as a printed string of text.

◆ print() [8/16]

template<>
::std::string lector::print ( const ::std::uint16_t &  value)

Prints a 16-bit natural number as a string of text.

Parameters
[in]valueThe 16-bit natural number to print.
Returns
The 16-bit natural number as a printed string of text.

◆ print() [9/16]

template<>
::std::string lector::print ( const ::std::uint32_t &  value)

Prints a 32-bit natural number as a string of text.

Parameters
[in]valueThe 32-bit natural number to print.
Returns
The 32-bit natural number as a printed string of text.

◆ print() [10/16]

template<>
::std::string lector::print ( const ::std::uint64_t &  value)

Prints a 64-bit natural number as a string of text.

Parameters
[in]valueThe 64-bit natural number to print.
Returns
The 64-bit natural number as a printed string of text.

◆ print() [11/16]

template<>
::std::string lector::print ( const ::std::uint8_t &  value)

Prints an 8-bit natural number as a string of text.

Parameters
[in]valueThe 8-bit natural number to print.
Returns
The 8-bit natural number as a printed string of text.

◆ print() [12/16]

template<>
::std::string lector::print ( const bool &  value)

Prints a boolean value as a string of text.

Parameters
[in]valueThe boolean value to print.
Returns
The boolean value as a printed string of text.

◆ print() [13/16]

template<>
::std::string lector::print ( const double &  value)

Prints a double-precision floating-point number as a string of text.

Parameters
[in]valueThe double-precision floating-point number to print.
Returns
The double-precision floating-point number as a printed string of text.

◆ print() [14/16]

template<>
::std::string lector::print ( const float &  value)

Prints a single-precision floating-point number as a string of text.

Parameters
[in]valueThe single-precision floating-point number to print.
Returns
The single-precision floating-point number as a printed string of text.

◆ print() [15/16]

template<>
::std::string lector::print ( const long double &  value)

Prints an extended-precision floating-point number as a string of text.

Parameters
[in]valueThe extended-precision floating-point number to print.
Returns
The extended-precision floating-point number as a printed string of text.

◆ print() [16/16]

template<typename Type >
::std::string lector::print ( const Type &  value)

Prints a value of a specific type as a string of text.

Prints a value of a specific type as a string of text. If the type is an enumeration type, it must define a specialization of the lector::Names constant for its type; otherwise, the type must be streamable with the << output stream operator.

Template Parameters
TypeThe type of the value to print.
Parameters
[in]valueThe value to print.
Returns
The value as a printed string of text.

◆ print_enumeration()

template<typename EnumerationType >
constexpr ::std::string_view lector::print_enumeration ( const EnumerationType  value)
constexpr

Prints a value of a specified enumeration type as a string of text. The enumeration type must define a specialization of the lector::Names constant for its type.

Template Parameters
EnumerationTypeThe enumeration type.
Parameters
[in]valueThe enumeration value to print.
Returns
The value as a printed string of text.

◆ wrap()

::std::vector<::std::string > lector::wrap ( const ::std::string_view  text,
const ::std::size_t  line_length 
)

Wraps a string of text to a line length and returns the result as a vector of strings that contains one string per line.

Parameters
[in]textThe string of text to wrap.
[in]line_lengthThe desired line length to use when wrapping. The actual line length may be longer if the string of text contains very long words whose lengths exceed the desired line length.
Returns
The resulting vector of strings that contains one string per line.

◆ wrap_and_left_align()

::std::string lector::wrap_and_left_align ( const ::std::string_view  text,
const ::std::size_t  line_length 
)

Left-aligns and wraps a string of text to a line length.

Parameters
[in]textThe string of text to left-align and wrap.
[in]line_lengthThe desired line length to use when wrapping. The actual line length may be longer if the string of text contains very long words whose lengths exceed the desired line length.
Returns
The resulting left-aligned and wrapped text.

Variable Documentation

◆ Names

template<typename Type >
constexpr ::std::array<::lector::Name<Type>, 0UL> lector::Names {}

Map of canonical printed names to their corresponding values of a specified type.

Template Parameters
TypeThe type of the values.

◆ Spellings

template<typename Type >
constexpr ::std::array<::lector::Spelling<Type>, 0UL> lector::Spellings {}

Map of spellings to their corresponding values of a specified type.

Template Parameters
TypeThe type of the values.