getType never retrun a RealGeneric 52/11352/1
Cedric Delamarre [Fri, 19 Apr 2013 16:13:15 +0000 (18:13 +0200)]
test_run("string","length")

Change-Id: I05dbbfeb5a6b08f3b96b1cd242fb607767e5ce33

scilab/modules/string/sci_gateway/cpp/sci_length.cpp

index 3131c83..2eaa008 100644 (file)
@@ -63,36 +63,39 @@ Function::ReturnValue sci_length(typed_list &in, int _iRetCount, typed_list &out
         return Function::Error;
     }
 
-    switch (in[0]->getType())
+    if (in[0]->isString())
     {
-        case InternalType::RealString :
-            pOut = lengthStrings(in[0]->getAs<types::String>());
-            break;
-        case InternalType::RealMList :
+        pOut = lengthStrings(in[0]->getAs<types::String>());
+    }
+    else if (in[0]->isMList())
+    {
+        //build overload name and check if function exists.
+        MList* pML = in[0]->getAs<MList>();
+        std::wstring wst = L"%" + pML->getShortTypeStr() + L"_length";
+        symbol::Context* pCtx = symbol::Context::getInstance();
+        InternalType* pFunc = pCtx->get(symbol::Symbol(wst));
+        if (pFunc && pFunc->isCallable())
         {
-            //build overload name and check if function exists.
-            MList* pML = in[0]->getAs<MList>();
-            std::wstring wst = L"%" + pML->getShortTypeStr() + L"_length";
-            symbol::Context* pCtx = symbol::Context::getInstance();
-            InternalType* pFunc = pCtx->get(symbol::Symbol(wst));
-            if (pFunc && pFunc->isCallable())
-            {
-                //call overload
-                Overload::generateNameAndCall(L"length", in, _iRetCount, out, new ExecVisitor());
-                return Function::OK;
-            }
-
-            //MList without overloading, manage like a list
-            //let pass !
+            //call overload
+            Overload::generateNameAndCall(L"length", in, _iRetCount, out, new ExecVisitor());
+            return Function::OK;
         }
-        case InternalType::RealList :
-            pOut = lengthList(in[0]->getAs<List>());
-            break;
-        case InternalType::RealGeneric :
-            pOut = lengthMatrix(in[0]->getAs<GenericType>());
-        default :
-            Scierror(999, _("%s: Wrong type for input argument(s).\n"), "length");
-            return Function::Error;
+
+        //MList without overloading, manage like a list
+        pOut = lengthList(in[0]->getAs<List>());
+    }
+    else if (in[0]->isList())
+    {
+        pOut = lengthList(in[0]->getAs<List>());
+    }
+    else if (in[0]->isGenericType())
+    {
+        pOut = lengthMatrix(in[0]->getAs<GenericType>());
+    }
+    else
+    {
+        Scierror(999, _("%s: Wrong type for input argument(s).\n"), "length");
+        return Function::Error;
     }
 
     out.push_back(pOut);