43#ifndef LASS_GUARDIAN_OF_INCLUSION_IO_ARG_PARSER_INL
44#define LASS_GUARDIAN_OF_INCLUSION_IO_ARG_PARSER_INL
60 const std::string& iShortName,
61 const std::string& iLongName,
62 const std::string& iDescription,
64 ArgParameter(iParser, iShortName, iLongName, iArgMode),
65 description_(iDescription)
73ArgValue<T>::ArgValue(ArgParser& iParser,
74 const std::string& iShortName,
75 const std::string& iLongName,
76 const std::string& iDescription,
79 ArgParameter(iParser, iShortName, iLongName, iArgMode),
80 default_(1, iDefault),
81 description_(iDescription)
89ArgValue<T>::ArgValue(ArgParser& iParser,
90 const ArgFormat& iFormat):
91 ArgParameter(iParser, iFormat.shortName, iFormat.longName, iFormat.argMode),
92 description_(iFormat.description)
94 if (iFormat.hasDefault)
96 default_.push_back(util::stringCast<T>(iFormat.defaultValue));
98 checkMode(iFormat.argMode);
106const typename ArgValue<T>::TValues& ArgValue<T>::all()
const
108 return !values_.empty() ? values_ : default_;
116size_t ArgValue<T>::size()
const
126typename ArgValue<T>::TConstReference ArgValue<T>::operator[](
size_t iIndex)
const
128 LASS_ASSERT(iIndex < size());
129 return all()[iIndex];
137typename ArgValue<T>::TConstReference ArgValue<T>::at(
size_t iIndex)
const
139 return all().at(iIndex);
147typename ArgValue<T>::TValueIterator ArgValue<T>::begin()
const
149 return all().begin();
157typename ArgValue<T>::TValueIterator ArgValue<T>::end()
const
168void ArgValue<T>::checkMode(
int iArgMode)
const
170 if (iArgMode & amNoValue)
172 LASS_THROW(
"You can't set the mode 'amNoValue' for a ArgValue '" << names() <<
"'.");
175 const int field = iArgMode & mask;
176 if (field != amOptional && field != amRequired)
178 LASS_THROW(
"For a ArgValue '" << names() <<
"' you must choose between mode 'amOptional' "
179 <<
"or 'amRequired'. At least one of these must be set, but not both.");
186const std::string ArgValue<T>::doFormat()
const
188 LASS_ASSERT(!(mode() & amNoValue));
190 std::ostringstream result;
191 result <<
"[" << names() <<
" ";
193 if (mode() & amOptional)
197 result <<
"<" << (description_.empty() ?
"value" : description_) <<
">";
198 if (mode() & amMultiple)
202 if (mode() & amOptional)
214bool ArgValue<T>::doSetValue(
const std::string& iValue)
216 LASS_ASSERT(!(mode() & amNoValue));
220 if (mode() & amRequired)
222 if (!parserIsQuiet())
224 LASS_THROW_EX(ArgBadArgument,
225 "Bad program arguments: you didn't provide a value for the parameter '"
226 << names() <<
"' as required.\n");
235 if (values_.size() != 0 && !(mode() & amMultiple))
237 if (!parserIsQuiet())
239 LASS_THROW_EX(ArgBadArgument,
240 "Bad program arguments: parameter '" << names() <<
"' already has a value '"
241 << values_[0] <<
"' assigned, you can't assign another value '" << iValue
242 <<
"' because this parameter cannot be multiple valued.\n");
250 values_.push_back(util::stringCast<T>(iValue));
252 catch (
const util::BadStringCast&)
254 if (!parserIsQuiet())
256 LASS_THROW_EX(ArgBadArgument,
257 "Bad program arguments: could not interpret '" << iValue
258 <<
"' as a value of type '" <<
typeid(T).name()
259 <<
"' for parameter '" << names() <<
".\n");
@ amOptional
if argument is used, it can take a value, but is not required
@ amRequired
if argument is used, a value is required
streams, binary streams, vrmlstreams, ...
Library for Assembled Shared Sources.