|
|
@ -174,6 +174,8 @@ using Base2Coord =Base2Struct<struct gmt_coord>; |
|
|
|
using Base2Region=Base2Struct<struct gmt_region>; |
|
|
|
using Base2Region=Base2Struct<struct gmt_region>; |
|
|
|
using Base2Proj =Base2Struct<struct gmt_projection>; |
|
|
|
using Base2Proj =Base2Struct<struct gmt_projection>; |
|
|
|
using Base2Color =Base2Struct<struct gmt_color>; |
|
|
|
using Base2Color =Base2Struct<struct gmt_color>; |
|
|
|
|
|
|
|
using Base2Dash =Base2Struct<struct gmt_dash>; |
|
|
|
|
|
|
|
using Base2Pen =Base2Struct<struct gmt_pen>; |
|
|
|
|
|
|
|
|
|
|
|
// Simple aliases of convertors with default values
|
|
|
|
// Simple aliases of convertors with default values
|
|
|
|
using Base2StringD=Base2StructD<std::string>; |
|
|
|
using Base2StringD=Base2StructD<std::string>; |
|
|
@ -194,7 +196,37 @@ class Base2CoordD: public DefaultConverter<Base2Coord> |
|
|
|
Base2CoordD(double d):DefaultConverter<Base2Coord>(Def(d)) {} |
|
|
|
Base2CoordD(double d):DefaultConverter<Base2Coord>(Def(d)) {} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Convertors for double non-negative value
|
|
|
|
// Convertor with default value for gmt_color. Added constructor for creating default value from double argument
|
|
|
|
|
|
|
|
class Base2ColorD: public DefaultConverter<Base2Color> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
static ValueType Def(double d) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ValueType v; |
|
|
|
|
|
|
|
std::string fake; |
|
|
|
|
|
|
|
v.Convert(d,fake); |
|
|
|
|
|
|
|
return v; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
using ValueType=DefaultConverter<Base2Color>::ValueType; |
|
|
|
|
|
|
|
Base2ColorD(double d):DefaultConverter<Base2Color>(Def(d)) {} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convertor with default value for gmt_dash. Default value is always no dash.
|
|
|
|
|
|
|
|
class Base2DashD: public DefaultConverter<Base2Dash> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
static ValueType Def() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ValueType v; |
|
|
|
|
|
|
|
v.Clear(); |
|
|
|
|
|
|
|
return v; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
using ValueType=DefaultConverter<Base2Dash>::ValueType; |
|
|
|
|
|
|
|
Base2DashD():DefaultConverter<Base2Dash>(Def()) {} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convertors for double positive value
|
|
|
|
class Base2Pos: public Base2Double |
|
|
|
class Base2Pos: public Base2Double |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
@ -211,6 +243,23 @@ class Base2Pos: public Base2Double |
|
|
|
}; |
|
|
|
}; |
|
|
|
using Base2PosD=DefaultConverter<Base2Pos>; |
|
|
|
using Base2PosD=DefaultConverter<Base2Pos>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convertors for double non-negative value
|
|
|
|
|
|
|
|
class Base2NonNeg: public Base2Double |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
double Convert(const ObjectBase* ob, bool* res, std::string& err) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
double t=Base2Double::Convert(ob,res,err); |
|
|
|
|
|
|
|
if(res && t<0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
*res=false; |
|
|
|
|
|
|
|
err="Value mast be non-negative"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return t; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
using Base2NonNegD=DefaultConverter<Base2NonNeg>; |
|
|
|
|
|
|
|
|
|
|
|
// Convertors for double values which must be in some interval
|
|
|
|
// Convertors for double values which must be in some interval
|
|
|
|
template<int32_t Min, int32_t Max> |
|
|
|
template<int32_t Min, int32_t Max> |
|
|
|
class Base2InRange: public Base2Double |
|
|
|
class Base2InRange: public Base2Double |
|
|
@ -837,9 +886,6 @@ class Convert2Struct<struct gmt_color, ObjectList> |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Helper types
|
|
|
|
|
|
|
|
typedef SearchParameterWDefO<double,DoubleDefaultVal<>,false,PMin<0> > Base2Width; |
|
|
|
|
|
|
|
typedef SearchParameter<double,false,PMin<0> > BaseM2Width; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Converting List to GMTPen
|
|
|
|
// Converting List to GMTPen
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -860,91 +906,53 @@ class Convert2Struct<struct gmt_pen, ObjectList> |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
struct gmt_pen operator()(const ObjectList* input, bool* issuc) const |
|
|
|
struct gmt_pen operator()(const ObjectList* input, bool* issuc, std::string& err) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct gmt_pen p; |
|
|
|
struct gmt_pen p; |
|
|
|
auto size=input->Size(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(1==size) // Cases 1, 2 and 4
|
|
|
|
if(1==input->Size()) // Cases 1, 2 and 4
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Base2Pen pen(input,0); |
|
|
|
Base2Pen pen; |
|
|
|
bool suc=true; |
|
|
|
bool suc=true; |
|
|
|
p=pen(&suc); |
|
|
|
p=pen.Convert(input->At(0),&suc,err); |
|
|
|
if(!suc) goto fail; // Conversion failed
|
|
|
|
if(!suc) goto fail; // Conversion failed
|
|
|
|
return p; |
|
|
|
return p; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Case 3
|
|
|
|
// Case 5 and 6
|
|
|
|
{ |
|
|
|
|
|
|
|
bool casevalid=false; |
|
|
|
|
|
|
|
bool upd; |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
BaseMT2Pen updarg(input,"pen","p"); |
|
|
|
|
|
|
|
bool suc=true; |
|
|
|
|
|
|
|
p=updarg(&upd,&suc); |
|
|
|
|
|
|
|
if(upd && !suc) goto fail; // Conversion failed or too many arguments
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!upd) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// default pen is solid black 1mm width
|
|
|
|
OPosPar<Base2NonNegD> width("width",gmt_pen::default_width); |
|
|
|
p.width=gmt_pen::default_width; |
|
|
|
OPosPar<Base2ColorD> color("color",0.0); |
|
|
|
p.color.Convert(0); |
|
|
|
OPosPar<Base2DashD> dash("dash"); |
|
|
|
p.dash.Clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
ParsePositionalParameters params(input,width,color,dash); |
|
|
|
BaseM2Width w(input,"w","width"); |
|
|
|
if(!params) goto case3; // May be case3 will work
|
|
|
|
if(w.Exist()) |
|
|
|
p.color=color; |
|
|
|
{ |
|
|
|
p.dash=dash; |
|
|
|
bool suc=true; |
|
|
|
p.dash.width=p.width=width; |
|
|
|
p.width=w(&suc); |
|
|
|
return p; |
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
|
|
|
|
casevalid=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Color
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
BaseMT2Color color(input,"color","c"); |
|
|
|
|
|
|
|
if(color.Exist()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool suc=true; |
|
|
|
|
|
|
|
p.color=color(&suc); |
|
|
|
|
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
|
|
|
|
casevalid=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Dash
|
|
|
|
// Case 3
|
|
|
|
{ |
|
|
|
case3: |
|
|
|
BaseMT2Dash dash(input,"dash","d"); |
|
|
|
|
|
|
|
if(dash.Exist()) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
bool suc=true; |
|
|
|
bool upd; |
|
|
|
p.dash=dash(&suc); |
|
|
|
ONFPar<Base2Pen,ObjectGMTPen> pen("pen"); |
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
ONFPar<Base2ColorD,ObjectGMTColor> color("color",0.0); |
|
|
|
|
|
|
|
ONFPar<Base2DashD,ObjectGMTDash> dash("dash"); |
|
|
|
|
|
|
|
ONPar<Base2NonNegD> width("width",gmt_pen::default_width); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ParseNamedParameters params(input,color,pen,dash,width); if(!params) {err=params.Error(); goto fail;} } // Fail to parse by variant 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upd=pen.Exist(); |
|
|
|
|
|
|
|
if(upd) p=pen; |
|
|
|
|
|
|
|
if(color.Exist() || !upd) p.color=color; |
|
|
|
|
|
|
|
if(dash.Exist() || !upd) p.dash=dash; |
|
|
|
|
|
|
|
if(width.Exist() || !upd) p.width=width; |
|
|
|
p.dash.width=p.width; |
|
|
|
p.dash.width=p.width; |
|
|
|
casevalid=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(casevalid || upd) return p; // Pen created or updated
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Case 5 and 6
|
|
|
|
if(color.Exist() || dash.Exist() || width.Exist() || upd) return p; // Pen created or updated
|
|
|
|
if(2==size || 3==size) |
|
|
|
err="Specify at least one of color, dash or width"; |
|
|
|
{ |
|
|
|
|
|
|
|
Base2Width w(input,0); |
|
|
|
|
|
|
|
Base2Color c(input,1); |
|
|
|
|
|
|
|
Base2Dash d(input,2); |
|
|
|
|
|
|
|
bool suc=true; |
|
|
|
|
|
|
|
p.width=w(&suc); |
|
|
|
|
|
|
|
p.color=c(&suc); |
|
|
|
|
|
|
|
if(!suc) goto fail; // Something wrong
|
|
|
|
|
|
|
|
p.dash=d(&suc,p.width); |
|
|
|
|
|
|
|
if(!suc) goto fail; // Something wrong
|
|
|
|
|
|
|
|
return p; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fail: |
|
|
|
fail: |
|
|
|