Added support for bool in ArgumentParser::Parameter.
Added support for using Input::read(...) methods using ArgumentParser::Paramter to adapter to multiple paramter types.
This commit is contained in:
parent
cf69352873
commit
7ea3632dfc
@ -33,6 +33,7 @@ class OSG_EXPORT ArgumentParser
|
||||
public:
|
||||
enum ParameterType
|
||||
{
|
||||
BOOL_PARAMETER,
|
||||
FLOAT_PARAMETER,
|
||||
DOUBLE_PARAMETER,
|
||||
INT_PARAMETER,
|
||||
@ -42,6 +43,7 @@ class OSG_EXPORT ArgumentParser
|
||||
|
||||
union ValueUnion
|
||||
{
|
||||
bool* _bool;
|
||||
float* _float;
|
||||
double* _double;
|
||||
int* _int;
|
||||
@ -49,6 +51,8 @@ class OSG_EXPORT ArgumentParser
|
||||
std::string* _string;
|
||||
};
|
||||
|
||||
Parameter(bool& value) { _type = BOOL_PARAMETER; _value._bool = &value; }
|
||||
|
||||
Parameter(float& value) { _type = FLOAT_PARAMETER; _value._float = &value; }
|
||||
|
||||
Parameter(double& value) { _type = DOUBLE_PARAMETER; _value._double = &value; }
|
||||
@ -83,6 +87,9 @@ class OSG_EXPORT ArgumentParser
|
||||
/** Return true if specified parameter is a number. */
|
||||
static bool isNumber(const char* str);
|
||||
|
||||
/** Return true if specified parameter is a bool. */
|
||||
static bool isBool(const char* str);
|
||||
|
||||
public:
|
||||
|
||||
ArgumentParser(int* argc,char **argv);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <osg/Node>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/ArgumentParser>
|
||||
|
||||
#include <osgDB/FieldReaderIterator>
|
||||
#include <osgDB/ReaderWriter>
|
||||
@ -57,6 +58,18 @@ class OSGDB_EXPORT Input : public FieldReaderIterator
|
||||
virtual osg::Object* getObjectForUniqueID(const std::string& uniqueID);
|
||||
virtual void registerUniqueIDForObject(const std::string& uniqueID,osg::Object* obj);
|
||||
|
||||
typedef osg::ArgumentParser::Parameter Parameter;
|
||||
|
||||
bool read(const char* str);
|
||||
bool read(const char* str, Parameter value1);
|
||||
bool read(const char* str, Parameter value1, Parameter value2);
|
||||
bool read(const char* str, Parameter value1, Parameter value2, Parameter value3);
|
||||
bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4);
|
||||
bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5);
|
||||
bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6);
|
||||
bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7);
|
||||
bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8);
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map< std::string, osg::ref_ptr<osg::Object> > UniqueIDToObjectMapping;
|
||||
|
@ -35,6 +35,15 @@ bool ArgumentParser::isString(const char* str)
|
||||
//return !isOption(str);
|
||||
}
|
||||
|
||||
bool ArgumentParser::isBool(const char* str)
|
||||
{
|
||||
if (!str) return false;
|
||||
|
||||
return (strcmp(str,"True")==0 || strcmp(str,"true")==0 || strcmp(str,"TRUE")==0 ||
|
||||
strcmp(str,"False")==0 || strcmp(str,"false")==0 || strcmp(str,"FALSE")==0 ||
|
||||
strcmp(str,"0")==0 || strcmp(str,"1")==0);
|
||||
}
|
||||
|
||||
bool ArgumentParser::isNumber(const char* str)
|
||||
{
|
||||
if (!str) return false;
|
||||
@ -133,6 +142,7 @@ bool ArgumentParser::Parameter::valid(const char* str) const
|
||||
{
|
||||
switch(_type)
|
||||
{
|
||||
case Parameter::BOOL_PARAMETER: return isBool(str); break;
|
||||
case Parameter::FLOAT_PARAMETER: return isNumber(str); break;
|
||||
case Parameter::DOUBLE_PARAMETER: return isNumber(str); break;
|
||||
case Parameter::INT_PARAMETER: return isNumber(str); break;
|
||||
@ -148,6 +158,11 @@ bool ArgumentParser::Parameter::assign(const char* str)
|
||||
{
|
||||
switch(_type)
|
||||
{
|
||||
case Parameter::BOOL_PARAMETER:
|
||||
{
|
||||
*_value._bool = (strcmp(str,"True")==0 || strcmp(str,"true")==0 || strcmp(str,"TRUE")==0);
|
||||
break;
|
||||
}
|
||||
case Parameter::FLOAT_PARAMETER: *_value._float = atof(str); break;
|
||||
case Parameter::DOUBLE_PARAMETER: *_value._double = atof(str); break;
|
||||
case Parameter::INT_PARAMETER: *_value._int = atoi(str); break;
|
||||
|
@ -97,3 +97,164 @@ osg::Node* Input::readNode(const std::string& fileName)
|
||||
{
|
||||
return readNodeFile(fileName,_options.get());
|
||||
}
|
||||
|
||||
bool Input::read(const char* str)
|
||||
{
|
||||
if ((*this)[0].matchWord(str))
|
||||
{
|
||||
(*this) += 1;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Input::read(const char* str, Parameter value1)
|
||||
{
|
||||
if ((*this)[0].matchWord(str) && value1.valid((*this)[1].getStr()))
|
||||
{
|
||||
value1.assign((*this)[1].getStr());
|
||||
(*this) += 2;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Input::read(const char* str, Parameter value1, Parameter value2)
|
||||
{
|
||||
if ((*this)[0].matchWord(str) &&
|
||||
value1.valid((*this)[1].getStr()) &&
|
||||
value2.valid((*this)[2].getStr()))
|
||||
{
|
||||
value1.assign((*this)[1].getStr());
|
||||
value2.assign((*this)[2].getStr());
|
||||
(*this) += 3;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Input::read(const char* str, Parameter value1, Parameter value2, Parameter value3)
|
||||
{
|
||||
if ((*this)[0].matchWord(str) &&
|
||||
value1.valid((*this)[1].getStr()) &&
|
||||
value2.valid((*this)[2].getStr()) &&
|
||||
value3.valid((*this)[3].getStr()))
|
||||
{
|
||||
value1.assign((*this)[1].getStr());
|
||||
value2.assign((*this)[2].getStr());
|
||||
value3.assign((*this)[3].getStr());
|
||||
(*this) += 4;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Input::read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4)
|
||||
{
|
||||
if ((*this)[0].matchWord(str) &&
|
||||
value1.valid((*this)[1].getStr()) &&
|
||||
value2.valid((*this)[2].getStr()) &&
|
||||
value3.valid((*this)[3].getStr()) &&
|
||||
value4.valid((*this)[4].getStr()))
|
||||
{
|
||||
value1.assign((*this)[1].getStr());
|
||||
value2.assign((*this)[2].getStr());
|
||||
value3.assign((*this)[3].getStr());
|
||||
value4.assign((*this)[4].getStr());
|
||||
(*this) += 5;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Input::read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5)
|
||||
{
|
||||
if ((*this)[0].matchWord(str) &&
|
||||
value1.valid((*this)[1].getStr()) &&
|
||||
value2.valid((*this)[2].getStr()) &&
|
||||
value3.valid((*this)[3].getStr()) &&
|
||||
value4.valid((*this)[4].getStr()) &&
|
||||
value5.valid((*this)[5].getStr()))
|
||||
{
|
||||
value1.assign((*this)[1].getStr());
|
||||
value2.assign((*this)[2].getStr());
|
||||
value3.assign((*this)[3].getStr());
|
||||
value4.assign((*this)[4].getStr());
|
||||
value5.assign((*this)[5].getStr());
|
||||
(*this) += 6;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Input::read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6)
|
||||
{
|
||||
if ((*this)[0].matchWord(str) &&
|
||||
value1.valid((*this)[1].getStr()) &&
|
||||
value2.valid((*this)[2].getStr()) &&
|
||||
value3.valid((*this)[3].getStr()) &&
|
||||
value4.valid((*this)[4].getStr()) &&
|
||||
value5.valid((*this)[5].getStr()) &&
|
||||
value6.valid((*this)[6].getStr()))
|
||||
{
|
||||
value1.assign((*this)[1].getStr());
|
||||
value2.assign((*this)[2].getStr());
|
||||
value3.assign((*this)[3].getStr());
|
||||
value4.assign((*this)[4].getStr());
|
||||
value5.assign((*this)[5].getStr());
|
||||
value6.assign((*this)[6].getStr());
|
||||
(*this) += 7;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Input::read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7)
|
||||
{
|
||||
if ((*this)[0].matchWord(str) &&
|
||||
value1.valid((*this)[1].getStr()) &&
|
||||
value2.valid((*this)[2].getStr()) &&
|
||||
value3.valid((*this)[3].getStr()) &&
|
||||
value4.valid((*this)[4].getStr()) &&
|
||||
value5.valid((*this)[5].getStr()) &&
|
||||
value6.valid((*this)[6].getStr()) &&
|
||||
value7.valid((*this)[7].getStr()))
|
||||
{
|
||||
value1.assign((*this)[1].getStr());
|
||||
value2.assign((*this)[2].getStr());
|
||||
value3.assign((*this)[3].getStr());
|
||||
value4.assign((*this)[4].getStr());
|
||||
value5.assign((*this)[5].getStr());
|
||||
value6.assign((*this)[6].getStr());
|
||||
value7.assign((*this)[7].getStr());
|
||||
(*this) += 8;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Input::read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8)
|
||||
{
|
||||
if ((*this)[0].matchWord(str) &&
|
||||
value1.valid((*this)[1].getStr()) &&
|
||||
value2.valid((*this)[2].getStr()) &&
|
||||
value3.valid((*this)[3].getStr()) &&
|
||||
value4.valid((*this)[4].getStr()) &&
|
||||
value5.valid((*this)[5].getStr()) &&
|
||||
value6.valid((*this)[6].getStr()) &&
|
||||
value7.valid((*this)[7].getStr()) &&
|
||||
value8.valid((*this)[8].getStr()))
|
||||
{
|
||||
value1.assign((*this)[1].getStr());
|
||||
value2.assign((*this)[2].getStr());
|
||||
value3.assign((*this)[3].getStr());
|
||||
value4.assign((*this)[4].getStr());
|
||||
value5.assign((*this)[5].getStr());
|
||||
value6.assign((*this)[6].getStr());
|
||||
value7.assign((*this)[7].getStr());
|
||||
value8.assign((*this)[8].getStr());
|
||||
(*this) += 9;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
@ -232,6 +232,10 @@ BEGIN_VALUE_REFLECTOR(osg::ArgumentParser)
|
||||
__bool__isNumber__C5_char_P1_S,
|
||||
"Return true if specified parameter is a number. ",
|
||||
"");
|
||||
I_StaticMethod1(bool, isBool, IN, const char *, str,
|
||||
__bool__isBool__C5_char_P1_S,
|
||||
"Return true if specified parameter is a bool. ",
|
||||
"");
|
||||
I_SimpleProperty(std::string, ApplicationName,
|
||||
__std_string__getApplicationName,
|
||||
0);
|
||||
@ -245,6 +249,7 @@ END_REFLECTOR
|
||||
|
||||
BEGIN_ENUM_REFLECTOR(osg::ArgumentParser::Parameter::ParameterType)
|
||||
I_DeclaringFile("osg/ArgumentParser");
|
||||
I_EnumLabel(osg::ArgumentParser::Parameter::BOOL_PARAMETER);
|
||||
I_EnumLabel(osg::ArgumentParser::Parameter::FLOAT_PARAMETER);
|
||||
I_EnumLabel(osg::ArgumentParser::Parameter::DOUBLE_PARAMETER);
|
||||
I_EnumLabel(osg::ArgumentParser::Parameter::INT_PARAMETER);
|
||||
@ -254,6 +259,11 @@ END_REFLECTOR
|
||||
|
||||
BEGIN_VALUE_REFLECTOR(osg::ArgumentParser::Parameter)
|
||||
I_DeclaringFile("osg/ArgumentParser");
|
||||
I_Constructor1(IN, bool &, value,
|
||||
Properties::NON_EXPLICIT,
|
||||
____Parameter__bool_R1,
|
||||
"",
|
||||
"");
|
||||
I_Constructor1(IN, float &, value,
|
||||
Properties::NON_EXPLICIT,
|
||||
____Parameter__float_R1,
|
||||
|
@ -28,6 +28,8 @@
|
||||
#undef OUT
|
||||
#endif
|
||||
|
||||
TYPE_NAME_ALIAS(osg::ArgumentParser::Parameter, osgDB::Input::Parameter)
|
||||
|
||||
BEGIN_OBJECT_REFLECTOR(osgDB::Input)
|
||||
I_DeclaringFile("osgDB/Input");
|
||||
I_BaseType(osgDB::FieldReaderIterator);
|
||||
@ -109,6 +111,51 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Input)
|
||||
__void__registerUniqueIDForObject__C5_std_string_R1__osg_Object_P1,
|
||||
"",
|
||||
"");
|
||||
I_Method1(bool, read, IN, const char *, str,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1,
|
||||
"",
|
||||
"");
|
||||
I_Method2(bool, read, IN, const char *, str, IN, osgDB::Input::Parameter, value1,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1__Parameter,
|
||||
"",
|
||||
"");
|
||||
I_Method3(bool, read, IN, const char *, str, IN, osgDB::Input::Parameter, value1, IN, osgDB::Input::Parameter, value2,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1__Parameter__Parameter,
|
||||
"",
|
||||
"");
|
||||
I_Method4(bool, read, IN, const char *, str, IN, osgDB::Input::Parameter, value1, IN, osgDB::Input::Parameter, value2, IN, osgDB::Input::Parameter, value3,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1__Parameter__Parameter__Parameter,
|
||||
"",
|
||||
"");
|
||||
I_Method5(bool, read, IN, const char *, str, IN, osgDB::Input::Parameter, value1, IN, osgDB::Input::Parameter, value2, IN, osgDB::Input::Parameter, value3, IN, osgDB::Input::Parameter, value4,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1__Parameter__Parameter__Parameter__Parameter,
|
||||
"",
|
||||
"");
|
||||
I_Method6(bool, read, IN, const char *, str, IN, osgDB::Input::Parameter, value1, IN, osgDB::Input::Parameter, value2, IN, osgDB::Input::Parameter, value3, IN, osgDB::Input::Parameter, value4, IN, osgDB::Input::Parameter, value5,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1__Parameter__Parameter__Parameter__Parameter__Parameter,
|
||||
"",
|
||||
"");
|
||||
I_Method7(bool, read, IN, const char *, str, IN, osgDB::Input::Parameter, value1, IN, osgDB::Input::Parameter, value2, IN, osgDB::Input::Parameter, value3, IN, osgDB::Input::Parameter, value4, IN, osgDB::Input::Parameter, value5, IN, osgDB::Input::Parameter, value6,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1__Parameter__Parameter__Parameter__Parameter__Parameter__Parameter,
|
||||
"",
|
||||
"");
|
||||
I_Method8(bool, read, IN, const char *, str, IN, osgDB::Input::Parameter, value1, IN, osgDB::Input::Parameter, value2, IN, osgDB::Input::Parameter, value3, IN, osgDB::Input::Parameter, value4, IN, osgDB::Input::Parameter, value5, IN, osgDB::Input::Parameter, value6, IN, osgDB::Input::Parameter, value7,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1__Parameter__Parameter__Parameter__Parameter__Parameter__Parameter__Parameter,
|
||||
"",
|
||||
"");
|
||||
I_Method9(bool, read, IN, const char *, str, IN, osgDB::Input::Parameter, value1, IN, osgDB::Input::Parameter, value2, IN, osgDB::Input::Parameter, value3, IN, osgDB::Input::Parameter, value4, IN, osgDB::Input::Parameter, value5, IN, osgDB::Input::Parameter, value6, IN, osgDB::Input::Parameter, value7, IN, osgDB::Input::Parameter, value8,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__read__C5_char_P1__Parameter__Parameter__Parameter__Parameter__Parameter__Parameter__Parameter__Parameter,
|
||||
"",
|
||||
"");
|
||||
I_SimpleProperty(const osgDB::ReaderWriter::Options *, Options,
|
||||
__C5_ReaderWriter_Options_P1__getOptions,
|
||||
__void__setOptions__C5_ReaderWriter_Options_P1);
|
||||
|
Loading…
Reference in New Issue
Block a user