Merge branch '2.4'
authorAndrey Kamaev <andrey.kamaev@itseez.com>
Thu, 25 Oct 2012 11:32:48 +0000 (15:32 +0400)
committerAndrey Kamaev <andrey.kamaev@itseez.com>
Thu, 25 Oct 2012 11:32:48 +0000 (15:32 +0400)
1  2 
modules/core/include/opencv2/core/core.hpp
modules/core/src/algorithm.cpp

@@@ -441,6 -514,68 +514,59 @@@ union GetSetPara
      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 )
          {
@@@ -554,9 -721,24 +704,13 @@@ void AlgorithmInfo::get(const Algorithm
              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 )