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), 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 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: */

  <option>
    <name>custom</name>
    <type>customOptClass</type>
    <opt>c</opt>
    <descr>A custom option</descr>
  </option>

/* In the source file: */

#include <x/value_stringable.H>

class customOptClass {

public:

	std::string s;

        static const x::stringable_t stringable=x::class_tostring;

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

		std::copy(beg_iter, end_iter,
			  std::back_insert_iterator<std::string>(c.s));
		return c;
	}

	template<typename OutputIterator>
	OutputIterator to_string(OutputIterator iter,
				const x::const_locale &localeRef)
		const
	{
		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->is_set())
    {
        /* 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 from_string 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 to_string 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 from_string().

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.