@ -68,6 +68,29 @@ class Convert2Struct<double,ObjectString>
double operator ( ) ( const ObjectString * q , bool * suc ) const { double d = 0 ; * suc = ( * suc ) & & str2double ( q - > Value ( ) , & d ) ; return d ; }
double operator ( ) ( const ObjectString * q , bool * suc ) const { double d = 0 ; * suc = ( * suc ) & & str2double ( q - > Value ( ) , & d ) ; return d ; }
} ;
} ;
// Converting Int or Real to bool
template < class O >
class Convert2Struct < bool , O >
{
public :
bool operator ( ) ( const O * q , bool * suc ) const { return q - > Value ( ) ! = 0 ; }
} ;
// Converting String to bool
template < >
class Convert2Struct < bool , ObjectString >
{
public :
bool operator ( ) ( const ObjectString * q , bool * suc ) const
{
std : : string v = q - > Value ( ) ;
tolower ( v ) ;
if ( " y " = = v | | " yes " = = v | | " on " = = v | | " t " = = v | | " true " = = v | | " 1 " = = v ) return true ;
if ( " n " = = v | | " no " = = v | | " off " = = v | | " f " = = v | | " false " = = v | | " 0 " = = v ) return false ;
* suc = false ;
return false ;
}
} ;
// Get string
// Get string
template < >
template < >
class Convert2Struct < std : : string , ObjectString >
class Convert2Struct < std : : string , ObjectString >
@ -76,6 +99,14 @@ class Convert2Struct<std::string,ObjectString>
std : : string operator ( ) ( const ObjectString * q , bool * suc ) const { return q - > Value ( ) ; }
std : : string operator ( ) ( const ObjectString * q , bool * suc ) const { return q - > Value ( ) ; }
} ;
} ;
// This class search parameter with specified names in the list, which may be converted to Struct.
// If SearchByType is true, additionaly search unnamed parameter of corresponding Object class (ObjectGMTClass<Struct> for gmt_struct-derived types, for example).
// Additionally, Policies can be used to check correctness of found parameter.
template < class Struct , bool SearchByType = true , class . . . Policies >
class SearchParameter ;
template < class Struct , bool SearchByType = true , class . . . Policies >
class SearchParameterWDef ;
// Generic type storage class
// Generic type storage class
template < class Struct , class . . . Types >
template < class Struct , class . . . Types >
class gTypeStorage
class gTypeStorage
@ -83,6 +114,10 @@ class gTypeStorage
template < class O > class Convertor : public Convert2Struct < Struct , O > { } ; // Conversion type
template < class O > class Convertor : public Convert2Struct < Struct , O > { } ; // Conversion type
public :
public :
typedef Base2Something < Convertor , Types . . . > Base2Type ;
typedef Base2Something < Convertor , Types . . . > Base2Type ;
typedef SearchParameter < Struct , false > BaseM2Type ;
typedef SearchParameter < Struct , true > BaseMT2Type ;
typedef SearchParameterWDef < Struct , false > BaseMD2Type ;
typedef SearchParameterWDef < Struct , true > BaseMTD2Type ;
} ;
} ;
// Specific type storage class
// Specific type storage class
template < class Struct >
template < class Struct >
@ -127,15 +162,18 @@ struct SearchHelper<Struct,true>
}
}
} ;
} ;
// This class search parameter with specified names in the list, which may be converted to Struct.
// Definition without policies
// If Struct is derived from gmt_struct, additionaly search unnamed parameter of type ObjectGMTClass<Struct>
template < class Struct , bool SearchByType >
template < class Struct >
class SearchParameter < Struct , SearchByType >
class SearchParameter
{
{
typedef typename TypeStorage < Struct > : : Base2Type Base2Struct ;
protected :
bool exist ; // There is at least one parameter with given names
bool exist ; // There is at least one parameter with given names
bool ok ; // True if conversion to corresponding structure was successful and there is only one parameter with given names
bool ok ; // True if conversion to corresponding structure was successful and there is only one parameter with given names
Struct val ;
Struct val ;
typedef typename TypeStorage < Struct > : : Base2Type Base2Struct ;
SearchParameter ( ) = delete ;
SearchParameter ( SearchParameter & & ) = delete ;
SearchParameter ( SearchParameter & ) = delete ;
public :
public :
// Recursive constructor
// Recursive constructor
template < class . . . Args >
template < class . . . Args >
@ -154,7 +192,17 @@ class SearchParameter
}
}
}
}
// Bottom of recursion
// Bottom of recursion
SearchParameter ( const ObjectList * input ) : exist ( false ) , ok ( true ) { SearchHelper < Struct , std : : is_base_of < gmt_struct , Struct > : : value > ( ) ( input , & val , & exist , & ok ) ; }
SearchParameter ( const ObjectList * input ) : exist ( false ) , ok ( true ) { SearchHelper < Struct , SearchByType > ( ) ( input , & val , & exist , & ok ) ; }
// Search by index
SearchParameter ( const ObjectList * input , const ObjectList : : ListValues : : size_type i ) : exist ( false ) , ok ( true )
{
Base2Struct a ( input , i ) ;
if ( a . Exist ( ) )
{
exist = true ;
val = a ( & ok ) ;
}
}
Struct operator ( ) ( bool * suc ) const
Struct operator ( ) ( bool * suc ) const
{
{
if ( ! ok | | ! exist ) * suc = false ;
if ( ! ok | | ! exist ) * suc = false ;
@ -169,101 +217,159 @@ class SearchParameter
bool Exist ( ) const { return exist ; }
bool Exist ( ) const { return exist ; }
} ;
} ;
// Definitions for double
// Definition with policies
template < > class TypeStorage < double > : public gTypeStorage < double , ObjectReal , ObjectInt , ObjectString > { } ;
template < class Struct , bool SearchByType , class Policy , class . . . Policies >
typedef TypeStorage < double > : : Base2Type Base2Double ; // Copy definition to global namespace
class SearchParameter < Struct , SearchByType , Policy , Policies . . . > : public SearchParameter < Struct , SearchByType , Policies . . . >
// Definitions for string
template < > class TypeStorage < std : : string > : public gTypeStorage < std : : string , ObjectString > { } ;
typedef TypeStorage < std : : string > : : Base2Type Base2String ; // Copy definition to global namespace
// This source using Base2Double to get value of parameter. If parameter not exist, fallback to default value.
// Default value can be setted as template parameter or as parameter of constructor.
// We use rational representation of floating point number, because double type values not allowed as template parameter
template < int32_t num = 0 , uint32_t denum = 1 >
class SourceDefaultVal : public Base2Double
{
{
double defval ;
SearchParameter ( ) = delete ;
SearchParameter ( SearchParameter & & ) = delete ;
SearchParameter ( SearchParameter & ) = delete ;
public :
public :
// Constructors without default value
using SearchParameter < Struct , SearchByType , Policies . . . > : : ok ;
SourceDefaultVal ( const ObjectBase * arg ) : Base2Double ( arg ) , defval ( static_cast < double > ( num ) / denum ) { } ;
using SearchParameter < Struct , SearchByType , Policies . . . > : : exist ;
SourceDefaultVal ( const ObjectList * input , const std : : string & name ) : Base2Double ( input , name ) , defval ( static_cast < double > ( num ) / denum ) { } ;
// Recursive constructor
SourceDefaultVal ( const ObjectList * input , const ObjectList : : ListValues : : size_type i ) : Base2Double ( input , i ) , defval ( static_cast < double > ( num ) / denum ) { } ;
template < class . . . Args >
// Constructors with default value
SearchParameter ( const ObjectList * input , Args . . . args ) : SearchParameter < Struct , SearchByType , Policies . . . > ( input , args . . . ) { }
SourceDefaultVal ( const ObjectBase * arg , double d ) : Base2Double ( arg ) , defval ( d ) { } ;
Struct operator ( ) ( bool * suc ) const
SourceDefaultVal ( const ObjectList * input , const std : : string & name , double d ) : Base2Double ( input , name ) , defval ( d ) { } ;
SourceDefaultVal ( const ObjectList * input , const ObjectList : : ListValues : : size_type i , double d ) : Base2Double ( input , i ) , defval ( d ) { } ;
double operator ( ) ( bool * suc ) const
{
{
if ( Exist ( ) ) return Base2Double : : operator ( ) ( suc ) ;
return Policy ( ) ( SearchParameter < Struct , SearchByType , Policies . . . > : : operator ( ) ( suc ) , suc ) ;
else return defval ;
}
Struct operator ( ) ( bool * ex , bool * suc ) const
{
return Policy ( ) ( SearchParameter < Struct , SearchByType , Policies . . . > : : operator ( ) ( suc ) , suc ) ;
}
}
} ;
} ;
// This source try to get value of named parameter from list, which may have different names. Only one name must be in list.
// SearchParameter with default value
template < class Struct >
template < class Struct , bool SearchByType , class . . . Policies >
class SourceMultiInputNames
class SearchParameterWDef : protected SearchParameter < Struct , SearchByType , Policies . . . >
{
{
bool exist ; // There is at least one parameter with given names
typedef SearchParameter < Struct , SearchByType , Policies . . . > SP ;
bool ok ; // True if conversion to Struct was successful and there is only one parameter with given names
SearchParameterWDef ( ) = delete ;
Struct val ;
SearchParameterWDef ( SearchParameterWDef & & ) = delete ;
typedef typename TypeStorage < Struct > : : Base2Type Base2Struct ;
SearchParameterWDef ( SearchParameterWDef & ) = delete ;
public :
public :
// Recursive constructor
template < class . . . Args >
template < class . . . Args >
SourceMultiInputNames ( const ObjectList * input , const std : : string & name , Args . . . args ) : SourceMultiInputNames ( input , args . . . )
SearchParameterWDef ( const ObjectList * input , const Struct & def , Args . . . args ) : SP ( input , args . . . )
{
Base2Struct a ( input , name ) ;
if ( exist & & a . Exist ( ) ) ok = false ;
else if ( a . Exist ( ) )
{
exist = true ;
ok = true ;
val = a ( & ok ) ;
}
}
// Bottom of recursion
SourceMultiInputNames ( const ObjectList * input , const std : : string & name )
{
{
Base2Struct a ( input , name ) ;
if ( ! SP : : exist ) SP : : val = def ;
exist = a . Exist ( ) ;
SP : : exist = true ;
ok = true ;
if ( exist ) val = a ( & ok ) ;
}
}
Struct operator ( ) ( bool * suc ) const
Struct operator ( ) ( bool * suc ) const { return SP : : operator ( ) ( suc ) ; }
Struct operator ( ) ( bool * ex , bool * suc ) const { return SP : : operator ( ) ( ex , suc ) ; }
bool Exist ( ) const { return true ; }
} ;
// SearchParameter with default value setted as class
template < class Struct , class DefClass , bool SearchByType = false , class . . . Policies >
class SearchParameterWDefO : protected SearchParameter < Struct , SearchByType , Policies . . . >
{
typedef SearchParameter < Struct , SearchByType , Policies . . . > SP ;
SearchParameterWDefO ( ) = delete ;
SearchParameterWDefO ( SearchParameterWDefO & & ) = delete ;
SearchParameterWDefO ( SearchParameterWDefO & ) = delete ;
public :
template < class . . . Args >
SearchParameterWDefO ( const ObjectList * input , Args . . . args ) : SP ( input , args . . . )
{
{
if ( ! ok | | ! exist ) * suc = false ;
if ( ! SP : : exist ) SP : : val = DefClass ( ) ( ) ;
return val ;
SP : : exist = true ;
}
}
bool Exist ( ) const { return exist ; }
Struct operator ( ) ( bool * suc ) const { return SP : : operator ( ) ( suc ) ; }
Struct operator ( ) ( bool * ex , bool * suc ) const { return SP : : operator ( ) ( ex , suc ) ; }
bool Exist ( ) const { return true ; }
} ;
} ;
// Simple type for multiple input names
// Class for default double value
typedef GetDouble < SourceMultiInputNames < double > > BaseM2Double ;
// We use rational representation of floating point number, because double type values not allowed as template parameter
template < int32_t num = 0 , uint32_t denum = 1 >
class DoubleDefaultVal
{
DoubleDefaultVal ( DoubleDefaultVal & & ) = delete ;
DoubleDefaultVal ( DoubleDefaultVal & ) = delete ;
public :
DoubleDefaultVal ( ) { } ;
double operator ( ) ( ) const { return static_cast < double > ( num ) / denum ; }
} ;
// Definitions for double
template < > class TypeStorage < double > : public gTypeStorage < double , ObjectReal , ObjectInt , ObjectString > { } ;
typedef TypeStorage < double > : : Base2Type Base2Double ;
typedef TypeStorage < double > : : BaseM2Type BaseM2Double ;
typedef TypeStorage < double > : : BaseMT2Type BaseMT2Double ;
typedef TypeStorage < double > : : BaseMD2Type BaseMD2Double ;
typedef TypeStorage < double > : : BaseMTD2Type BaseMTD2Double ;
// Definitions for bool
template < > class TypeStorage < bool > : public gTypeStorage < bool , ObjectInt , ObjectReal , ObjectString > { } ;
typedef TypeStorage < bool > : : Base2Type Base2Bool ;
typedef TypeStorage < bool > : : BaseM2Type BaseM2Bool ;
typedef TypeStorage < bool > : : BaseMT2Type BaseMT2Bool ;
typedef TypeStorage < bool > : : BaseMD2Type BaseMD2Bool ;
typedef TypeStorage < bool > : : BaseMTD2Type BaseMTD2Bool ;
// Definitions for string
template < > class TypeStorage < std : : string > : public gTypeStorage < std : : string , ObjectString > { } ;
typedef TypeStorage < std : : string > : : Base2Type Base2String ;
typedef TypeStorage < std : : string > : : BaseM2Type BaseM2String ;
typedef TypeStorage < std : : string > : : BaseMT2Type BaseMT2String ;
typedef TypeStorage < std : : string > : : BaseMD2Type BaseMD2String ;
typedef TypeStorage < std : : string > : : BaseMTD2Type BaseMTD2String ;
// Definitions for ObjectGMTCoord
// Definitions for ObjectGMTCoord
template < > class TypeStorage < struct gmt_coord > : public gTypeStorage < struct gmt_coord , ObjectReal , ObjectInt , ObjectString , ObjectGMTCoord , ObjectList > { } ;
template < > class TypeStorage < struct gmt_coord > : public gTypeStorage < struct gmt_coord , ObjectReal , ObjectInt , ObjectString , ObjectGMTCoord , ObjectList > { } ;
typedef TypeStorage < struct gmt_coord > : : Base2Type Base2Coord ;
typedef TypeStorage < struct gmt_coord > : : Base2Type Base2Coord ;
typedef TypeStorage < struct gmt_coord > : : BaseM2Type BaseM2Coord ;
typedef TypeStorage < struct gmt_coord > : : BaseMT2Type BaseMT2Coord ;
typedef TypeStorage < struct gmt_coord > : : BaseMD2Type BaseMD2Coord ;
typedef TypeStorage < struct gmt_coord > : : BaseMTD2Type BaseMTD2Coord ;
// Definitions for ObjectGMTRegion
// Definitions for ObjectGMTRegion
template < > class TypeStorage < struct gmt_region > : public gTypeStorage < struct gmt_region , ObjectList , ObjectString , ObjectGMTRegion > { } ;
template < > class TypeStorage < struct gmt_region > : public gTypeStorage < struct gmt_region , ObjectList , ObjectString , ObjectGMTRegion > { } ;
typedef TypeStorage < struct gmt_region > : : Base2Type Base2Region ;
typedef TypeStorage < struct gmt_region > : : Base2Type Base2Region ;
typedef TypeStorage < struct gmt_region > : : BaseM2Type BaseM2Region ;
typedef TypeStorage < struct gmt_region > : : BaseMT2Type BaseMT2Region ;
typedef TypeStorage < struct gmt_region > : : BaseMD2Type BaseMD2Region ;
typedef TypeStorage < struct gmt_region > : : BaseMTD2Type BaseMTD2Region ;
// Definitions for ObjectGMTProjection
// Definitions for ObjectGMTProjection
template < > class TypeStorage < struct gmt_projection > : public gTypeStorage < struct gmt_projection , ObjectList , ObjectGMTProjection > { } ;
template < > class TypeStorage < struct gmt_projection > : public gTypeStorage < struct gmt_projection , ObjectList , ObjectGMTProjection > { } ;
typedef TypeStorage < struct gmt_projection > : : Base2Type Base2Projection ;
typedef TypeStorage < struct gmt_projection > : : Base2Type Base2Projection ;
typedef TypeStorage < struct gmt_projection > : : BaseM2Type BaseM2Projection ;
typedef TypeStorage < struct gmt_projection > : : BaseMT2Type BaseMT2Projection ;
typedef TypeStorage < struct gmt_projection > : : BaseMD2Type BaseMD2Projection ;
typedef TypeStorage < struct gmt_projection > : : BaseMTD2Type BaseMTD2Projection ;
// Definitions for ObjectGMTColor
// Definitions for ObjectGMTColor
template < > class TypeStorage < struct gmt_color > : public gTypeStorage < struct gmt_color , ObjectList , ObjectString , ObjectReal , ObjectInt , ObjectGMTColor > { } ;
template < > class TypeStorage < struct gmt_color > : public gTypeStorage < struct gmt_color , ObjectList , ObjectString , ObjectReal , ObjectInt , ObjectGMTColor > { } ;
typedef TypeStorage < struct gmt_color > : : Base2Type Base2Color ;
typedef TypeStorage < struct gmt_color > : : Base2Type Base2Color ;
typedef TypeStorage < struct gmt_color > : : BaseM2Type BaseM2Color ;
typedef TypeStorage < struct gmt_color > : : BaseMT2Type BaseMT2Color ;
typedef TypeStorage < struct gmt_color > : : BaseMD2Type BaseMD2Color ;
typedef TypeStorage < struct gmt_color > : : BaseMTD2Type BaseMTD2Color ;
// Definitions for ObjectGMTDash
// Definitions for ObjectGMTDash
template < > class TypeStorage < struct gmt_dash > : public gTypeStorage < struct gmt_dash , ObjectString , ObjectGMTDash > { } ;
template < > class TypeStorage < struct gmt_dash > : public gTypeStorage < struct gmt_dash , ObjectString , ObjectGMTDash > { } ;
typedef TypeStorage < struct gmt_dash > : : Base2Type Base2Dash ;
typedef TypeStorage < struct gmt_dash > : : Base2Type Base2Dash ;
typedef TypeStorage < struct gmt_dash > : : BaseM2Type BaseM2Dash ;
typedef TypeStorage < struct gmt_dash > : : BaseMT2Type BaseMT2Dash ;
typedef TypeStorage < struct gmt_dash > : : BaseMD2Type BaseMD2Dash ;
typedef TypeStorage < struct gmt_dash > : : BaseMTD2Type BaseMTD2Dash ;
// Definitions for ObjectGMTPen
// Definitions for ObjectGMTPen
template < > class TypeStorage < struct gmt_pen > : public gTypeStorage < struct gmt_pen , ObjectList , ObjectString , ObjectReal , ObjectInt , ObjectGMTPen > { } ;
template < > class TypeStorage < struct gmt_pen > : public gTypeStorage < struct gmt_pen , ObjectList , ObjectString , ObjectReal , ObjectInt , ObjectGMTPen > { } ;
typedef TypeStorage < struct gmt_pen > : : Base2Type Base2Pen ;
typedef TypeStorage < struct gmt_pen > : : Base2Type Base2Pen ;
typedef TypeStorage < struct gmt_pen > : : BaseM2Type BaseM2Pen ;
typedef TypeStorage < struct gmt_pen > : : BaseMT2Type BaseMT2Pen ;
typedef TypeStorage < struct gmt_pen > : : BaseMD2Type BaseMD2Pen ;
typedef TypeStorage < struct gmt_pen > : : BaseMTD2Type BaseMTD2Pen ;
// Definitions for ObjectGMTFont
// Definitions for ObjectGMTFont
template < > class TypeStorage < struct gmt_font > : public gTypeStorage < struct gmt_font , ObjectList , ObjectString , ObjectReal , ObjectInt , ObjectGMTFont > { } ;
template < > class TypeStorage < struct gmt_font > : public gTypeStorage < struct gmt_font , ObjectList , ObjectString , ObjectReal , ObjectInt , ObjectGMTFont > { } ;
typedef TypeStorage < struct gmt_font > : : Base2Type Base2Font ;
typedef TypeStorage < struct gmt_font > : : Base2Type Base2Font ;
typedef TypeStorage < struct gmt_font > : : BaseM2Type BaseM2Font ;
typedef TypeStorage < struct gmt_font > : : BaseMT2Type BaseMT2Font ;
typedef TypeStorage < struct gmt_font > : : BaseMD2Type BaseMD2Font ;
typedef TypeStorage < struct gmt_font > : : BaseMTD2Type BaseMTD2Font ;
// Definitions for ObjectGMTLayer
// Definitions for ObjectGMTLayer
template < > class TypeStorage < struct gmt_layer > : public gTypeStorage < struct gmt_layer , ObjectList , ObjectGMTLayer > { } ;
template < > class TypeStorage < struct gmt_layer > : public gTypeStorage < struct gmt_layer , ObjectList , ObjectGMTLayer > { } ;
typedef TypeStorage < struct gmt_layer > : : Base2Type Base2Layer ;
typedef TypeStorage < struct gmt_layer > : : Base2Type Base2Layer ;
typedef TypeStorage < struct gmt_layer > : : BaseM2Type BaseM2Layer ;
typedef TypeStorage < struct gmt_layer > : : BaseMT2Type BaseMT2Layer ;
typedef TypeStorage < struct gmt_layer > : : BaseMD2Type BaseMD2Layer ;
typedef TypeStorage < struct gmt_layer > : : BaseMTD2Type BaseMTD2Layer ;
// Conversion from List to GMTRegion
// Conversion from List to GMTRegion
/*
/*
@ -284,11 +390,11 @@ class Convert2Struct<struct gmt_region, ObjectList>
{
{
struct gmt_region r ;
struct gmt_region r ;
auto size = input - > Size ( ) ;
auto size = input - > Size ( ) ;
bool suc = true ;
if ( 1 = = size ) // Cases 1, 2 and 3
if ( 1 = = size ) // Cases 1, 2 and 3
{
{
Base2Region region ( input , 0 ) ;
Base2Region region ( input , 0 ) ;
bool suc = true ;
r = region ( & suc ) ;
r = region ( & suc ) ;
if ( ! suc ) goto fail ; // Conversion failed
if ( ! suc ) goto fail ; // Conversion failed
return r ;
return r ;
@ -296,30 +402,39 @@ class Convert2Struct<struct gmt_region, ObjectList>
// Case 4
// Case 4
{
{
OBType < ObjectString > type ( input - > Get ( " type " ) ) ;
std : : string type ;
if ( type & & r . Convert ( type - > Value ( ) ) ) return r ; // type is one of "global*" string, we can return, becuse upd is irrelevant
bool typeexist = false ;
{
Base2String t ( input , " type " ) ;
if ( t . Exist ( ) )
{
type = t ( & suc ) ;
tolower ( type ) ;
if ( ! suc ) goto fail ; // Conversion failed
typeexist = true ;
}
else type = " nobbox " ;
}
if ( r . Convert ( type ) ) return r ; // type is one of "global*" string, we can return, becuse upd is irrelevant
bool upd ;
bool upd ;
{
{
SearchParameter < struct gmt_region > updarg ( input , " r " , " region " ) ;
BaseMT2Region updarg ( input , " r " , " region " ) ;
bool suc = true ;
r = updarg ( & upd , & suc ) ;
r = updarg ( & upd , & suc ) ;
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
suc = true ;
}
}
Base2Coord ixb ( input , " xb " ) , ixe ( input , " xe " ) , iyb ( input , " yb " ) , iye ( input , " ye " ) ;
Base2Coord ixb ( input , " xb " ) , ixe ( input , " xe " ) , iyb ( input , " yb " ) , iye ( input , " ye " ) ;
if ( ! ( type . Exist ( ) | | ixb . Exist ( ) | | ixe . Exist ( ) | | iyb . Exist ( ) | | iye . Exist ( ) | | upd ) ) goto case5 ; // No named parameters, no update mode, possibly case 5
if ( ! ( typeexist | | ixb . Exist ( ) | | ixe . Exist ( ) | | iyb . Exist ( ) | | iye . Exist ( ) | | upd ) ) goto case5 ; // No named parameters, no update mode, possibly case 5
bool suc = true ;
struct gmt_coord xb , yb , xe , ye ;
struct gmt_coord xb , yb , xe , ye ;
bool isbbox = upd ? ( gmt_region : : BBOX = = r . type ) : false ;
bool isbbox = upd ? ( gmt_region : : BBOX = = r . type ) : false ;
if ( type )
if ( typeexist )
{
{
std : : string s = type - > Value ( ) ;
if ( " bbox " = = type ) isbbox = true ;
tolower ( s ) ;
if ( " nobbox " = = type ) isbbox = false ;
if ( " bbox " = = s ) isbbox = true ;
if ( " bbox " ! = type & & " nobbox " ! = type ) goto fail ; // Unknown type
if ( " nobbox " = = s ) isbbox = false ;
if ( " bbox " ! = s & & " nobbox " ! = s ) goto fail ; // Unknown type
}
}
if ( upd )
if ( upd )
@ -329,7 +444,7 @@ class Convert2Struct<struct gmt_region, ObjectList>
if ( ! iyb . Exist ( ) ) yb = r . yb ;
if ( ! iyb . Exist ( ) ) yb = r . yb ;
if ( ! iye . Exist ( ) ) ye = r . ye ;
if ( ! iye . Exist ( ) ) ye = r . ye ;
}
}
else suc = suc & & ixb & & ixe & & iyb & & iye ; // In "new" mode all parameters must exists and have correct type
else suc = suc & & ixb . Exist ( ) & & ixe . Exist ( ) & & iyb . Exist ( ) & & iye . Exist ( ) ; // In "new" mode all parameters must exists
if ( ixb . Exist ( ) ) xb = ixb ( & suc ) ;
if ( ixb . Exist ( ) ) xb = ixb ( & suc ) ;
if ( ixe . Exist ( ) ) xe = ixe ( & suc ) ;
if ( ixe . Exist ( ) ) xe = ixe ( & suc ) ;
if ( iyb . Exist ( ) ) yb = iyb ( & suc ) ;
if ( iyb . Exist ( ) ) yb = iyb ( & suc ) ;
@ -346,17 +461,16 @@ class Convert2Struct<struct gmt_region, ObjectList>
bool isbbox = false ;
bool isbbox = false ;
if ( 5 = = size )
if ( 5 = = size )
{
{
OBType < ObjectString > type ( input - > At ( 4 ) ) ;
Base2String type ( input , 4 ) ;
if ( ! type ) goto fail ; // Unknown fifth parameter
std : : string str = type ( & suc ) ;
std : : string str = type - > Value ( ) ;
if ( ! suc ) goto fail ; // Wrong parameter
tolower ( str ) ;
tolower ( str ) ;
if ( " bbox " ! = str | | " nobbox " ! = str ) goto fail ; // Unknown fifth parameter
if ( " bbox " ! = str | | " nobbox " ! = str ) goto fail ; // Unknown fifth parameter
if ( " bbox " = = str ) isbbox = true ;
if ( " bbox " = = str ) isbbox = true ;
}
}
Base2Coord ixb ( input , 0 ) , ixe ( input , ( isbbox ? 2 : 1 ) ) , iyb ( input , ( isbbox ? 1 : 2 ) ) , iye ( input , 3 ) ;
Base2Coord ixb ( input , 0 ) , ixe ( input , ( isbbox ? 2 : 1 ) ) , iyb ( input , ( isbbox ? 1 : 2 ) ) , iye ( input , 3 ) ;
bool suc = true ;
struct gmt_coord xb = ixb ( & suc ) , yb = iyb ( & suc ) , xe = ixe ( & suc ) , ye = iye ( & suc ) ;
struct gmt_coord xb = ixb ( & suc ) , yb = iyb ( & suc ) , xe = ixe ( & suc ) , ye = iye ( & suc ) ;
if ( ixb & & ixe & & iyb & & iye & & suc )
if ( suc )
{
{
if ( ! r . Convert ( xb , xe , yb , ye , isbbox ) ) goto fail ; // Conversion failed
if ( ! r . Convert ( xb , xe , yb , ye , isbbox ) ) goto fail ; // Conversion failed
return r ; // Case 4 with all parameters
return r ; // Case 4 with all parameters
@ -390,9 +504,10 @@ class Convert2Struct<struct gmt_projection, ObjectList>
public :
public :
struct gmt_projection operator ( ) ( const ObjectList * input , bool * issuc ) const
struct gmt_projection operator ( ) ( const ObjectList * input , bool * issuc ) const
{
{
typedef GetDouble < SourceMultiInputNames < double > , PMin < 0 > > BaseM2Nonneg ;
typedef SearchParameter < double , false , PMin < 0 > > BaseM2Nonneg ;
struct gmt_projection p ;
struct gmt_projection p ;
auto size = input - > Size ( ) ;
auto size = input - > Size ( ) ;
bool suc = true ;
if ( 1 = = size ) // Cases 1, and 2
if ( 1 = = size ) // Cases 1, and 2
{
{
@ -408,18 +523,17 @@ class Convert2Struct<struct gmt_projection, ObjectList>
bool upd ;
bool upd ;
bool changetype = false ;
bool changetype = false ;
{
{
SearchParameter < struct gmt_projection > updarg ( input , " p " , " proj " , " projection " ) ;
BaseMT2Projection updarg ( input , " p " , " proj " , " projection " ) ;
bool suc = true ;
p = updarg ( & upd , & suc ) ;
p = updarg ( & upd , & suc ) ;
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
suc = true ;
}
}
// Try to set type of projection
// Try to set type of projection
{
{
SearchParameter < std : : string > type ( input , " t " , " type " , " projtype " ) ;
BaseM2String type ( input , " t " , " type " , " projtype " ) ;
if ( ! ( type . Exist ( ) | | upd ) ) goto case4 ; // No named parameter, not update mode, go to case 4
if ( ! ( type . Exist ( ) | | upd ) ) goto case4 ; // No named parameter, not update mode, go to case 4
// Check on redundant parameters
// Check on redundant parameters
bool suc = true ;
if ( type . Exist ( ) )
if ( type . Exist ( ) )
{
{
std : : string typestr = type ( & suc ) ;
std : : string typestr = type ( & suc ) ;
@ -431,9 +545,8 @@ class Convert2Struct<struct gmt_projection, ObjectList>
// We need the region
// We need the region
{
{
SearchParameter < struct gmt_region > region ( input , " r " , " region " ) ;
BaseMT2Region region ( input , " r " , " region " ) ;
if ( ! ( region . Exist ( ) | | upd ) ) goto fail ; // Region must be defined in "new" mode
if ( ! ( region . Exist ( ) | | upd ) ) goto fail ; // Region must be defined in "new" mode
bool suc = true ;
if ( region . Exist ( ) ) p . region = region ( & suc ) ;
if ( region . Exist ( ) ) p . region = region ( & suc ) ;
if ( ! suc ) goto fail ; // Conversion failed
if ( ! suc ) goto fail ; // Conversion failed
}
}
@ -914,17 +1027,17 @@ class Convert2Struct<struct gmt_projection, ObjectList>
} ;
} ;
// Helper types
// Helper types
typedef GetDouble < Sourc eDefaultVal< > , PMin < 0 > , PMax < 255 > > Base2RGB ;
typedef SearchParameterWDefO < double , Doubl eDefaultVal< > , false , PMin < 0 > , PMax < 255 > > Base2RGB ;
typedef GetDouble < Sourc eDefaultVal< > , PMin < 0 > , PMax < 360 > > Base2Hue ;
typedef SearchParameterWDefO < double , Doubl eDefaultVal< > , false , PMin < 0 > , PMax < 360 > > Base2Hue ;
typedef GetDouble < Sourc eDefaultVal< > , PMin < 0 > , PMax < 1 > > Base2SV ;
typedef SearchParameterWDefO < double , Doubl eDefaultVal< > , false , PMin < 0 > , PMax < 1 > > Base2SV ;
typedef GetDouble < Sourc eDefaultVal< > , PMin < 0 > , PMax < 100 > > Base2CMYK ;
typedef SearchParameterWDefO < double , Doubl eDefaultVal< > , false , PMin < 0 > , PMax < 100 > > Base2CMYK ;
typedef GetDouble < Sourc eDefaultVal< > , PMin < 0 > , PMax < 100 > > Base2Transp ;
typedef SearchParameterWDefO < double , Doubl eDefaultVal< > , false , PMin < 0 > , PMax < 100 > > Base2Transp ;
typedef GetDouble < SourceMultiInputNames < double > , PMin < 0 > , PMax < 255 > > BaseM2RGB ;
typedef SearchParameter < double , false , PMin < 0 > , PMax < 255 > > BaseM2RGB ;
typedef GetDouble < SourceMultiInputNames < double > , PMin < 0 > , PMax < 360 > > BaseM2Hue ;
typedef SearchParameter < double , false , PMin < 0 > , PMax < 360 > > BaseM2Hue ;
typedef GetDouble < SourceMultiInputNames < double > , PMin < 0 > , PMax < 1 > > BaseM2SV ;
typedef SearchParameter < double , false , PMin < 0 > , PMax < 1 > > BaseM2SV ;
typedef GetDouble < SourceMultiInputNames < double > , PMin < 0 > , PMax < 100 > > BaseM2CMYK ;
typedef SearchParameter < double , false , PMin < 0 > , PMax < 100 > > BaseM2CMYK ;
typedef GetDouble < SourceMultiInputNames < double > , PMin < 0 > , PMax < 100 > > BaseM2Transp ;
typedef SearchParameter < double , false , PMin < 0 > , PMax < 100 > > BaseM2Transp ;
// Converting List to GMTColor
// Converting List to GMTColor
/*
/*
@ -964,7 +1077,7 @@ class Convert2Struct<struct gmt_color, ObjectList>
bool cmodset = false ;
bool cmodset = false ;
bool upd ;
bool upd ;
{
{
SearchParameter < struct gmt_color > updarg ( input , " color " ) ;
BaseMT2Color updarg ( input , " color " ) ;
bool suc = true ;
bool suc = true ;
c = updarg ( & upd , & suc ) ;
c = updarg ( & upd , & suc ) ;
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
@ -1059,14 +1172,10 @@ class Convert2Struct<struct gmt_color, ObjectList>
Base2RGB r ( input , 0 ) , g ( input , 1 ) , b ( input , 2 ) ;
Base2RGB r ( input , 0 ) , g ( input , 1 ) , b ( input , 2 ) ;
c . model = gmt_color : : RGB ;
c . model = gmt_color : : RGB ;
bool suc = true ;
bool suc = true ;
if ( r & & g & & b )
c . r = r ( & suc ) ;
{
c . g = g ( & suc ) ;
c . r = r ( & suc ) ;
c . b = b ( & suc ) ;
c . g = g ( & suc ) ;
if ( ! suc ) goto fail ; // Parsing error
c . b = b ( & suc ) ;
if ( ! suc ) goto fail ; // Parsing error
}
else goto fail ; // Something wrong
return c ;
return c ;
}
}
@ -1076,15 +1185,11 @@ class Convert2Struct<struct gmt_color, ObjectList>
Base2CMYK cc ( input , 0 ) , m ( input , 1 ) , y ( input , 2 ) , k ( input , 3 ) ;
Base2CMYK cc ( input , 0 ) , m ( input , 1 ) , y ( input , 2 ) , k ( input , 3 ) ;
c . model = gmt_color : : CMYK ;
c . model = gmt_color : : CMYK ;
bool suc = true ;
bool suc = true ;
if ( cc & & m & & y & & k )
c . cyan = cc ( & suc ) ;
{
c . magenta = m ( & suc ) ;
c . cyan = cc ( & suc ) ;
c . yellow = y ( & suc ) ;
c . magenta = m ( & suc ) ;
c . black = k ( & suc ) ;
c . yellow = y ( & suc ) ;
if ( ! suc ) goto fail ; // Parsing error
c . black = k ( & suc ) ;
if ( ! suc ) goto fail ; // Parsing error
}
else goto fail ; // Something wrong
return c ;
return c ;
}
}
@ -1095,8 +1200,8 @@ class Convert2Struct<struct gmt_color, ObjectList>
} ;
} ;
// Helper types
// Helper types
typedef GetDouble < Sourc eDefaultVal< > , PMin < 0 > > Base2Width ;
typedef SearchParameterWDefO < double , Doubl eDefaultVal< > , false , PMin < 0 > > Base2Width ;
typedef GetDouble < SourceMultiInputNames < double > , PMin < 0 > > BaseM2Width ;
typedef SearchParameter < double , false , PMin < 0 > > BaseM2Width ;
// Converting List to GMTPen
// Converting List to GMTPen
/*
/*
@ -1136,7 +1241,7 @@ class Convert2Struct<struct gmt_pen, ObjectList>
bool casevalid = false ;
bool casevalid = false ;
bool upd ;
bool upd ;
{
{
SearchParameter < struct gmt_pen > updarg ( input , " pen " , " p " ) ;
BaseMT2Pen updarg ( input , " pen " , " p " ) ;
bool suc = true ;
bool suc = true ;
p = updarg ( & upd , & suc ) ;
p = updarg ( & upd , & suc ) ;
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
@ -1163,7 +1268,7 @@ class Convert2Struct<struct gmt_pen, ObjectList>
// Color
// Color
{
{
SearchParameter < struct gmt_color > color ( input , " color " , " c " ) ;
BaseMT2Color color ( input , " color " , " c " ) ;
if ( color . Exist ( ) )
if ( color . Exist ( ) )
{
{
bool suc = true ;
bool suc = true ;
@ -1175,7 +1280,7 @@ class Convert2Struct<struct gmt_pen, ObjectList>
// Dash
// Dash
{
{
SearchParameter < struct gmt_dash > dash ( input , " dash " , " d " ) ;
BaseMT2Dash dash ( input , " dash " , " d " ) ;
if ( dash . Exist ( ) )
if ( dash . Exist ( ) )
{
{
bool suc = true ;
bool suc = true ;
@ -1196,13 +1301,10 @@ class Convert2Struct<struct gmt_pen, ObjectList>
Base2Color c ( input , 1 ) ;
Base2Color c ( input , 1 ) ;
Base2Dash d ( input , 2 ) ;
Base2Dash d ( input , 2 ) ;
bool suc = true ;
bool suc = true ;
if ( w & & c )
p . width = w ( & suc ) ;
{
p . color = c ( & suc ) ;
p . width = w ( & suc ) ;
if ( ! suc ) goto fail ; // Something wrong
p . color = c ( & suc ) ;
p . dash = d ( & suc , p . width ) ;
}
else goto fail ; // Something wrong
if ( d ) p . dash = d ( & suc , p . width ) ;
if ( ! suc ) goto fail ; // Something wrong
if ( ! suc ) goto fail ; // Something wrong
return p ;
return p ;
}
}
@ -1253,7 +1355,7 @@ class Convert2Struct<struct gmt_font, ObjectList>
bool casevalid = false ;
bool casevalid = false ;
bool upd ;
bool upd ;
{
{
SearchParameter < struct gmt_font > updarg ( input , " font " ) ;
BaseMT2Font updarg ( input , " font " ) ;
bool suc = true ;
bool suc = true ;
f = updarg ( & upd , & suc ) ;
f = updarg ( & upd , & suc ) ;
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
if ( upd & & ! suc ) goto fail ; // Conversion failed or too many arguments
@ -1281,7 +1383,7 @@ class Convert2Struct<struct gmt_font, ObjectList>
// Family
// Family
{
{
SearchParameter < std : : string > family ( input , " family " , " f " ) ;
BaseM2String family ( input , " family " , " f " ) ;
if ( family . Exist ( ) )
if ( family . Exist ( ) )
{
{
bool suc = true ;
bool suc = true ;
@ -1293,7 +1395,7 @@ class Convert2Struct<struct gmt_font, ObjectList>
// Color
// Color
{
{
SearchParameter < struct gmt_color > color ( input , " color " , " c " ) ;
BaseMT2Color color ( input , " color " , " c " ) ;
if ( color . Exist ( ) )
if ( color . Exist ( ) )
{
{
bool suc = true ;
bool suc = true ;
@ -1313,13 +1415,9 @@ class Convert2Struct<struct gmt_font, ObjectList>
Base2String fam ( input , 1 ) ;
Base2String fam ( input , 1 ) ;
Base2Color c ( input , 2 ) ;
Base2Color c ( input , 2 ) ;
bool suc = true ;
bool suc = true ;
if ( s & & fam )
f . size = s ( & suc ) ;
{
f . family = fam ( & suc ) ;
f . size = s ( & suc ) ;
f . color = c ( & suc ) ;
f . family = fam ( & suc ) ;
}
else goto fail ; // Something wrong
if ( c ) f . color = c ( & suc ) ;
if ( ! suc ) goto fail ; // Something wrong
if ( ! suc ) goto fail ; // Something wrong
return f ;
return f ;
}
}