Some parameters can have legal/illegal ranges and values. These are set with the !LEGAL_VALUE , !ILLEGAL_VALUE , !LEGAL_RANGE and !ILLEGAL_RANGE fields.
bool
int, float and double
string, file and param_file
OEMol and OEGraphMol
Chapter 32 - Example 13 : cpp file
#include "oeplatform.h"
#include "oesystem.h"
//Defines static const unsigned char* array InterfaceData
#include "ch32-13.itf"
//Defines static const unsigned char* array RequirementData
#include "ch32-13r.req"
using namespace OEPlatform;
using namespace OESystem;
using namespace std;
int main(int argc, char** argv)
{
OEInterface itf;
OEConfigure(itf,InterfaceData);
if (OECheckHelp(itf,argc,argv)) return 0;
OEParseCommandLine(itf,argc,argv,RequirementData);
if (!itf.Has<string>("-op"))
{
OEThrow.Error("You must specify -op");
return 1;
}
string op = itf.Get<string>("-op");
float x = itf.Get<float>("-x");
float y = itf.Get<float>("-y");
if (op == "add")
{
oeout << x << " plus " << y << " is " << x+y << oeendl;
}
else if (op == "subtract")
{
oeout << x << " minus " << y << " is " << x-y << oeendl;
}
else if (op == "multiply")
{
oeout << x << " times " << y << " is " << x*y << oeendl;
}
else if (op == "divide")
{
oeout << x << " divided by " << y << " is " << x/y << oeendl;
}
//This isn't needed since op is now restricted to legal values
//else
//{
// OEThrow.Error("%s is not a valid operation",op.c_str());
// return 1;
//}
return 0;
}
Chapter 32 - Example 13 : OEConfigure txt configuration file
!CATEGORY Variables
!BRIEF Category for variables
!PARAMETER -x
!TYPE float
!DEFAULT 10
!LEGAL_RANGE -inf -10
!LEGAL_RANGE 10 1000
!BRIEF First variable
!END
!PARAMETER -y
!TYPE float
!DEFAULT 0.0
!LEGAL_RANGE 0 inf
!BRIEF Second variable
!END
!END
!CATEGORY operator
!PARAMETER -op
!TYPE string
!BRIEF Operation to perform on x and y
!REQUIRED yes
!LEGAL_VALUE add
!LEGAL_VALUE substract
!LEGAL_VALUE multiply
!LEGAL_VALUE divide
!DETAIL
The operation performed is
x <-op> y
So if -op is 'add' the operation is
x + y
!END
!END
Chapter 32 - Example 13 : Requirement txt configuration file
!REQUIREMENT
!OPTION -y 0.0 !-op divide
!OPTION !-y 0.0
!ERROR_MSG
Cannot divide by zero
result would be undefined
!END
The following is example output from the above example program.
> ch32-13 -x -1 -y -1 -op add
Fatal: -1 is not a legal setting for parameter -x (specified on command line)
> ch32-13 -x -1 -y -1 -op divide
Fatal: -1 is not a legal setting for parameter -x (specified on command line)
> ch32-13 -x -99999 -y -1 -op divide
Fatal: -1 is not a legal setting for parameter -y (specified on command line)
> ch32-13 -x -99999 -y 0 -op divide
Fatal: Missing requirements:
Cannot divide by zero
result would be undefined
> ch32-13 -x -99999 -y 0 -op add
-99999.000000 plus 0.000000 is -99999.000000
>
The basic rules for the value range checking are
IMPORTANT: Default parameter values must be legal values.