Browse Source

Gmt module: Add possibility for ParsePositionalParameters to parse only part of list.

gmtdatadir
Michael Uleysky 8 years ago
parent
commit
218d8c0f00
  1. 18
      modules/gmt/modgmt_param.h

18
modules/gmt/modgmt_param.h

@ -128,7 +128,7 @@ class ParsePositionalParameters: public ParseParameters
// Main parsing function
template <class Par, class... Args>
void Parse(ObjectList::IndexType i, const ObjectList* ol, Par& param, Args&... args)
void Parse(ObjectList::IndexType i, ObjectList::IndexType max, const ObjectList* ol, Par& param, Args&... args)
{
// Check types of arguments
static_assert(std::is_same<PositionalParameter<typename Par::ConverterType, Par::optional>,Par>::value,"ParsePositionalParameters argument(s) must be PositionalParameter");
@ -141,10 +141,10 @@ class ParsePositionalParameters: public ParseParameters
}
// List is ended
if(i>=ol->Size())
if(i>=max)
{
// Parameter is optional, skip it
if(Par::optional) Parse(i,ol,args...);
if(Par::optional) Parse(i,max,ol,args...);
// Parameter is required, this is an error
else err="Parameter "+param.Name()+" is required, but can't be setted because list is ended";
}
@ -153,22 +153,24 @@ class ParsePositionalParameters: public ParseParameters
{
bool res=param.Init(ol->At(i),err);
// All Ok, continue to next element in list
if(res) Parse(i+1,ol,args...);
if(res) Parse(i+1,max,ol,args...);
else
{
// All Ok, optional parameter may be absent, try to initialise next parameter by same list element
if(Par::optional) Parse(i,ol,args...);
if(Par::optional) Parse(i,max,ol,args...);
// Error, required parameter not initialised
else err="Can't initialise parameter "+param.Name()+" from list element number "+ToString(i)+": "+err;
}
}
}
// Bottom of recursion
void Parse(ObjectList::IndexType i, const ObjectList* ol) {if(i<ol->Size()) err="There are excess elements in list";}
void Parse(ObjectList::IndexType i, ObjectList::IndexType max, const ObjectList* ol) {if(i<max) err="There are excess elements in list";}
public:
template <class... Args>
ParsePositionalParameters(const ObjectList* ol, Args&... args) {Parse(0,ol,args...);}
template <class Converter, bool optional, class... Args>
ParsePositionalParameters(const ObjectList* ol, PositionalParameter<Converter,optional>& p1, Args&... args) {Parse(0,ol->Size(),ol,p1,args...);}
template <class Converter, bool optional, class... Args>
ParsePositionalParameters(const ObjectList* ol, ObjectList::IndexType min, ObjectList::IndexType max, PositionalParameter<Converter,optional>& p1, Args&... args) {Parse(min,std::min(max,ol->Size()),ol,p1,args...);}
};

Loading…
Cancel
Save