Xcos MVC: update for the XcosView implementation 23/14923/3
Clément DAVID [Fri, 18 Jul 2014 09:02:30 +0000 (11:02 +0200)]
 * use ScicosID as a long long (easily mapped to a Java long)
 * Fix how to handle a full map (return a zero ScicosID)
 * Move some files to scicos/includes

Change-Id: Id1d51b0552e1400f92ee0dd4c65b2a7138ff065f

scilab/modules/scicos/includes/Controller.hxx [moved from scilab/modules/scicos/src/cpp/Controller.hxx with 99% similarity]
scilab/modules/scicos/includes/View.hxx [moved from scilab/modules/scicos/src/cpp/View.hxx with 100% similarity]
scilab/modules/scicos/includes/utilities.hxx
scilab/modules/scicos/src/c/scicos.vcxproj
scilab/modules/scicos/src/c/scicos.vcxproj.filters
scilab/modules/scicos/src/cpp/LoggerView.cpp
scilab/modules/scicos/src/cpp/Model.cpp

similarity index 99%
rename from scilab/modules/scicos/src/cpp/Controller.hxx
rename to scilab/modules/scicos/includes/Controller.hxx
index 2862f95..9d86a74 100644 (file)
@@ -19,7 +19,6 @@
 #include "utilities.hxx"
 #include "Model.hxx"
 #include "View.hxx"
-#include "model/BaseObject.hxx"
 
 namespace org_scilab_modules_scicos
 {
index 8f8755d..e2b9889 100644 (file)
@@ -23,29 +23,29 @@ namespace org_scilab_modules_scicos
  *
  * The '0' value is used indicate that BaseObject is not handled by the controller.
  */
-//typedef unsigned long long ScicosID;
-struct ScicosID
-{
-    ScicosID(const ScicosID& u) : v(u.v) {}
-    typedef unsigned long long uid_container_type;
-    ScicosID(uid_container_type u) : v(u) {}
-
-    inline bool operator<(const ScicosID& u) const
-    {
-        return v < u.v;
-    }
-    inline bool operator==(const ScicosID& u) const
-    {
-        return v == u.v;
-    }
-    inline void operator++(int added)
-    {
-        v = v + added;
-    }
-    friend std::ostream& operator<< (std::ostream &out, const ScicosID& u);
-private:
-    uid_container_type v;
-};
+typedef long long ScicosID;
+//struct ScicosID
+//{
+//    ScicosID(const ScicosID& u) : v(u.v) {}
+//    typedef unsigned long long uid_container_type;
+//    ScicosID(uid_container_type u) : v(u) {}
+//
+//    inline bool operator<(const ScicosID& u) const
+//    {
+//        return v < u.v;
+//    }
+//    inline bool operator==(const ScicosID& u) const
+//    {
+//        return v == u.v;
+//    }
+//    inline void operator++(int added)
+//    {
+//        v = v + added;
+//    }
+//    friend std::ostream& operator<< (std::ostream &out, const ScicosID& u);
+//private:
+//    uid_container_type v;
+//};
 
 /**
  * Return status of get and set
index 41aabf9..7564caf 100644 (file)
@@ -322,10 +322,10 @@ lib /DEF:"$(ProjectDir)differential_equations_f_Import.def" /SUBSYSTEM:WINDOWS /
     <ClCompile Include="var2sci.c" />
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="..\cpp\Controller.hxx" />
+    <ClInclude Include="..\..\includes\Controller.hxx" />
+    <ClInclude Include="..\..\includes\View.hxx" />
     <ClInclude Include="..\cpp\LoggerView.hxx" />
     <ClInclude Include="..\cpp\Model.hxx" />
-    <ClInclude Include="..\cpp\View.hxx" />
     <ClInclude Include="..\cpp\view_scilab\Adapters.hxx" />
     <ClInclude Include="..\cpp\view_scilab\BaseAdapter.hxx" />
     <ClInclude Include="..\cpp\view_scilab\BlockAdapter.hxx" />
index 9d7d497..4d02a44 100644 (file)
     <ClInclude Include="sciblk4.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="..\cpp\Controller.hxx">
-      <Filter>Header Files\MVC</Filter>
-    </ClInclude>
     <ClInclude Include="..\cpp\LoggerView.hxx">
       <Filter>Header Files\MVC</Filter>
     </ClInclude>
     <ClInclude Include="..\cpp\Model.hxx">
       <Filter>Header Files\MVC</Filter>
     </ClInclude>
-    <ClInclude Include="..\cpp\View.hxx">
-      <Filter>Header Files\MVC</Filter>
-    </ClInclude>
     <ClInclude Include="..\cpp\view_scilab\TextAdapter.hxx">
       <Filter>Header Files\MVC\view_scilab</Filter>
     </ClInclude>
     <ClInclude Include="..\cpp\view_scilab\ParamsAdapter.hxx">
       <Filter>Header Files\MVC\view_scilab</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\includes\Controller.hxx">
+      <Filter>Header Files\MVC</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\includes\View.hxx">
+      <Filter>Header Files\MVC</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="Dynamic_link_Import.def">
index 52ae3f9..ee5a83f 100644 (file)
@@ -29,11 +29,6 @@ LoggerView::~LoggerView()
 {
 }
 
-std::ostream& operator<< (std::ostream &out, const ScicosID& u)
-{
-    return out << u.v;
-}
-
 // generated with :
 // awk ' $2 == "//!<" {sub(",","", $1); print "case " $1 ":\n    os << \"" $1 "\";\n    break;" }' ~/work/branches/YaSp/scilab/modules/scicos/includes/utilities.hxx
 
index e7e91cc..78eab82 100644 (file)
@@ -61,11 +61,33 @@ ScicosID Model::createObject(kind_t k)
      * Found the next unused id
      */
     lastId++;
+    if (lastId == 0)
+    {
+        lastId++;
+    }
+
+    // full map, detection
+    bool has_looped = false;
+
     objects_map_t::iterator iter = allObjects.lower_bound(lastId);
-    while (iter != allObjects.end() && !(lastId < iter->first))
+    while (iter != allObjects.end() && !(lastId < iter->first)) // while key is found
     {
-        // while key is found
+        // try a valid ID
         lastId++;
+        if (lastId == 0)
+        {
+            lastId++;
+
+            // if the map is full, return 0;
+            if (has_looped)
+            {
+                delete o;
+                return 0;
+            }
+            has_looped = true;
+        }
+
+        // look for it
         iter = allObjects.lower_bound(lastId);
     }