Xcos MVC: minor fixes 59/15759/2
Paul Bignier [Wed, 7 Jan 2015 16:12:14 +0000 (17:12 +0100)]
Change-Id: I83dc68e453ef2fedb34bff3d4dd4048465f9dfd6

scilab/modules/scicos/src/cpp/Controller.cpp
scilab/modules/scicos/src/cpp/view_scilab/BaseAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ModelAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/recursive_cloning.cpp

index c357b23..cb77023 100644 (file)
@@ -54,8 +54,7 @@ void Controller::unregister_view(View* v)
     view_set_t::iterator it = std::find(m_instance.allViews.begin(), m_instance.allViews.end(), v);
     if (it != m_instance.allViews.end())
     {
-        int d = std::distance(m_instance.allViews.begin(), it);
-
+        size_t d = std::distance(m_instance.allViews.begin(), it);
         m_instance.allNamedViews.erase(m_instance.allNamedViews.begin() + d);
         m_instance.allViews.erase(m_instance.allViews.begin() + d);
     }
@@ -68,8 +67,7 @@ View* Controller::unregister_view(const std::string& name)
     view_name_set_t::iterator it = std::find(m_instance.allNamedViews.begin(), m_instance.allNamedViews.end(), name);
     if (it != m_instance.allNamedViews.end())
     {
-        int d = std::distance(m_instance.allNamedViews.begin(), it);
-
+        size_t d = std::distance(m_instance.allNamedViews.begin(), it);
         view = *(m_instance.allViews.begin() + d);
         m_instance.allNamedViews.erase(m_instance.allNamedViews.begin() + d);
         m_instance.allViews.erase(m_instance.allViews.begin() + d);
@@ -85,8 +83,7 @@ View* Controller::look_for_view(const std::string& name)
     view_name_set_t::iterator it = std::find(m_instance.allNamedViews.begin(), m_instance.allNamedViews.end(), name);
     if (it != m_instance.allNamedViews.end())
     {
-        int d = std::distance(m_instance.allNamedViews.begin(), it);
-
+        size_t d = std::distance(m_instance.allNamedViews.begin(), it);
         view = *(m_instance.allViews.begin() + d);
     }
 
@@ -208,7 +205,7 @@ void Controller::deleteVector(ScicosID uid, kind_t k, object_properties_t uid_pr
     std::vector<ScicosID> children;
     getObjectProperty(uid, k, uid_prop, children);
 
-    for (ScicosID id : children)
+for (ScicosID id : children)
     {
         deleteObject(id);
     }
@@ -308,7 +305,7 @@ void Controller::deepCloneVector(std::map<ScicosID, ScicosID>& mapped, ScicosID
     std::vector<ScicosID> cloned;
     cloned.reserve(v.size());
 
-    for (const ScicosID & id : v)
+for (const ScicosID & id : v)
     {
         if (id == 0)
         {
index 00e168f..2f2458e 100644 (file)
@@ -308,7 +308,7 @@ private:
                     std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
 
                     // Allocate the return
-                    types::String* pOut = new types::String(1, properties.size());
+                    types::String* pOut = new types::String(1, static_cast<int>(properties.size()));
 
                     int i = 0;
                     for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it, ++i)
index a517db2..81a8c63 100644 (file)
@@ -498,11 +498,11 @@ struct exprs
 
             for (size_t i = 0; i < paramvSize; ++i)
             {
-                if (list->get(i)->getType() != types::InternalType::ScilabString)
+                if (list->get(static_cast<int>(i))->getType() != types::InternalType::ScilabString)
                 {
                     return false;
                 }
-                types::String* listElement = list->get(i)->getAs<types::String>();
+                types::String* listElement = list->get(static_cast<int>(i))->getAs<types::String>();
                 c_str = wide_string_to_UTF8(listElement->get(0));
                 std::string paramvElement(c_str);
                 FREE(c_str);
@@ -564,7 +564,7 @@ struct exprs
                 types::String* funtxtField = current->get(9)->getAs<types::String>();
 
                 funtxtSize = funtxtField->getSize();
-                int exprsSize = exprs.size(); // Saving last index before resizing
+                size_t exprsSize = exprs.size(); // Saving last index before resizing
                 exprs.resize(exprs.size() + 1 + funtxtSize); // Allocation for the 'funtxt' strings
                 strFuntxt << funtxtSize;
                 std::string funtxtSizeStr = strFuntxt.str();
@@ -572,7 +572,7 @@ struct exprs
 
                 for (size_t i = 0; i < funtxtSize; ++i)
                 {
-                    c_str = wide_string_to_UTF8(funtxtField->get(i));
+                    c_str = wide_string_to_UTF8(funtxtField->get(static_cast<int>(i)));
                     std::string funtxtElement(c_str);
                     FREE(c_str);
                     exprs[exprsSize + 1 + i] = funtxtElement;
index 0ec78b7..b232bbb 100644 (file)
@@ -314,7 +314,7 @@ link_t getLinkEnd(const LinkAdapter& adaptor, const Controller& controller, cons
             return ret;
         }
         controller.getObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
-        ret.block = std::distance(children.begin(), std::find(children.begin(), children.end(), sourceBlock)) + 1;
+        ret.block = static_cast<int>(std::distance(children.begin(), std::find(children.begin(), children.end(), sourceBlock)) + 1);
 
         // To find the port index from its 'endID' ID, search through all the block's ports lists
         std::vector<ScicosID> sourceBlockPorts;
@@ -343,7 +343,7 @@ link_t getLinkEnd(const LinkAdapter& adaptor, const Controller& controller, cons
                 }
             }
         }
-        ret.port = std::distance(sourceBlockPorts.begin(), found) + 1;
+        ret.port = static_cast<int>(std::distance(sourceBlockPorts.begin(), found) + 1);
 
         bool isImplicit;
         controller.getObjectProperty(endID, PORT, IMPLICIT, isImplicit);
@@ -731,8 +731,8 @@ struct from
         link_t from_content {0, 0, Start};
         if (current->getSize() >= 2)
         {
-            from_content.block = current->get(0);
-            from_content.port = current->get(1);
+            from_content.block = static_cast<int>(current->get(0));
+            from_content.port = static_cast<int>(current->get(1));
             // By default, 'kind' designates an output (set to 0)
 
             if (current->getSize() == 3)
@@ -784,8 +784,8 @@ struct to
         link_t to_content {0, 0, End};
         if (current->getSize() >= 2)
         {
-            to_content.block = current->get(0);
-            to_content.port = current->get(1);
+            to_content.block = static_cast<int>(current->get(0));
+            to_content.port = static_cast<int>(current->get(1));
             // By default, 'kind' designates an input (set to 1)
 
             if (current->getSize() == 3)
index ea2eaf1..83c4342 100644 (file)
@@ -914,8 +914,6 @@ struct rpar
         {
             std::shared_ptr<model::Diagram> super = std::static_pointer_cast<model::Diagram>(controller.getObject(diagramChild[0]));
             DiagramAdapter* localAdaptor = new DiagramAdapter(super);
-            //model::Diagram* super = static_cast<model::Diagram*>(controller.getObject(diagramC[0]).get());
-            //DiagramAdapter* localAdapter = new DiagramAdapter(std::shared_ptr<model::Diagram>(super));
 
             DiagramAdapter* diagram = adaptor.getDiagram();
             localAdaptor->setListObjects(diagram->getListObjects());
@@ -1455,6 +1453,7 @@ struct equations
             {
                 return false;
             }
+
             c_str = wide_string_to_UTF8(modelField->get(0));
             std::string modelFieldStored(c_str);
             FREE(c_str);
@@ -1485,6 +1484,7 @@ struct equations
             {
                 return false;
             }
+
             inputsSize = 0;
             std::ostringstream strInputs;
             strInputs << inputsSize;
@@ -1497,6 +1497,7 @@ struct equations
             {
                 return false;
             }
+
             types::String* inputsField = current->get(2)->getAs<types::String>();
             inputsSize = inputsField->getSize();
             equations.resize(equations.size() + 1 + inputsSize);
@@ -1506,7 +1507,7 @@ struct equations
             equations[1] = inputsSizeStr; // Saving the size of the 'inputs' field'
             for (size_t i = 0; i < inputsSize; ++i)
             {
-                c_str = wide_string_to_UTF8(inputsField->get(i));
+                c_str = wide_string_to_UTF8(inputsField->get(static_cast<int>(i)));
                 std::string inputsFieldStored(c_str);
                 FREE(c_str);
                 equations[i + 2] = inputsFieldStored;
@@ -1522,6 +1523,7 @@ struct equations
             {
                 return false;
             }
+
             outputsSize = 0;
             std::ostringstream strOutputs;
             strOutputs << outputsSize;
@@ -1534,6 +1536,7 @@ struct equations
             {
                 return false;
             }
+
             types::String* outputsField = current->get(3)->getAs<types::String>();
             outputsSize = outputsField->getSize();
             equations.resize(equations.size() + 1 + outputsSize);
@@ -1543,7 +1546,7 @@ struct equations
             equations[2 + inputsSize] = outputsSizeStr; // Saving the size of the 'outputs' field'
             for (size_t i = 0; i < outputsSize; ++i)
             {
-                c_str = wide_string_to_UTF8(outputsField->get(i));
+                c_str = wide_string_to_UTF8(outputsField->get(static_cast<int>(i)));
                 std::string outputsFieldStored(c_str);
                 FREE(c_str);
                 equations[i + 3 + inputsSize] = outputsFieldStored;
@@ -1560,12 +1563,15 @@ struct equations
             {
                 return false;
             }
+
             parametersIndex++;
         }
+
         if (current->get(parametersIndex)->getType() != types::InternalType::ScilabList)
         {
             return false;
         }
+
         types::List* list = current->get(parametersIndex)->getAs<types::List>();
         if (list->getSize() < 1)
         {
@@ -1581,6 +1587,7 @@ struct equations
             {
                 return false;
             }
+
             // When 'parameters(1)'=[], just insert "0" in 'equations', set in the model and return
             parametersSize = 0;
             std::ostringstream strParameters;
@@ -1597,6 +1604,7 @@ struct equations
             {
                 return false;
             }
+
             types::String* parametersNames = list->get(0)->getAs<types::String>();
             parametersSize = parametersNames->getSize();
             equations.resize(equations.size() + 1 + parametersSize);
@@ -1606,7 +1614,7 @@ struct equations
             equations[3 + inputsSize + outputsSize] = parametersSizeStr; // Saving the size of the 'parameters' field'
             for (size_t i = 0; i < parametersSize; ++i)
             {
-                c_str = wide_string_to_UTF8(parametersNames->get(i));
+                c_str = wide_string_to_UTF8(parametersNames->get(static_cast<int>(i)));
                 std::string parametersName(c_str);
                 FREE(c_str);
                 equations[i + 4 + inputsSize + outputsSize] = parametersName;
@@ -1621,10 +1629,11 @@ struct equations
             {
                 return false;
             }
+
             for (size_t i = 0; i < parametersSize; ++i)
             {
                 std::ostringstream strParameterVal;
-                strParameterVal << parameterVal->get(i);
+                strParameterVal << parameterVal->get(static_cast<int>(i));
                 std::string parameterValStr = strParameterVal.str();
                 equations.push_back(parameterValStr);
             }
@@ -1635,23 +1644,27 @@ struct equations
             {
                 return false;
             }
+
             types::List* list2 = list->get(1)->getAs<types::List>();
             if (list2->getSize() != static_cast<int>(parametersSize))
             {
                 return false;
             }
+
             equations.resize(equations.size() + parametersSize);
             for (size_t i = 0; i < parametersSize; ++i)
             {
-                if (list2->get(i)->getType() != types::InternalType::ScilabDouble)
+                if (list2->get(static_cast<int>(i))->getType() != types::InternalType::ScilabDouble)
                 {
                     return false;
                 }
-                types::Double* parametersVal = list2->get(i)->getAs<types::Double>();
+
+                types::Double* parametersVal = list2->get(static_cast<int>(i))->getAs<types::Double>();
                 if (parametersVal->getSize() != 1)
                 {
                     return false;
                 }
+
                 std::ostringstream strParametersVal;
                 strParametersVal << parametersVal->get(0);
                 std::string parametersValStr = strParametersVal.str();
index f0a4e84..2233ecb 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "types.hxx"
 #include "list.hxx"
+#include "mlist.hxx"
+#include "string.hxx"
 
 #include "utilities.hxx"
 #include "adapters_utilities.hxx"
@@ -117,7 +119,7 @@ types::List* deepCreateAdapters(const std::vector<ScicosID>& diagramChildren, ty
     }
 
     // Do the linking at model-level, from the old 'from_vec' and 'to_vec'
-    for (int i = 0; i < static_cast<int>(linkListView.size()); ++i)
+    for (size_t i = 0; i < linkListView.size(); ++i)
     {
         // Trigger 'from' and 'to' properties
         linkListView[i]->setFromInModel(from[i], controller);