void (Algorithm::*set_algo)(const Ptr<Algorithm>&);
};
- case Param::SHORT: return "short";
+ static string getNameOfType(int argType);
+
+ static string getNameOfType(int argType)
+ {
+ switch(argType)
+ {
+ case Param::INT: return "integer";
- else if (paramType == Param::SHORT)
- {
- message += "so it should be set by integer value, ";
- }
+ case Param::BOOLEAN: return "boolean";
+ case Param::REAL: return "double";
+ case Param::STRING: return "string";
+ case Param::MAT: return "cv::Mat";
+ case Param::MAT_VECTOR: return "std::vector<cv::Mat>";
+ case Param::ALGORITHM: return "algorithm";
+ default: CV_Error(CV_StsBadArg, "Wrong argument type");
+ }
+ return "";
+ }
+ static string getErrorMessageForWrongArgumentInSetter(string algoName, string paramName, int paramType, int argType);
+ static string getErrorMessageForWrongArgumentInSetter(string algoName, string paramName, int paramType, int argType)
+ {
+ string message = string("Argument error: the setter")
+ + " method was called for the parameter '" + paramName + "' of the algorithm '" + algoName
+ +"', the parameter has " + getNameOfType(paramType) + " type, ";
+
+ if (paramType == Param::INT || paramType == Param::BOOLEAN || paramType == Param::REAL)
+ {
+ message += "so it should be set by integer, boolean, or double value, ";
+ }
- else if (paramType == Param::SHORT)
- {
- message += "so it should be get as integer value, ";
- }
+ message += "but the setter was called with " + getNameOfType(argType) + " value";
+
+ return message;
+ }
+
+ static string getErrorMessageForWrongArgumentInGetter(string algoName, string paramName, int paramType, int argType);
+ static string getErrorMessageForWrongArgumentInGetter(string algoName, string paramName, int paramType, int argType)
+ {
+ string message = string("Argument error: the getter")
+ + " method was called for the parameter '" + paramName + "' of the algorithm '" + algoName
+ +"', the parameter has " + getNameOfType(paramType) + " type, ";
+
+ if (paramType == Param::BOOLEAN)
+ {
+ message += "so it should be get as integer, boolean, or double value, ";
+ }
+ else if (paramType == Param::INT)
+ {
+ message += "so it should be get as integer or double value, ";
+ }
+ message += "but the getter was called to get a " + getNameOfType(argType) + " value";
+
+ return message;
+ }
+
void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, const void* value, bool force) const
{
const Param* p = findstr(data->params, parameter);
if( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL )
{
- CV_Assert( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN );
- if ( !( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN || (p->type == Param::SHORT && argType == Param::INT)) )
++ if ( !( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN) )
+ {
+ string message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType);
+ CV_Error(CV_StsBadArg, message);
+ }
if( p->type == Param::INT )
{
else
*(double*)value = val;
}
- else if( p->type == Param::SHORT )
- {
- if( argType != Param::INT )
- {
- string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
- CV_Error(CV_StsBadArg, message);
- }
- int val = p->getter ? (algo->*f.get_int)() : *(short*)((uchar*)algo + p->offset);
-
- *(int*)value = val;
- }
else if( p->type == Param::BOOLEAN )
{
- CV_Assert( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL );
+ if (!( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL ))
+ {
+ string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
+ CV_Error(CV_StsBadArg, message);
+ }
bool val = p->getter ? (algo->*f.get_bool)() : *(bool*)((uchar*)algo + p->offset);
if( argType == Param::INT )