From 218d8c0f003be930f839e6f00f6fef24a9d4dd1f Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Sat, 1 Oct 2016 22:03:24 +1000 Subject: [PATCH] Gmt module: Add possibility for ParsePositionalParameters to parse only part of list. --- modules/gmt/modgmt_param.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/gmt/modgmt_param.h b/modules/gmt/modgmt_param.h index 08adbaa..a80154f 100644 --- a/modules/gmt/modgmt_param.h +++ b/modules/gmt/modgmt_param.h @@ -128,7 +128,7 @@ class ParsePositionalParameters: public ParseParameters // Main parsing function template - 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,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(iSize()) err="There are excess elements in list";} + void Parse(ObjectList::IndexType i, ObjectList::IndexType max, const ObjectList* ol) {if(i - ParsePositionalParameters(const ObjectList* ol, Args&... args) {Parse(0,ol,args...);} + template + ParsePositionalParameters(const ObjectList* ol, PositionalParameter& p1, Args&... args) {Parse(0,ol->Size(),ol,p1,args...);} + template + ParsePositionalParameters(const ObjectList* ol, ObjectList::IndexType min, ObjectList::IndexType max, PositionalParameter& p1, Args&... args) {Parse(min,std::min(max,ol->Size()),ol,p1,args...);} };