Specifying option types

type is required, and specifies each option's type, what name->value or name->values gets. The following types are known: bool (useful for options that take no values), int, uint, long, ulong, longlong, ulonglong, int16, uint16, int32, uint32, int64, uint64, string (a std::string, the value is a generic string that's not intepreted any further), wstring (a std::wstring, the value is a generic wide string, parsed using the system environment locale), hms, ymd, ymd_interval (x::hms, x::ymd, and x::ymd::interval classes), uri (a x::uriimpl object), memsize (a x::memsize object that represents a numeric memory or file size value that gets specified as a basic human-readable string, like 10 Mb.

list / can be specified for any of the above numerical types, and the narrow and the wide string type. This declares an option list of the given type, see option reference for more information.

Anything other type gets interpreted as a custom class. The custom class needs to be defined as follows:

/* In the XML file: */

    <descr>A custom option</descr>

/* In the source file: */

#include <x/value_stringable.H>

class customOptClass {


	std::string s;
        static const x::stringable_t stringable=x::class_tostring;

	template<typename InputIterator>
	static customOptClass fromString(InputIterator beg_iter,
					 InputIterator end_iter,
					 const x::const_locale &localeArg)
		customOptClass c;

		std::copy(beg_iter, end_iter,
		return c;

	template<typename OutputIterator>
	OutputIterator toString(OutputIterator iter,
				const x::const_locale &localeRef)
		return (std::copy(s.begin(), s.end(), iter));

#include "testoptions.h"

int main(int argc, char **argv)
    testoptions opts;

    std::list<std::string> args(opts.parse(argc, argv)->args);

    if (opts.custom->isSet())
        /* opts.custom->value is a customOptClass */


The custom class must support the requirements of the x::value_string template. Briefly: the custom class must define a static fromString template that takes a beginning and an ending input iterator over a character sequence, a locale object, and returns an instance of the custom class; and a toString class template that takes an output iterator for a character sequence, a locale object, and converts the class to a string form, the opposite of fromString(). The class must also declare the stringable static constant member, as in the example above.

The class has the option of implementing fromWideString() and toWideString(), and setting stringable to x::towstring, instead.

On top of these x::value_string requirements for custom classes, the custom class must also implement a default constructor, a copy constructor, and an assignment operator.