Xcos MVC: implement Adapters methods 79/14979/2
Clément DAVID [Mon, 4 Aug 2014 16:47:06 +0000 (18:47 +0200)]
 * g=scicos_graphics(); disp(g.orig)
 * use anonymous namespace for struct getter / setter
 * getters are not implemented

Change-Id: I4c75f7d23c466adfa91e0056fcebf957c5f2417d

20 files changed:
scilab/modules/scicos/src/cpp/view_scilab/BaseAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/BlockAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/BlockAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/CprAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/DiagramAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/DiagramAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ModelAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ParamsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ParamsAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ScsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ScsAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/StateAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/StateAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/TextAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/TextAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ports_management.hxx

index 2e29957..4d84b0d 100644 (file)
@@ -19,6 +19,8 @@
 #include <iostream>
 
 #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,10 +151,60 @@ 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;
 };
index 495d52d..df78421 100644 (file)
@@ -33,6 +33,8 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
 
 struct graphics
 {
@@ -123,6 +125,8 @@ struct doc
     }
 };
 
+} /* namespace */
+
 template<> property<BlockAdapter>::props_t property<BlockAdapter>::fields = property<BlockAdapter>::props_t();
 
 BlockAdapter::BlockAdapter(const BlockAdapter& o) :
@@ -148,12 +152,6 @@ BlockAdapter::~BlockAdapter()
     delete doc_content;
 }
 
-bool BlockAdapter::toString(std::wostringstream& ostr)
-{
-    ostr << L"BlockAdapter.hxx: Dunno what to display there";
-    return true;
-}
-
 std::wstring BlockAdapter::getTypeStr()
 {
     return getSharedTypeStr();
index 529f9d4..c809b0c 100644 (file)
@@ -39,7 +39,6 @@ public:
         return L"Block";
     }
 
-    bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 
index ee81f98..74840f5 100644 (file)
@@ -24,6 +24,10 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
+
+} /* namespace */
 
 template<> property<CprAdapter>::props_t property<CprAdapter>::fields = property<CprAdapter>::props_t();
 
index b0bfcfd..a8737ab 100644 (file)
@@ -31,6 +31,8 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
 
 struct props
 {
@@ -101,6 +103,8 @@ struct contrib
     }
 };
 
+} /* namespace */
+
 template<> property<DiagramAdapter>::props_t property<DiagramAdapter>::fields = property<DiagramAdapter>::props_t();
 
 DiagramAdapter::DiagramAdapter(const DiagramAdapter& o) :
@@ -123,12 +127,6 @@ DiagramAdapter::~DiagramAdapter()
 {
 }
 
-bool DiagramAdapter::toString(std::wostringstream& ostr)
-{
-    ostr << L"DiagramAdapter.hxx: Dunno what to display there";
-    return true;
-}
-
 std::wstring DiagramAdapter::getTypeStr()
 {
     return getSharedTypeStr();
index bf95497..55652b1 100644 (file)
@@ -37,7 +37,6 @@ public:
         return L"Diagram";
     }
 
-    bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 
index b2dd1f2..2e02ac6 100644 (file)
@@ -30,6 +30,8 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
 
 struct orig
 {
@@ -508,6 +510,8 @@ struct style
     }
 };
 
+} /* namespace */
+
 template<> property<GraphicsAdapter>::props_t property<GraphicsAdapter>::fields = property<GraphicsAdapter>::props_t();
 
 GraphicsAdapter::GraphicsAdapter(const GraphicsAdapter& o) :
@@ -520,7 +524,7 @@ GraphicsAdapter::GraphicsAdapter(org_scilab_modules_scicos::model::Block* o) :
 {
     if (property<GraphicsAdapter>::properties_has_not_been_set())
     {
-        property<GraphicsAdapter>::fields.reserve(17);
+        property<GraphicsAdapter>::fields.reserve(18);
         property<GraphicsAdapter>::add_property(L"orig", &orig::get, &orig::set);
         property<GraphicsAdapter>::add_property(L"sz", &sz::get, &sz::set);
         property<GraphicsAdapter>::add_property(L"flip", &flip::get, &flip::set);
@@ -535,6 +539,7 @@ GraphicsAdapter::GraphicsAdapter(org_scilab_modules_scicos::model::Block* o) :
         property<GraphicsAdapter>::add_property(L"in_implicit", &in_implicit::get, &in_implicit::set);
         property<GraphicsAdapter>::add_property(L"out_implicit", &out_implicit::get, &out_implicit::set);
         property<GraphicsAdapter>::add_property(L"in_style", &in_style::get, &in_style::set);
+        property<GraphicsAdapter>::add_property(L"out_style", &out_style::get, &out_style::set);
         property<GraphicsAdapter>::add_property(L"in_label", &in_label::get, &in_label::set);
         property<GraphicsAdapter>::add_property(L"out_label", &out_label::get, &out_label::set);
         property<GraphicsAdapter>::add_property(L"style", &style::get, &style::set);
@@ -548,12 +553,6 @@ GraphicsAdapter::~GraphicsAdapter()
     delete gr_i_content;
 }
 
-bool GraphicsAdapter::toString(std::wostringstream& ostr)
-{
-    ostr << L"GraphicsAdapter.hxx: Dunno what to display there" << std::endl;
-    return true;
-}
-
 std::wstring GraphicsAdapter::getTypeStr()
 {
     return getSharedTypeStr();
@@ -575,5 +574,5 @@ void GraphicsAdapter::setGrIContent(types::InternalType* v)
     gr_i_content = v->clone();
 }
 
-} /* view_scilab */
+} /* namespace view_scilab */
 } /* namespace org_scilab_modules_scicos */
