Scicos: speedup model transformation
[scilab.git] / scilab / modules / scicos / src / cpp / view_scilab / Adapters.cpp
index 8167aea..97f9a6d 100644 (file)
@@ -1,12 +1,15 @@
 /*
  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2014-2014 - Scilab Enterprises - Clement DAVID
+ *  Copyright (C) 2014-2016 - Scilab Enterprises - Clement DAVID
  *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
  *
  */
 
@@ -76,7 +79,6 @@ Adapters::adapters_index_t Adapters::lookup_by_typename(const std::wstring& name
     return INVALID_ADAPTER;
 }
 
-
 std::wstring Adapters::get_typename(Adapters::adapters_index_t kind)
 {
     for (auto it : adapters)
@@ -90,43 +92,46 @@ std::wstring Adapters::get_typename(Adapters::adapters_index_t kind)
     return L"";
 }
 
-
-const model::BaseObject* Adapters::descriptor(types::InternalType* v)
+model::BaseObject* Adapters::descriptor(types::InternalType* v)
 {
     const std::wstring& name = v->getShortTypeStr();
     adapters_t::iterator it = std::lower_bound(adapters.begin(), adapters.end(), name);
     if (v->isUserType() && it != adapters.end() && !(name < it->name))
     {
-        switch (it->kind)
-        {
-            case BLOCK_ADAPTER:
-                return v->getAs<view_scilab::BlockAdapter>()->getAdaptee();
-            case CPR_ADAPTER:
-                return v->getAs<view_scilab::CprAdapter>()->getAdaptee();
-            case DIAGRAM_ADAPTER:
-                return v->getAs<view_scilab::DiagramAdapter>()->getAdaptee();
-            case GRAPHIC_ADAPTER:
-                return v->getAs<view_scilab::GraphicsAdapter>()->getAdaptee();
-            case LINK_ADAPTER:
-                return v->getAs<view_scilab::LinkAdapter>()->getAdaptee();
-            case MODEL_ADAPTER:
-                return v->getAs<view_scilab::ModelAdapter>()->getAdaptee();
-            case PARAMS_ADAPTER:
-                return v->getAs<view_scilab::ParamsAdapter>()->getAdaptee();
-            case SCS_ADAPTER:
-                return v->getAs<view_scilab::ScsAdapter>()->getAdaptee();
-            case STATE_ADAPTER:
-                return v->getAs<view_scilab::StateAdapter>()->getAdaptee();
-            case TEXT_ADAPTER:
-                return v->getAs<view_scilab::TextAdapter>()->getAdaptee();
-            default:
-                return nullptr;
-        }
+        return descriptor(it->kind, v);
     }
-
     return nullptr;
 }
 
+model::BaseObject* Adapters::descriptor(adapters_index_t index, types::InternalType* v)
+{
+    switch (index)
+    {
+        case BLOCK_ADAPTER:
+            return v->getAs<view_scilab::BlockAdapter>()->getAdaptee();
+        case CPR_ADAPTER:
+            return v->getAs<view_scilab::CprAdapter>()->getAdaptee();
+        case DIAGRAM_ADAPTER:
+            return v->getAs<view_scilab::DiagramAdapter>()->getAdaptee();
+        case GRAPHIC_ADAPTER:
+            return v->getAs<view_scilab::GraphicsAdapter>()->getAdaptee();
+        case LINK_ADAPTER:
+            return v->getAs<view_scilab::LinkAdapter>()->getAdaptee();
+        case MODEL_ADAPTER:
+            return v->getAs<view_scilab::ModelAdapter>()->getAdaptee();
+        case PARAMS_ADAPTER:
+            return v->getAs<view_scilab::ParamsAdapter>()->getAdaptee();
+        case SCS_ADAPTER:
+            return v->getAs<view_scilab::ScsAdapter>()->getAdaptee();
+        case STATE_ADAPTER:
+            return v->getAs<view_scilab::StateAdapter>()->getAdaptee();
+        case TEXT_ADAPTER:
+            return v->getAs<view_scilab::TextAdapter>()->getAdaptee();
+        default:
+            return nullptr;
+    }
+}
+
 types::InternalType* Adapters::allocate_view(ScicosID id, kind_t kind)
 {
     Controller controller;
@@ -134,11 +139,11 @@ types::InternalType* Adapters::allocate_view(ScicosID id, kind_t kind)
     switch (kind)
     {
         case BLOCK:
-            return new view_scilab::BlockAdapter(controller, static_cast<model::Block*>(controller.getObject(id)));
+            return new view_scilab::BlockAdapter(controller, controller.getBaseObject<model::Block>(id));
         case LINK:
-            return new view_scilab::LinkAdapter(controller, static_cast<model::Link*>(controller.getObject(id)));
+            return new view_scilab::LinkAdapter(controller, controller.getBaseObject<model::Link>(id));
         case DIAGRAM:
-            return new view_scilab::DiagramAdapter(controller, static_cast<model::Diagram*>(controller.getObject(id)));
+            return new view_scilab::DiagramAdapter(controller, controller.getBaseObject<model::Diagram>(id));
         default:
             return nullptr;
     }