Xcos MVC: fix header licences
[scilab.git] / scilab / modules / scicos / src / cpp / view_scilab / BaseAdapter.hxx
index 2e29957..95afd40 100644 (file)
@@ -6,7 +6,7 @@
  *  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-en.txt
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
  *
  */
 
 
 #include <algorithm>
 #include <string>
-#include <utility>
-#include <iostream>
+#include <vector>
+#include <sstream>
 
 #include "user.hxx"
+#include "internal.hxx"
+#include "string.hxx"
 
 #include "Controller.hxx"
 #include "Adapters.hxx"
@@ -43,9 +45,10 @@ public:
     typedef typename props_t::iterator props_t_it;
 
 
-    property(const std::wstring& prop, getter_t g, setter_t s) : name(prop), get(g), set(s) {};
+    property(const std::wstring& prop, getter_t g, setter_t s) : original_index(fields.size()), name(prop), get(g), set(s) {};
     ~property() {};
 
+    size_t original_index;
     std::wstring name;
     getter_t get;
     setter_t set;
@@ -55,6 +58,11 @@ public:
         return name < v;
     }
 
+    static bool original_index_cmp(property<Adaptor> p1, property<Adaptor> p2)
+    {
+        return p1.original_index < p2.original_index;
+    }
+
     /*
      * Static properties accessors
      */
@@ -99,14 +107,14 @@ public:
 
     bool hasProperty(const std::wstring& _sKey) const
     {
-        typename property<Adaptor>::props_t_it found = std::binary_search(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
-        return found != property<Adaptor>::fields.end();
+        typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
+        return found != property<Adaptor>::fields.end() && !(_sKey < found->name);
     }
 
     types::InternalType* getProperty(const std::wstring& _sKey, Controller controller = Controller()) const
     {
         typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
-        if (found != property<Adaptor>::fields.end())
+        if (found != property<Adaptor>::fields.end() && !(_sKey < found->name))
         {
             return found->get(static_cast<Adaptor*>(this), controller);
         }
@@ -116,7 +124,7 @@ public:
     bool setProperty(const std::wstring& _sKey, types::InternalType* v, Controller controller = Controller())
     {
         typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
-        if (found != property<Adaptor>::fields.end())
+        if (found != property<Adaptor>::fields.end() && !(_sKey < found->name))
         {
             return found->set(*static_cast<Adaptor*>(this), v, controller);
         }
@@ -143,16 +151,66 @@ public:
      * All following methods should be implemented by each template instance
      */
 
-    virtual bool toString(std::wostringstream& ostr) = 0;
     virtual std::wstring getTypeStr() = 0;
     virtual std::wstring getShortTypeStr() = 0;
 
+    /*
+     * Implement a specific types::User
+     */
+private:
+    types::InternalType* clone()
+    {
+        return new Adaptor(*static_cast<Adaptor*>(this));
+    }
+
+    bool isAssignable()
+    {
+        return true;
+    }
+
+    bool extract(const std::wstring & name, types::InternalType *& out)
+    {
+        typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), name);
+        if (found != property<Adaptor>::fields.end() && !(name < found->name))
+        {
+            Controller controller = Controller();
+            types::InternalType* value = found->get(*static_cast<Adaptor*>(this), controller);
+            if (value == 0)
+            {
+                return false;
+            }
+
+            out = value;
+            return true;
+        }
+        return false;
+    }
+
+    void whoAmI(void)
+    {
+        std::cout << "scicos object";
+    }
+
+    bool toString(std::wostringstream& ostr)
+    {
+        typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
+        std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
+
+        ostr << L"scicos_" <<  getTypeStr() << L" type :" << std::endl;
+        for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it)
+        {
+            ostr << L"  " << it->name << std::endl;
+        }
+        return true;
+    }
+
+
 private:
     Adaptee* adaptee;
 };
 
 
-} /* view_scilab */
+} /* namespace view_scilab */
 } /* namespace org_scilab_modules_scicos */
 
 #endif /* BASEADAPTER_HXX_ */