index 1f393b2..70a543e 100644 (file)
@@ -38,7 +38,6 @@ public:
         return L"graphics";
     }
 
-    bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 
index b876f49..faf7a15 100644 (file)
@@ -24,6 +24,10 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
+
+} /* namespace */
 
 template<> property<LinkAdapter>::props_t property<LinkAdapter>::fields = property<LinkAdapter>::props_t();
 
@@ -43,12 +47,6 @@ LinkAdapter::~LinkAdapter()
 {
 }
 
-bool LinkAdapter::toString(std::wostringstream& ostr)
-{
-    ostr << L"LinkAdapter.hxx: Dunno what to display there";
-    return true;
-}
-
 std::wstring LinkAdapter::getTypeStr()
 {
     return getSharedTypeStr();
index 4ad8fd4..de20072 100644 (file)
@@ -37,7 +37,6 @@ public:
         return L"Link";
     }
 
-    bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 };
index a3c73b7..26ea9d4 100644 (file)
@@ -26,6 +26,8 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
 
 struct sim
 {
@@ -332,8 +334,6 @@ struct odstate
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
-
         if (v->getType() != types::InternalType::ScilabList)
         {
             return false;
@@ -400,6 +400,8 @@ struct blocktype
     }
 };
 
+} /* namespace */
+
 template<> property<ModelAdapter>::props_t property<ModelAdapter>::fields = property<ModelAdapter>::props_t();
 
 ModelAdapter::ModelAdapter(const ModelAdapter& o) :
index 5a58cc4..a97f90b 100644 (file)
@@ -16,6 +16,10 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
+
+} /* namespace */
 
 template<> property<ParamsAdapter>::props_t property<ParamsAdapter>::fields = property<ParamsAdapter>::props_t();
 
@@ -35,12 +39,6 @@ ParamsAdapter::~ParamsAdapter()
 {
 }
 
-bool ParamsAdapter::toString(std::wostringstream& ostr)
-{
-    ostr << L"ParamsAdapter.hxx: Dunno what to display there";
-    return true;
-}
-
 std::wstring ParamsAdapter::getTypeStr()
 {
     return getSharedTypeStr();
index 078e105..bb11d65 100644 (file)
@@ -37,7 +37,6 @@ public:
         return L"params";
     }
 
-    bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 };
index 13ad9a9..ef1a414 100644 (file)
@@ -24,6 +24,10 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
+
+} /* namespace */
 
 template<> property<ScsAdapter>::props_t property<ScsAdapter>::fields = property<ScsAdapter>::props_t();
 
@@ -43,12 +47,6 @@ ScsAdapter::~ScsAdapter()
 {
 }
 
-bool ScsAdapter::toString(std::wostringstream& ostr)
-{
-    ostr << L"ScsAdapter.hxx: Dunno what to display there";
-    return true;
-}
-
 std::wstring ScsAdapter::getTypeStr()
 {
     return getSharedTypeStr();
index e58c85f..434e04f 100644 (file)
@@ -37,7 +37,6 @@ public:
         return L"scs";
     }
 
-    bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 };
index 2277619..b7f1b9f 100644 (file)
@@ -24,6 +24,10 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
+
+} /* namespace */
 
 template<> property<StateAdapter>::props_t property<StateAdapter>::fields = property<StateAdapter>::props_t();
 
@@ -43,12 +47,6 @@ StateAdapter::~StateAdapter()
 {
 }
 
-bool StateAdapter::toString(std::wostringstream& ostr)
-{
-    ostr << L"StateAdapter.hxx: Dunno what to display there";
-    return true;
-}
-
 std::wstring StateAdapter::getTypeStr()
 {
     return getSharedTypeStr();
index 5ffdf62..0c37cc3 100644 (file)
@@ -37,7 +37,6 @@ public:
         return L"xcs";
     }
 
-    bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 };
index 44a4079..d377bee 100644 (file)
@@ -21,6 +21,10 @@ namespace org_scilab_modules_scicos
 {
 namespace view_scilab
 {
+namespace
+{
+
+} /* namespace */
 
 template<> property<TextAdapter>::props_t property<TextAdapter>::fields = property<TextAdapter>::props_t();
 
@@ -40,12 +44,6 @@ TextAdapter::~TextAdapter()
 {
 }
 
-bool TextAdapter::toString(std::wostringstream& ostr)
-{
-    ostr << L"TextAdapter.hxx: Dunno what to display there";
-    return true;
-}
-
 std::wstring TextAdapter::getTypeStr()
 {
     return getSharedTypeStr();
index e345545..2ccbad4 100644 (file)
@@ -37,7 +37,6 @@ public:
         return L"Text";
     }
 
-    bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 };
index 8a549a4..110125b 100644 (file)
@@ -100,7 +100,10 @@ types::InternalType* get_ports_property(const Adaptor& adaptor, object_propertie
             controller.getObjectProperty(adaptee->id(), adaptee->kind(), PARENT_DIAGRAM, diagram);
 
             std::vector<ScicosID> children;
-            controller.getObjectProperty(diagram, DIAGRAM, CHILDREN, children);
+            if (diagram != 0)
+            {
+                controller.getObjectProperty(diagram, DIAGRAM, CHILDREN, children);
+            }
 
             for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
             {