Xcos MVC: use shared_ptr on the Model 16/15416/6
Clément DAVID [Fri, 24 Oct 2014 09:36:39 +0000 (11:36 +0200)]
Model object pointers can be retrieve by any C++ View through
Model::getObject. To track the associated memory and avoid double
delete (on the View then the Model), shared_ptr is used.

Note: this pointer access is not mapped to Java Views so these views
are just allowed to createObject / deleteObject using ScicosID.

Change-Id: Ifbab7d1bfda28105c3680bd28f52c9e35faf1824

38 files changed:
scilab/modules/ast/includes/types/arrayof.hxx
scilab/modules/ast/includes/types/internal.hxx
scilab/modules/scicos/includes/Controller.hxx
scilab/modules/scicos/includes/Model.hxx
scilab/modules/scicos/includes/utilities.hxx
scilab/modules/scicos/sci_gateway/cpp/sci_scicos_new.cpp
scilab/modules/scicos/src/cpp/Controller.cpp
scilab/modules/scicos/src/cpp/Model.cpp
scilab/modules/scicos/src/cpp/Model_getObjectProperties.cpp
scilab/modules/scicos/src/cpp/Model_setObjectProperties.cpp
scilab/modules/scicos/src/cpp/model/Annotation.hxx
scilab/modules/scicos/src/cpp/model/Block.hxx
scilab/modules/scicos/src/cpp/model/Diagram.hxx
scilab/modules/scicos/src/cpp/model/Link.hxx
scilab/modules/scicos/src/cpp/model/Port.hxx
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/CprAdapter.hxx
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/ModelAdapter.hxx
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
scilab/modules/xcos/src/jni/JavaController.i

index 50142f8..b073050 100644 (file)
@@ -1282,7 +1282,7 @@ public :
         return resize(piDims, 2);
     }
 
-    virtual void deleteData(T data)
+    virtual void deleteData(T /*data*/)
     {
     }
 
index 3787ae0..898964b 100644 (file)
@@ -230,7 +230,7 @@ public :
         return getTypeStr();
     }
     virtual InternalType*           clone(void) = 0;
-    virtual ast::Exp*               getExp(const Location &loc)
+    virtual ast::Exp*               getExp(const Location& /*loc*/)
     {
         return NULL;
     }
index 67b4e95..633a17e 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <vector>
 #include <map>
+#include <memory>
 
 #include "utilities.hxx"
 #include "Model.hxx"
@@ -46,8 +47,7 @@ public:
     void deleteObject(ScicosID uid);
     ScicosID cloneObject(ScicosID uid);
 
-    model::BaseObject* getObject(ScicosID uid);
-    update_status_t setObject(model::BaseObject* o);
+    std::shared_ptr<model::BaseObject> getObject(ScicosID uid) const;
 
     template<typename T>
     bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, T& v) const
@@ -103,7 +103,7 @@ private:
     ScicosID cloneObject(std::map<ScicosID, ScicosID>& mapped, ScicosID uid);
 
     template<typename T>
-    void cloneProperties(model::BaseObject* initial, ScicosID clone)
+    void cloneProperties(std::shared_ptr<model::BaseObject> initial, ScicosID clone)
     {
         for (int i = 0; i < MAX_OBJECT_PROPERTIES; ++i)
         {
index 704aee1..127615c 100644 (file)
@@ -16,6 +16,7 @@
 #include <vector>
 #include <map>
 #include <string>
+#include <memory>
 
 #include "utilities.hxx"
 #include "model/BaseObject.hxx"
@@ -62,15 +63,14 @@ public:
      * Model internal methods
      */
 
-    model::BaseObject* getObject(ScicosID uid) const;
-    update_status_t setObject(model::BaseObject* o);
+    std::shared_ptr<model::BaseObject> getObject(ScicosID uid) const;
 
     model::Datatype* flyweight(const model::Datatype& d);
     void erase(model::Datatype* d);
 
 private:
     ScicosID lastId;
-    typedef std::map<ScicosID, model::BaseObject*> objects_map_t;
+    typedef std::map<ScicosID, std::shared_ptr<model::BaseObject> > objects_map_t;
     objects_map_t allObjects;
 
     typedef std::vector<model::Datatype*> datatypes_set_t;
index 1f8d25a..d1188ad 100644 (file)
@@ -109,7 +109,7 @@ enum object_properties_t
     PROPERTIES,         //!< model::Diagram::tol & tf values
     DIAGRAM_CONTEXT,    //!< model::Diagram::context value
     VERSION_NUMBER,     //!< model::Diagram::version value
-    MAX_OBJECT_PROPERTIES //!< last valid value of the object_properties_t enum
+    MAX_OBJECT_PROPERTIES = VERSION_NUMBER //!< last valid value of the object_properties_t enum
 };
 
 #endif /* UTILITIES_HXX_ */
index 2adbc60..c12bcb8 100644 (file)
@@ -57,7 +57,7 @@ types::InternalType * alloc_and_set(kind_t k, types::String* type_name, types::t
 
     // create the associated object
     ScicosID o = controller.createObject(k);
-    Adaptor* adaptor = new Adaptor(true, static_cast<Adaptee*>(controller.getObject(o)));
+    Adaptor* adaptor = new Adaptor(std::static_pointer_cast<Adaptee>(controller.getObject(o)));
 
     // the first header entry is the type
     for (int i = 1; i < (int)in.size(); i++)
@@ -78,7 +78,7 @@ template<class Adaptor, class Adaptee>
 types::InternalType * alloc_and_set_as_mlist(types::String* type_name, types::typed_list &in)
 {
     // check header
-    Adaptor adaptor = Adaptor(false, 0);
+    Adaptor adaptor = Adaptor(0);
     for (int i = 1; i < (int)in.size(); i++)
     {
         std::wstring name(type_name->get(i));
index 57fea37..5de7ff0 100644 (file)
@@ -111,7 +111,7 @@ static void unlink_vector(Controller& controller, ScicosID uid, kind_t k, object
     controller.getObjectProperty(uid, k, uid_prop, v);
     if (v != 0)
     {
-        model::BaseObject* o = controller.getObject(v);
+        auto o = controller.getObject(v);
 
         std::vector<ScicosID> children;
         controller.getObjectProperty(o->id(), o->kind(), ref_prop, children);
@@ -132,7 +132,7 @@ static void unlink(Controller& controller, ScicosID uid, kind_t k, object_proper
     controller.getObjectProperty(uid, k, uid_prop, v);
     if (v != 0)
     {
-        model::BaseObject* o = controller.getObject(v);
+        auto o = controller.getObject(v);
         controller.setObjectProperty(o->id(), o->kind(), ref_prop, 0);
     }
 }
@@ -140,7 +140,7 @@ static void unlink(Controller& controller, ScicosID uid, kind_t k, object_proper
 void Controller::deleteObject(ScicosID uid)
 {
     // disconnect / remove references first
-    model::BaseObject* initial = getObject(uid);
+    auto initial = getObject(uid);
     const kind_t k = initial->kind();
     if (k == ANNOTATION)
     {
@@ -190,7 +190,7 @@ void Controller::deleteObject(ScicosID uid)
 
 ScicosID Controller::cloneObject(std::map<ScicosID, ScicosID>& mapped, ScicosID uid)
 {
-    model::BaseObject* initial = getObject(uid);
+    auto initial = getObject(uid);
     const kind_t k = initial->kind();
     ScicosID o = createObject(k);
     mapped.insert(std::make_pair(uid, o));
@@ -319,23 +319,9 @@ ScicosID Controller::cloneObject(ScicosID uid)
     return cloneObject(mapped, uid);
 }
 
-model::BaseObject* Controller::getObject(ScicosID uid)
+std::shared_ptr<model::BaseObject> Controller::getObject(ScicosID uid) const
 {
     return _instance->model.getObject(uid);
 }
 
-update_status_t Controller::setObject(model::BaseObject* o)
-{
-    update_status_t status = _instance->model.setObject(o);
-
-    if (status == SUCCESS)
-    {
-        for (view_set_t::iterator iter = _instance->allViews.begin(); iter != _instance->allViews.end(); ++iter)
-        {
-            (*iter)->objectUpdated(o->id(), o->kind());
-        }
-    }
-    return status;
-}
-
 } /* namespace org_scilab_modules_scicos */
index 727ebff..6b8ef73 100644 (file)
@@ -13,6 +13,7 @@
 #include <string>
 #include <utility>
 #include <algorithm>
+#include <memory>
 
 #include "Model.hxx"
 #include "utilities.hxx"
@@ -49,23 +50,23 @@ ScicosID Model::createObject(kind_t k)
     /*
      * Allocate the object per kind
      */
-    model::BaseObject* o;
+    std::shared_ptr<model::BaseObject> o;
     switch (k)
     {
         case ANNOTATION:
-            o = new model::Annotation();
+            o = std::make_shared<model::Annotation>(model::Annotation());
             break;
         case DIAGRAM:
-            o = new model::Diagram();
+            o = std::make_shared<model::Diagram>(model::Diagram());
             break;
         case BLOCK:
-            o = new model::Block();
+            o = std::make_shared<model::Block>(model::Block());
             break;
         case LINK:
-            o = new model::Link();
+            o = std::make_shared<model::Link>(model::Link());
             break;
         case PORT:
-            o = new model::Port();
+            o = std::make_shared<model::Port>(model::Port());
             break;
     }
 
@@ -93,7 +94,6 @@ ScicosID Model::createObject(kind_t k)
             // if the map is full, return 0;
             if (has_looped)
             {
-                delete o;
                 return 0;
             }
             has_looped = true;
@@ -119,11 +119,10 @@ void Model::deleteObject(ScicosID uid)
         throw std::string("key has not been found");
     }
 
-    delete iter->second;
     allObjects.erase(iter);
 }
 
-model::BaseObject* Model::getObject(ScicosID uid) const
+std::shared_ptr<model::BaseObject> Model::getObject(ScicosID uid) const
 {
     objects_map_t::const_iterator iter = allObjects.lower_bound(uid);
     if (iter == allObjects.end() || uid < iter->first)
@@ -134,25 +133,6 @@ model::BaseObject* Model::getObject(ScicosID uid) const
     return iter->second;
 }
 
-update_status_t Model::setObject(model::BaseObject* o)
-{
-    objects_map_t::iterator iter = allObjects.lower_bound(o->id());
-    if (iter == allObjects.end() || o->id() < iter->first)
-    {
-        throw std::string("key has not been found");
-    }
-
-    if (*iter->second == *o)
-    {
-        return NO_CHANGES;
-    }
-
-    o->id(iter->second->id());
-    delete iter->second;
-    iter->second = o;
-    return SUCCESS;
-}
-
 // datatypes being a vector of Datatype pointers, we need a dereferencing comparison operator to use std::lower_bound()
 static bool isInferior(const model::Datatype* d1, const model::Datatype* d2)
 {
index 27f4004..faf6664 100644 (file)
@@ -63,7 +63,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, dou
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case FIRING:
@@ -89,7 +89,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, int
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case SIM_FUNCTION_API:
@@ -115,7 +115,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, int
     }
     else if (k == LINK)
     {
-        model::Link* o = static_cast<model::Link*>(getObject(uid));
+        model::Link* o = static_cast<model::Link*>(getObject(uid).get());
         switch (p)
         {
             case COLOR:
@@ -130,7 +130,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, int
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case PORT_KIND:
@@ -180,7 +180,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, boo
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case IMPLICIT:
@@ -198,7 +198,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
 
     if (k == ANNOTATION)
     {
-        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid));
+        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid).get());
         switch (p)
         {
             case DESCRIPTION:
@@ -216,7 +216,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case INTERFACE_FUNCTION:
@@ -243,7 +243,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == DIAGRAM)
     {
-        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid).get());
         switch (p)
         {
             case TITLE:
@@ -261,7 +261,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == LINK)
     {
-        model::Link* o = static_cast<model::Link*>(getObject(uid));
+        model::Link* o = static_cast<model::Link*>(getObject(uid).get());
         switch (p)
         {
             case LABEL:
@@ -273,7 +273,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case STYLE:
@@ -294,7 +294,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
 
     if (k == ANNOTATION)
     {
-        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid));
+        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid).get());
         switch (p)
         {
             case PARENT_DIAGRAM:
@@ -309,7 +309,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case PARENT_DIAGRAM:
@@ -331,7 +331,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
     }
     else if (k == LINK)
     {
-        model::Link* o = static_cast<model::Link*>(getObject(uid));
+        model::Link* o = static_cast<model::Link*>(getObject(uid).get());
         switch (p)
         {
             case PARENT_DIAGRAM:
@@ -349,7 +349,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case SOURCE_BLOCK:
@@ -373,7 +373,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
 
     if (k == ANNOTATION)
     {
-        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid));
+        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid).get());
         switch (p)
         {
             case GEOMETRY:
@@ -385,7 +385,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case GEOMETRY:
@@ -409,7 +409,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == DIAGRAM)
     {
-        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid).get());
         switch (p)
         {
             case PROPERTIES:
@@ -421,7 +421,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == LINK)
     {
-        model::Link* o = static_cast<model::Link*>(getObject(uid));
+        model::Link* o = static_cast<model::Link*>(getObject(uid).get());
         switch (p)
         {
             case CONTROL_POINTS:
@@ -459,7 +459,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case SIM_DEP_UT:
@@ -496,7 +496,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case DATATYPE:
@@ -522,7 +522,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case EXPRS:
@@ -534,7 +534,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == DIAGRAM)
     {
-        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid).get());
         switch (p)
         {
             case DIAGRAM_CONTEXT:
@@ -576,7 +576,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case INPUTS:
@@ -600,7 +600,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == DIAGRAM)
     {
-        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid).get());
         switch (p)
         {
             case CHILDREN:
@@ -620,7 +620,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case CONNECTED_SIGNALS:
index c94dc75..dffae67 100644 (file)
@@ -63,7 +63,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case FIRING:
@@ -88,7 +88,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case SIM_FUNCTION_API:
@@ -111,7 +111,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == LINK)
     {
-        model::Link* o = static_cast<model::Link*>(getObject(uid));
+        model::Link* o = static_cast<model::Link*>(getObject(uid).get());
         switch (p)
         {
             case COLOR:
@@ -124,7 +124,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case PORT_KIND:
@@ -173,7 +173,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case IMPLICIT:
@@ -190,7 +190,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
 
     if (k == ANNOTATION)
     {
-        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid));
+        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid).get());
         switch (p)
         {
             case PARENT_DIAGRAM:
@@ -201,7 +201,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case PARENT_DIAGRAM:
@@ -224,7 +224,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == LINK)
     {
-        model::Link* o = static_cast<model::Link*>(getObject(uid));
+        model::Link* o = static_cast<model::Link*>(getObject(uid).get());
         switch (p)
         {
             case PARENT_DIAGRAM:
@@ -239,7 +239,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case SOURCE_BLOCK:
@@ -258,7 +258,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
 
     if (k == ANNOTATION)
     {
-        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid));
+        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid).get());
         switch (p)
         {
             case DESCRIPTION:
@@ -273,7 +273,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case INTERFACE_FUNCTION:
@@ -294,7 +294,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == DIAGRAM)
     {
-        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid).get());
         switch (p)
         {
             case TITLE:
@@ -309,7 +309,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == LINK)
     {
-        model::Link* o = static_cast<model::Link*>(getObject(uid));
+        model::Link* o = static_cast<model::Link*>(getObject(uid).get());
         switch (p)
         {
             case LABEL:
@@ -320,7 +320,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case STYLE:
@@ -339,7 +339,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
 
     if (k == ANNOTATION)
     {
-        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid));
+        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid).get());
         switch (p)
         {
             case GEOMETRY:
@@ -350,7 +350,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case GEOMETRY:
@@ -369,7 +369,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == DIAGRAM)
     {
-        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid).get());
         switch (p)
         {
             case PROPERTIES:
@@ -380,7 +380,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == LINK)
     {
-        model::Link* o = static_cast<model::Link*>(getObject(uid));
+        model::Link* o = static_cast<model::Link*>(getObject(uid).get());
         switch (p)
         {
             case CONTROL_POINTS:
@@ -415,7 +415,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case SIM_DEP_UT:
@@ -448,7 +448,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case DATATYPE:
@@ -473,7 +473,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case EXPRS:
@@ -484,7 +484,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == DIAGRAM)
     {
-        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid).get());
         switch (p)
         {
             case DIAGRAM_CONTEXT:
@@ -525,7 +525,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == BLOCK)
     {
-        model::Block* o = static_cast<model::Block*>(getObject(uid));
+        model::Block* o = static_cast<model::Block*>(getObject(uid).get());
         switch (p)
         {
             case INPUTS:
@@ -544,7 +544,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == DIAGRAM)
     {
-        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        model::Diagram* o = static_cast<model::Diagram*>(getObject(uid).get());
         switch (p)
         {
             case CHILDREN:
@@ -563,7 +563,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     }
     else if (k == PORT)
     {
-        model::Port* o = static_cast<model::Port*>(getObject(uid));
+        model::Port* o = static_cast<model::Port*>(getObject(uid).get());
         switch (p)
         {
             case CONNECTED_SIGNALS:
index 5efd68f..90fd2b5 100644 (file)
@@ -26,72 +26,73 @@ namespace model
 
 class Annotation: public BaseObject
 {
-    friend class ::org_scilab_modules_scicos::Model;
-
-private:
-    Annotation(): BaseObject(ANNOTATION), parentDiagram(0),
-        description(std::string("Text")), font(std::string("2")), font_size(std::string("1")), relatedTo(0)
+public:
+    Annotation(): BaseObject(ANNOTATION), m_parentDiagram(0),
+        m_description(std::string("Text")), m_font(std::string("2")), m_font_size(std::string("1")), relatedTo(0)
     {
         std::vector<double> geom (4, 0);
         geom[2] = 2;
         geom[3] = 1;
-        geometry = Geometry(geom);
+        m_geometry = Geometry(geom);
     };
-    Annotation(const Annotation& o) : BaseObject(ANNOTATION), parentDiagram(o.parentDiagram), geometry(o.geometry),
-        description(o.description), font(o.font), font_size(o.font_size), relatedTo(o.relatedTo) {};
-    ~Annotation() {};
+    Annotation(const Annotation& o) : BaseObject(ANNOTATION), m_parentDiagram(o.m_parentDiagram), m_geometry(o.m_geometry),
+        m_description(o.m_description), m_font(o.m_font), m_font_size(o.m_font_size), relatedTo(o.relatedTo) {};
+    ~Annotation() = default;
+
+private:
+    friend class ::org_scilab_modules_scicos::Model;
 
     void getDescription(std::string& data) const
     {
-        data = description;
+        data = m_description;
     }
 
     update_status_t setDescription(const std::string& data)
     {
-        if (data == description)
+        if (data == m_description)
         {
             return NO_CHANGES;
         }
 
-        description = data;
+        m_description = data;
         return SUCCESS;
     }
 
     void getFont(std::string& data) const
     {
-        data = font;
+        data = m_font;
     }
 
     update_status_t setFont(const std::string& data)
     {
-        if (data == font)
+        if (data == m_font)
         {
             return NO_CHANGES;
         }
 
-        font = data;
+        m_font = data;
         return SUCCESS;
     }
 
     void getFontSize(std::string& data) const
     {
-        data = font_size;
+        data = m_font_size;
     }
 
     update_status_t setFontSize(const std::string& data)
     {
-        if (data == font_size)
+        if (data == m_font_size)
         {
             return NO_CHANGES;
         }
 
-        font_size = data;
+        m_font_size = data;
         return SUCCESS;
     }
 
     void getGeometry(std::vector<double>& v) const
     {
-        geometry.fill(v);
+        m_geometry.fill(v);
     }
 
     update_status_t setGeometry(const std::vector<double>& v)
@@ -102,28 +103,28 @@ private:
         }
 
         Geometry g = Geometry(v);
-        if (g == geometry)
+        if (g == m_geometry)
         {
             return NO_CHANGES;
         }
 
-        geometry = g;
+        m_geometry = g;
         return SUCCESS;
     }
 
     void getParentDiagram(ScicosID& v) const
     {
-        v = parentDiagram;
+        v = m_parentDiagram;
     }
 
     update_status_t setParentDiagram(const ScicosID v)
     {
-        if (v == parentDiagram)
+        if (v == m_parentDiagram)
         {
             return NO_CHANGES;
         }
 
-        parentDiagram = v;
+        m_parentDiagram = v;
         return SUCCESS;
     }
 
@@ -144,11 +145,11 @@ private:
     }
 
 private:
-    ScicosID parentDiagram;
-    Geometry geometry;
-    std::string description;
-    std::string font;
-    std::string font_size;
+    ScicosID m_parentDiagram;
+    Geometry m_geometry;
+    std::string m_description;
+    std::string m_font;
+    std::string m_font_size;
     ScicosID relatedTo;
 };
 
index eb0d195..48661af 100644 (file)
@@ -99,43 +99,43 @@ struct Angle
 
 class Block: public BaseObject
 {
-private:
-    friend class ::org_scilab_modules_scicos::Model;
+public:
+    Block() : BaseObject(BLOCK), m_parentDiagram(0), m_interfaceFunction(), m_geometry(), m_angle(),
+        m_exprs(), m_label(), m_style(), m_nzcross(0), m_nmode(0), m_equations(), m_uid(), m_sim(), m_in(), m_out(), m_ein(), m_eout(),
+        m_parameter(), m_state(), m_parentBlock(0), m_children(), m_portReference(0)
+    {
+        m_sim.blocktype  = BLOCKTYPE_C;
+        m_parameter.opar = std::vector<int> (1, 0);
+        m_state.odstate  = std::vector<int> (1, 0);
+    };
+    Block(const Block& o) : BaseObject(BLOCK), m_parentDiagram(o.m_parentDiagram), m_interfaceFunction(o.m_interfaceFunction), m_geometry(o.m_geometry),
+        m_angle(o.m_angle), m_exprs(o.m_exprs), m_label(o.m_label), m_style(o.m_style), m_nzcross(o.m_nzcross), m_nmode(o.m_nmode), m_equations(o.m_equations), m_uid(o.m_uid),
+        m_sim(o.m_sim), m_in(o.m_in), m_out(o.m_out), m_ein(o.m_ein), m_eout(o.m_eout), m_parameter(o.m_parameter), m_state(o.m_state), m_parentBlock(o.m_parentBlock),
+        m_children(o.m_children), m_portReference(o.m_portReference) {};
+    ~Block() = default;
 
 private:
-    Block() : BaseObject(BLOCK), parentDiagram(0), interfaceFunction(), geometry(), angle(),
-        exprs(), label(), style(), nzcross(0), nmode(0), equations(), uid(), sim(), in(), out(), ein(), eout(),
-        parameter(), state(), parentBlock(0), children(), portReference(0)
-    {
-        sim.blocktype  = BLOCKTYPE_C;
-        parameter.opar = std::vector<int> (1, 0);
-        state.odstate  = std::vector<int> (1, 0);
-    };
-    Block(const Block& o) : BaseObject(BLOCK), parentDiagram(o.parentDiagram), interfaceFunction(o.interfaceFunction), geometry(o.geometry),
-        angle(o.angle), exprs(o.exprs), label(o.label), style(o.style), nzcross(o.nzcross), nmode(o.nmode), equations(o.equations), uid(o.uid),
-        sim(o.sim), in(o.in), out(o.out), ein(o.ein), eout(o.eout), parameter(o.parameter), state(o.state), parentBlock(o.parentBlock),
-        children(o.children), portReference(o.portReference) {};
-    ~Block() {}
+    friend class ::org_scilab_modules_scicos::Model;
 
     void getChildren(std::vector<ScicosID>& v) const
     {
-        v = this->children;
+        v = this->m_children;
     }
 
     update_status_t setChildren(const std::vector<ScicosID>& children)
     {
-        if (children == this->children)
+        if (children == this->m_children)
         {
             return NO_CHANGES;
         }
 
-        this->children = children;
+        this->m_children = children;
         return SUCCESS;
     }
 
     void getGeometry(std::vector<double>& v) const
     {
-        geometry.fill(v);
+        m_geometry.fill(v);
     }
 
     update_status_t setGeometry(const std::vector<double>& v)
@@ -146,18 +146,18 @@ private:
         }
 
         Geometry g = Geometry(v);
-        if (g == geometry)
+        if (g == m_geometry)
         {
             return NO_CHANGES;
         }
 
-        geometry = g;
+        m_geometry = g;
         return SUCCESS;
     }
 
     void getAngle(std::vector<double>& data) const
     {
-        angle.fill(data);
+        m_angle.fill(data);
     }
 
     update_status_t setAngle(const std::vector<double>& data)
@@ -168,342 +168,342 @@ private:
         }
 
         Angle a = Angle(data);
-        if (a == angle)
+        if (a == m_angle)
         {
             return NO_CHANGES;
         }
 
-        angle = a;
+        m_angle = a;
         return SUCCESS;
     }
 
     void getExprs(std::vector<std::string>& data) const
     {
-        data = exprs;
+        data = m_exprs;
     }
 
     update_status_t setExprs(const std::vector<std::string>& data)
     {
-        if (data == exprs)
+        if (data == m_exprs)
         {
             return NO_CHANGES;
         }
 
-        exprs = data;
+        m_exprs = data;
         return SUCCESS;
     }
 
     void getLabel(std::string& data) const
     {
-        data = label;
+        data = m_label;
     }
 
     update_status_t setLabel(const std::string& data)
     {
-        if (data == label)
+        if (data == m_label)
         {
             return NO_CHANGES;
         }
 
-        label = data;
+        m_label = data;
         return SUCCESS;
     }
 
     void getIn(std::vector<ScicosID>& v) const
     {
-        v = in;
+        v = m_in;
     }
 
     update_status_t setIn(const std::vector<ScicosID>& in)
     {
-        if (in == this->in)
+        if (in == this->m_in)
         {
             return NO_CHANGES;
         }
 
-        this->in = in;
+        this->m_in = in;
         return SUCCESS;
     }
 
     void getInterfaceFunction(std::string& fun) const
     {
-        fun = interfaceFunction;
+        fun = m_interfaceFunction;
     }
 
     update_status_t setInterfaceFunction(const std::string& fun)
     {
-        if (fun == interfaceFunction)
+        if (fun == m_interfaceFunction)
         {
             return NO_CHANGES;
         }
 
-        interfaceFunction = fun;
+        m_interfaceFunction = fun;
         return SUCCESS;
     }
 
     void getOut(std::vector<ScicosID>& v) const
     {
-        v = out;
+        v = m_out;
     }
 
     update_status_t setOut(const std::vector<ScicosID>& out)
     {
-        if (out == this->out)
+        if (out == this->m_out)
         {
             return NO_CHANGES;
         }
 
-        this->out = out;
+        this->m_out = out;
         return SUCCESS;
     }
 
     void getEin(std::vector<ScicosID>& v) const
     {
-        v = ein;
+        v = m_ein;
     }
 
     update_status_t setEin(const std::vector<ScicosID>& ein)
     {
-        if (ein == this->ein)
+        if (ein == this->m_ein)
         {
             return NO_CHANGES;
         }
 
-        this->ein = ein;
+        this->m_ein = ein;
         return SUCCESS;
     }
 
     void getEout(std::vector<ScicosID>& v) const
     {
-        v = eout;
+        v = m_eout;
     }
 
     update_status_t setEout(const std::vector<ScicosID>& eout)
     {
-        if (eout == this->eout)
+        if (eout == this->m_eout)
         {
             return NO_CHANGES;
         }
 
-        this->eout = eout;
+        this->m_eout = eout;
         return SUCCESS;
     }
 
     const Parameter& getParameter() const
     {
-        return parameter;
+        return m_parameter;
     }
 
     void setParameter(const Parameter& parameter)
     {
-        this->parameter = parameter;
+        this->m_parameter = parameter;
     }
 
     void getParentBlock(ScicosID& v) const
     {
-        v = parentBlock;
+        v = m_parentBlock;
     }
 
     update_status_t setParentBlock(ScicosID parentBlock)
     {
-        if (parentBlock == this->parentBlock)
+        if (parentBlock == this->m_parentBlock)
         {
             return NO_CHANGES;
         }
 
-        this->parentBlock = parentBlock;
+        this->m_parentBlock = parentBlock;
         return SUCCESS;
     }
 
     void getParentDiagram(ScicosID& v) const
     {
-        v = parentDiagram;
+        v = m_parentDiagram;
     }
 
     update_status_t setParentDiagram(const ScicosID v)
     {
-        if (v == parentDiagram)
+        if (v == m_parentDiagram)
         {
             return NO_CHANGES;
         }
 
-        parentDiagram = v;
+        m_parentDiagram = v;
         return SUCCESS;
     }
 
     void getPortReference(ScicosID& v) const
     {
-        v = portReference;
+        v = m_portReference;
     }
 
     update_status_t setPortReference(const ScicosID v)
     {
-        if (v == portReference)
+        if (v == m_portReference)
         {
             return NO_CHANGES;
         }
 
-        portReference = v;
+        m_portReference = v;
         return SUCCESS;
     }
 
     const Descriptor& getSim() const
     {
-        return sim;
+        return m_sim;
     }
 
     void setSim(const Descriptor& sim)
     {
-        this->sim = sim;
+        this->m_sim = sim;
     }
 
     void getStyle(std::string& data) const
     {
-        data = style;
+        data = m_style;
     }
 
     update_status_t setStyle(const std::string& data)
     {
-        if (data == style)
+        if (data == m_style)
         {
             return NO_CHANGES;
         }
 
-        style = data;
+        m_style = data;
         return SUCCESS;
     }
 
     void getNZcross(int& data) const
     {
-        data = nzcross;
+        data = m_nzcross;
     }
 
     update_status_t setNZcross(const int data)
     {
-        if (data == nzcross)
+        if (data == m_nzcross)
         {
             return NO_CHANGES;
         }
 
-        nzcross = data;
+        m_nzcross = data;
         return SUCCESS;
     }
 
     void getNMode(int& data) const
     {
-        data = nmode;
+        data = m_nmode;
     }
 
     update_status_t setNMode(const int data)
     {
-        if (data == nmode)
+        if (data == m_nmode)
         {
             return NO_CHANGES;
         }
 
-        nmode = data;
+        m_nmode = data;
         return SUCCESS;
     }
 
     void getUID(std::string& data) const
     {
-        data = uid;
+        data = m_uid;
     }
 
     update_status_t setUID(const std::string& data)
     {
-        if (data == uid)
+        if (data == m_uid)
         {
             return NO_CHANGES;
         }
 
-        uid = data;
+        m_uid = data;
         return SUCCESS;
     }
 
     void getRpar(std::vector<double>& data) const
     {
-        data = parameter.rpar;
+        data = m_parameter.rpar;
     }
 
     update_status_t setRpar(const std::vector<double>& data)
     {
-        if (data == parameter.rpar)
+        if (data == m_parameter.rpar)
         {
             return NO_CHANGES;
         }
 
-        parameter.rpar = data;
+        m_parameter.rpar = data;
         return SUCCESS;
     }
 
     void getIpar(std::vector<int>& data) const
     {
-        data = parameter.ipar;
+        data = m_parameter.ipar;
     }
 
     update_status_t setIpar(const std::vector<int>& data)
     {
-        if (data == parameter.ipar)
+        if (data == m_parameter.ipar)
         {
             return NO_CHANGES;
         }
 
-        parameter.ipar = data;
+        m_parameter.ipar = data;
         return SUCCESS;
     }
 
     void getOpar(std::vector<int>& data) const
     {
-        data = parameter.opar;
+        data = m_parameter.opar;
     }
 
     update_status_t setOpar(const std::vector<int>& data)
     {
-        if (data == parameter.opar)
+        if (data == m_parameter.opar)
         {
             return NO_CHANGES;
         }
 
-        parameter.opar = data;
+        m_parameter.opar = data;
         return SUCCESS;
     }
 
     void getSimFunctionName(std::string& data) const
     {
-        data = sim.functionName;
+        data = m_sim.functionName;
     }
 
     update_status_t setSimFunctionName(const std::string& data)
     {
-        if (data == sim.functionName)
+        if (data == m_sim.functionName)
         {
             return NO_CHANGES;
         }
 
-        sim.functionName = data;
+        m_sim.functionName = data;
         return SUCCESS;
     }
 
     void getSimFunctionApi(int& data) const
     {
-        data = sim.functionApi;
+        data = m_sim.functionApi;
     }
 
     update_status_t setSimFunctionApi(const int data)
     {
-        if (data == sim.functionApi)
+        if (data == m_sim.functionApi)
         {
             return NO_CHANGES;
         }
 
-        sim.functionApi = data;
+        m_sim.functionApi = data;
         return SUCCESS;
     }
 
     void getSimBlocktype(std::string& data) const
     {
-        data = std::string(1, sim.blocktype);
+        data = std::string(1, m_sim.blocktype);
     }
 
     update_status_t setSimBlocktype(const std::string data)
@@ -515,7 +515,7 @@ private:
 
         char c = *(data.c_str());
 
-        if (c == sim.blocktype)
+        if (c == m_sim.blocktype)
         {
             return NO_CHANGES;
         }
@@ -529,7 +529,7 @@ private:
             case BLOCKTYPE_M:
             case BLOCKTYPE_X:
             case BLOCKTYPE_Z:
-                sim.blocktype = c;
+                m_sim.blocktype = c;
                 return SUCCESS;
             default:
                 return FAIL;
@@ -539,7 +539,7 @@ private:
     void getSimDepUT(std::vector<int>& data) const
     {
         data.resize(2, 0);
-        switch (sim.dep_ut)
+        switch (m_sim.dep_ut)
         {
             case DEP_U & DEP_T:
                 // data is already set to [0 0] here.
@@ -583,97 +583,97 @@ private:
             dep = DEP_T;
         }
 
-        if (dep == sim.dep_ut)
+        if (dep == m_sim.dep_ut)
         {
             return NO_CHANGES;
         }
 
-        sim.dep_ut = dep;
+        m_sim.dep_ut = dep;
         return SUCCESS;
     }
 
     void getState(std::vector<double>& data) const
     {
-        data = state.state;
+        data = m_state.state;
     }
 
     update_status_t setState(const std::vector<double>& data)
     {
-        if (data == state.state)
+        if (data == m_state.state)
         {
             return NO_CHANGES;
         }
 
-        state.state = data;
+        m_state.state = data;
         return SUCCESS;
     }
 
     void getDState(std::vector<double>& data) const
     {
-        data = state.dstate;
+        data = m_state.dstate;
     }
 
     update_status_t setDState(const std::vector<double>& data)
     {
-        if (data == state.dstate)
+        if (data == m_state.dstate)
         {
             return NO_CHANGES;
         }
 
-        state.dstate = data;
+        m_state.dstate = data;
         return SUCCESS;
     }
 
     void getODState(std::vector<int>& data) const
     {
-        data = state.odstate;
+        data = m_state.odstate;
     }
 
     update_status_t setODState(const std::vector<int>& data)
     {
-        if (data == state.odstate)
+        if (data == m_state.odstate)
         {
             return NO_CHANGES;
         }
 
-        state.odstate = data;
+        m_state.odstate = data;
         return SUCCESS;
     }
 
 private:
-    ScicosID parentDiagram;
-    std::string interfaceFunction;
-    Geometry geometry;
-    Angle angle;
-    std::vector<std::string> exprs;
-    std::string label;
-    std::string style;
-    int nzcross;
-    int nmode;
+    ScicosID m_parentDiagram;
+    std::string m_interfaceFunction;
+    Geometry m_geometry;
+    Angle m_angle;
+    std::vector<std::string> m_exprs;
+    std::string m_label;
+    std::string m_style;
+    int m_nzcross;
+    int m_nmode;
     // FIXME: find an appropriate way to store 'equations'
-    std::vector<std::string> equations;
-    std::string uid;
+    std::vector<std::string> m_equations;
+    std::string m_uid;
 
-    Descriptor sim;
+    Descriptor m_sim;
 
-    std::vector<ScicosID> in;
-    std::vector<ScicosID> out;
-    std::vector<ScicosID> ein;
-    std::vector<ScicosID> eout;
+    std::vector<ScicosID> m_in;
+    std::vector<ScicosID> m_out;
+    std::vector<ScicosID> m_ein;
+    std::vector<ScicosID> m_eout;
 
-    Parameter parameter;
-    State state;
+    Parameter m_parameter;
+    State m_state;
 
     /**
      * SuperBlock: the blocks, links and so on contained into this block
      */
-    ScicosID parentBlock;
-    std::vector<ScicosID> children;
+    ScicosID m_parentBlock;
+    std::vector<ScicosID> m_children;
 
     /**
      * I/O Blocks: the corresponding parent port
      */
-    ScicosID portReference;
+    ScicosID m_portReference;
 };
 
 } /* namespace model */
index 04e0c23..fe94143 100644 (file)
@@ -67,59 +67,60 @@ struct SimulationConfig
 
 class Diagram: public BaseObject
 {
+public:
+    Diagram() : BaseObject(DIAGRAM), m_title("Untitled"), m_path(), m_properties(), m_context(), m_children(), m_version() {};
+    Diagram(const Diagram& o) : BaseObject(DIAGRAM), m_title(o.m_title), m_path(o.m_path), m_properties(o.m_properties),
+        m_context(o.m_context), m_children(o.m_children), m_version(o.m_version) {};
+    ~Diagram() = default;
+
 private:
     friend class ::org_scilab_modules_scicos::Model;
 
-    Diagram() : BaseObject(DIAGRAM), title("Untitled"), path(), properties(), context(), children(), version() {};
-    Diagram(const Diagram& o) : BaseObject(DIAGRAM), title(o.title), path(o.path), properties(o.properties),
-        context(o.context), children(o.children), version(o.version) {};
-    ~Diagram() {}
-
     void getChildren(std::vector<ScicosID>& c) const
     {
-        c = children;
+        c = m_children;
     }
 
     update_status_t setChildren(const std::vector<ScicosID>& c)
     {
-        if (c == children)
+        if (c == m_children)
         {
             return NO_CHANGES;
         }
 
-        children = c;
+        m_children = c;
         return SUCCESS;
     }
 
     void getContext(std::vector<std::string>& data) const
     {
-        data = context;
+        data = m_context;
     }
 
     update_status_t setContext(const std::vector<std::string>& data)
     {
-        if (data == context)
+        if (data == m_context)
         {
             return NO_CHANGES;
         }
 
-        context = data;
+        m_context = data;
         return SUCCESS;
     }
 
     const std::vector<Datatype*>& getDatatypes() const
     {
-        return datatypes;
+        return m_datatypes;
     }
 
     void setDatatypes(const std::vector<Datatype*>& datatypes)
     {
-        this->datatypes = datatypes;
+        this->m_datatypes = datatypes;
     }
 
     void getProperties(std::vector<double>& v) const
     {
-        properties.fill(v);
+        m_properties.fill(v);
     }
 
     update_status_t setProperties(const std::vector<double>& v)
@@ -130,73 +131,73 @@ private:
         }
 
         SimulationConfig p = SimulationConfig(v);
-        if (p == properties)
+        if (p == m_properties)
         {
             return NO_CHANGES;
         }
 
-        properties = p;
+        m_properties = p;
         return SUCCESS;
     }
 
     void getTitle(std::string& data) const
     {
-        data = title;
+        data = m_title;
     }
 
     update_status_t setTitle(const std::string& data)
     {
-        if (data == title)
+        if (data == m_title)
         {
             return NO_CHANGES;
         }
 
-        title = data;
+        m_title = data;
         return SUCCESS;
     }
 
     void getPath(std::string& data) const
     {
-        data = path;
+        data = m_path;
     }
 
     update_status_t setPath(const std::string& data)
     {
-        if (data == path)
+        if (data == m_path)
         {
             return NO_CHANGES;
         }
 
-        path = data;
+        m_path = data;
         return SUCCESS;
     }
 
     void getVersionNumber(std::string& data) const
     {
-        data = version;
+        data = m_version;
     }
 
     update_status_t setVersionNumber(const std::string& data)
     {
-        if (data == version)
+        if (data == m_version)
         {
             return NO_CHANGES;
         }
 
-        version = data;
+        m_version = data;
         return SUCCESS;
     }
 
 private:
-    std::string title;
-    std::string path;
-    SimulationConfig properties;
-    std::vector<std::string> context;
+    std::string m_title;
+    std::string m_path;
+    SimulationConfig m_properties;
+    std::vector<std::string> m_context;
 
-    std::vector<ScicosID> children;
-    std::vector<Datatype*> datatypes;
+    std::vector<ScicosID> m_children;
+    std::vector<Datatype*> m_datatypes;
 
-    std::string version;
+    std::string m_version;
 };
 
 } /* namespace model */
index 23f6285..65f93f5 100644 (file)
@@ -36,66 +36,67 @@ enum link_kind_t
 
 class Link: public BaseObject
 {
-    friend class ::org_scilab_modules_scicos::Model;
+public:
+    Link() : BaseObject(LINK), m_parentDiagram(0), m_sourcePort(0), m_destinationPort(0), m_controlPoints(),
+        m_label(), m_thick(std::vector<double>(2)), m_color(1), m_linkKind(regular) {};
+    Link(const Link& o) : BaseObject(LINK), m_parentDiagram(o.m_parentDiagram), m_sourcePort(o.m_sourcePort), m_destinationPort(o.m_destinationPort),
+        m_controlPoints(o.m_controlPoints), m_label(o.m_label), m_thick(o.m_thick), m_color(o.m_color), m_linkKind(o.m_linkKind) {};
+    ~Link() = default;
 
 private:
-    Link() : BaseObject(LINK), parentDiagram(0), sourcePort(0), destinationPort(0), controlPoints(),
-        label(), thick(std::vector<double>(2)), color(1), linkKind(regular) {};
-    Link(const Link& o) : BaseObject(LINK), parentDiagram(o.parentDiagram), sourcePort(o.sourcePort), destinationPort(o.destinationPort),
-        controlPoints(o.controlPoints), label(o.label), thick(o.thick), color(o.color), linkKind(o.linkKind) {};
-    ~Link() {}
+    friend class ::org_scilab_modules_scicos::Model;
 
     void getParentDiagram(ScicosID& v) const
     {
-        v = parentDiagram;
+        v = m_parentDiagram;
     }
 
     update_status_t setParentDiagram(const ScicosID v)
     {
-        if (v == parentDiagram)
+        if (v == m_parentDiagram)
         {
             return NO_CHANGES;
         }
 
-        parentDiagram = v;
+        m_parentDiagram = v;
         return SUCCESS;
     }
 
     void getControlPoints(std::vector<double>& v) const
     {
-        v = controlPoints;
+        v = m_controlPoints;
     }
 
     update_status_t setControlPoints(const std::vector<double>& v)
     {
-        if (v == controlPoints)
+        if (v == m_controlPoints)
         {
             return NO_CHANGES;
         }
 
-        controlPoints = v;
+        m_controlPoints = v;
         return SUCCESS;
     }
 
     void getLabel(std::string& data) const
     {
-        data = label;
+        data = m_label;
     }
 
     update_status_t setLabel(const std::string& data)
     {
-        if (data == label)
+        if (data == m_label)
         {
             return NO_CHANGES;
         }
 
-        label = data;
+        m_label = data;
         return SUCCESS;
     }
 
     void getThick(std::vector<double>& v) const
     {
-        v = thick;
+        v = m_thick;
     }
 
     update_status_t setThick(const std::vector<double>& v)
@@ -105,39 +106,39 @@ private:
             return FAIL;
         }
 
-        if (v == thick)
+        if (v == m_thick)
         {
             return NO_CHANGES;
         }
 
-        thick = v;
+        m_thick = v;
         return SUCCESS;
     }
 
     void getColor(int& c) const
     {
-        c = color;
+        c = m_color;
     }
 
     update_status_t setColor(const int c)
     {
-        if (c == color)
+        if (c == m_color)
         {
             return NO_CHANGES;
         }
 
-        color = c;
+        m_color = c;
         return SUCCESS;
     }
 
     void getKind(int& k) const
     {
-        k = linkKind;
+        k = m_linkKind;
     }
 
     update_status_t setKind(const int k)
     {
-        if (k == linkKind)
+        if (k == m_linkKind)
         {
             return NO_CHANGES;
         }
@@ -146,13 +147,13 @@ private:
         switch (k)
         {
             case activation:
-                linkKind = activation;
+                m_linkKind = activation;
                 break;
             case regular:
-                linkKind = regular;
+                m_linkKind = regular;
                 break;
             case implicit:
-                linkKind = implicit;
+                m_linkKind = implicit;
                 break;
             default:
                 return FAIL;
@@ -162,49 +163,49 @@ private:
 
     void getSourcePort(ScicosID& sp) const
     {
-        sp = sourcePort;
+        sp = m_sourcePort;
     }
 
     update_status_t setSourcePort(const ScicosID sp)
     {
-        if (sp == sourcePort)
+        if (sp == m_sourcePort)
         {
             return NO_CHANGES;
         }
 
-        sourcePort = sp;
+        m_sourcePort = sp;
         return SUCCESS;
     }
 
     void getDestinationPort(ScicosID& dp) const
     {
-        dp = destinationPort;
+        dp = m_destinationPort;
     }
 
     update_status_t setDestinationPort(const ScicosID dp)
     {
-        if (dp == destinationPort)
+        if (dp == m_destinationPort)
         {
             return NO_CHANGES;
         }
 
-        destinationPort = dp;
+        m_destinationPort = dp;
         return SUCCESS;
     }
 
 private:
-    ScicosID parentDiagram;
+    ScicosID m_parentDiagram;
 
-    ScicosID sourcePort;
-    ScicosID destinationPort;
+    ScicosID m_sourcePort;
+    ScicosID m_destinationPort;
 
     // used to store, user-defined control points
-    std::vector<double> controlPoints;
+    std::vector<double> m_controlPoints;
 
-    std::string label;
-    std::vector<double> thick;
-    int color;
-    link_kind_t linkKind;
+    std::string m_label;
+    std::vector<double> m_thick;
+    int m_color;
+    link_kind_t m_linkKind;
 
 };
 
index cf83d23..a6b487f 100644 (file)
@@ -31,34 +31,35 @@ enum portKind
 
 class Port: public BaseObject
 {
-    friend class ::org_scilab_modules_scicos::Model;
+public:
+    Port() : BaseObject(PORT), m_dataType(0), m_sourceBlock(0), m_kind(PORT_UNDEF), m_implicit(false),
+        m_style(), m_label(), m_firing(0), m_connectedSignals(std::vector<ScicosID> (1, 0)) {};
+    Port(const Port& o) : BaseObject(PORT), m_dataType(o.m_dataType), m_sourceBlock(o.m_sourceBlock), m_kind(o.m_kind), m_implicit(o.m_implicit),
+        m_style(o.m_style), m_label(o.m_label), m_firing(0), m_connectedSignals(o.m_connectedSignals) {};
+    ~Port() = default;
 
 private:
-    Port() : BaseObject(PORT), dataType(0), sourceBlock(0), kind(PORT_UNDEF), implicit(false),
-        style(), label(), firing(0), connectedSignals(std::vector<ScicosID> (1, 0)) {};
-    Port(const Port& o) : BaseObject(PORT), dataType(o.dataType), sourceBlock(o.sourceBlock), kind(o.kind), implicit(o.implicit),
-        style(o.style), label(o.label), firing(0), connectedSignals(o.connectedSignals) {};
-    ~Port() {};
+    friend class ::org_scilab_modules_scicos::Model;
 
     const std::vector<ScicosID>& getConnectedSignals() const
     {
-        return connectedSignals;
+        return m_connectedSignals;
     }
 
     update_status_t setConnectedSignals(const std::vector<ScicosID>& connectedSignals)
     {
-        if (this->connectedSignals == connectedSignals)
+        if (this->m_connectedSignals == connectedSignals)
         {
             return NO_CHANGES;
         }
 
-        this->connectedSignals = connectedSignals;
+        this->m_connectedSignals = connectedSignals;
         return SUCCESS;
     }
 
     void getDataType(std::vector<int>& v) const
     {
-        if (dataType == 0)
+        if (m_dataType == 0)
         {
             // By default, size is set to [-1,1] and type to real (1)
             v.resize(3, 1);
@@ -67,9 +68,9 @@ private:
         else
         {
             v.resize(3);
-            v[0] = dataType->rows;
-            v[1] = dataType->columns;
-            v[2] = dataType->datatype_id;
+            v[0] = m_dataType->rows;
+            v[1] = m_dataType->columns;
+            v[2] = m_dataType->datatype_id;
         }
     }
 
@@ -81,18 +82,18 @@ private:
         }
 
         model::Datatype datatype = model::Datatype(v);
-        if (this->dataType != 0 && *this->dataType == datatype)
+        if (this->m_dataType != 0 && *this->m_dataType == datatype)
         {
             return NO_CHANGES;
         }
 
-        this->dataType = model->flyweight(datatype);
+        this->m_dataType = model->flyweight(datatype);
         return SUCCESS;
     }
 
     void getKind(int& k) const
     {
-        k = kind;
+        k = m_kind;
     }
 
     update_status_t setKind(int k)
@@ -102,100 +103,100 @@ private:
             return FAIL;
         }
 
-        if (k == kind)
+        if (k == m_kind)
         {
             return NO_CHANGES;
         }
 
-        kind = static_cast<portKind>(k);
+        m_kind = static_cast<portKind>(k);
         return SUCCESS;
     }
 
     void getSourceBlock(ScicosID& sb) const
     {
-        sb = sourceBlock;
+        sb = m_sourceBlock;
     }
 
     update_status_t setSourceBlock(const ScicosID sb)
     {
-        if (sb == this->sourceBlock)
+        if (sb == this->m_sourceBlock)
         {
             return NO_CHANGES;
         }
-        this->sourceBlock = sb;
+        this->m_sourceBlock = sb;
         return SUCCESS;
     }
 
     void getImplicit(bool& v) const
     {
-        v = implicit;
+        v = m_implicit;
     }
 
     update_status_t setImplicit(bool implicit)
     {
-        if (implicit == this->implicit)
+        if (implicit == this->m_implicit)
         {
             return NO_CHANGES;
         }
-        this->implicit = implicit;
+        this->m_implicit = implicit;
         return SUCCESS;
     }
 
     void getStyle(std::string& s) const
     {
-        s = style;
+        s = m_style;
     }
 
     update_status_t setStyle(const std::string& style)
     {
-        if (style == this->style)
+        if (style == this->m_style)
         {
             return NO_CHANGES;
         }
-        this->style = style;
+        this->m_style = style;
         return SUCCESS;
     }
 
     void getLabel(std::string& l) const
     {
-        l = style;
+        l = m_style;
     }
 
     update_status_t setLabel(const std::string& label)
     {
-        if (label == this->label)
+        if (label == this->m_label)
         {
             return NO_CHANGES;
         }
-        this->label = label;
+        this->m_label = label;
         return SUCCESS;
     }
 
     void getFiring(double& f) const
     {
-        f = firing;
+        f = m_firing;
     }
 
     update_status_t setFiring(double firing)
     {
-        if (firing == this->firing)
+        if (firing == this->m_firing)
         {
             return NO_CHANGES;
         }
-        this->firing = firing;
+        this->m_firing = firing;
         return SUCCESS;
     }
 
 private:
-    Datatype* dataType;
-    ScicosID sourceBlock;
-    portKind kind;
-    bool implicit;
-    std::string style;
-    std::string label;
-    double firing;
-
-    std::vector<ScicosID> connectedSignals;
+    Datatype* m_dataType;
+    ScicosID m_sourceBlock;
+    portKind m_kind;
+    bool m_implicit;
+    std::string m_style;
+    std::string m_label;
+    double m_firing;
+
+    std::vector<ScicosID> m_connectedSignals;
 };
 
 } /* namespace model */
index 947a145..f023b21 100644 (file)
@@ -17,6 +17,7 @@
 #include <string>
 #include <vector>
 #include <sstream>
+#include <memory>
 
 #include "user.hxx"
 #include "internal.hxx"
@@ -99,13 +100,15 @@ class BaseAdapter : public types::UserType
 {
 
 public:
-    BaseAdapter(bool ownAdaptee, Adaptee* adaptee) : ownAdaptee(ownAdaptee), adaptee(adaptee) {};
-    virtual ~BaseAdapter()
+    BaseAdapter(std::shared_ptr<Adaptee> adaptee) : m_adaptee(adaptee) {};
+    BaseAdapter(const BaseAdapter& adapter) : m_adaptee(adapter.m_adaptee) {};
+    ~BaseAdapter()
     {
-        if (ownAdaptee)
+        // do not use adaptee.unique() as adaptee has not been destroyed yet
+        if (m_adaptee.use_count() == 2)
         {
             Controller controller;
-            controller.deleteObject(getAdaptee()->id());
+            controller.deleteObject(m_adaptee->id());
         }
     };
 
@@ -220,11 +223,11 @@ public:
     }
 
     /**
-     * @return the Adaptee instance
+     * @return the Adaptee
      */
-    Adaptee* getAdaptee() const
+    std::shared_ptr<Adaptee> getAdaptee() const
     {
-        return adaptee;
+        return m_adaptee;
     }
 
     /*
@@ -236,11 +239,12 @@ public:
 
 private:
 
-    virtual types::InternalType* clone()
+    types::InternalType* clone()
     {
         Controller controller = Controller();
-        ScicosID clone = controller.cloneObject(getAdaptee()->id());
-        return new Adaptor(false, static_cast<Adaptee*>(controller.getObject(clone)));
+        ScicosID id = controller.cloneObject(getAdaptee()->id());
+        std::shared_ptr<Adaptee> adaptee = std::static_pointer_cast<Adaptee>(controller.getObject(id));
+        return new Adaptor(adaptee);
     }
 
     /*
@@ -295,7 +299,7 @@ private:
 
     types::InternalType* insert(types::typed_list* _pArgs, InternalType* _pSource)
     {
-        for (int i = 0; i < _pArgs->size(); i++)
+        for (size_t i = 0; i < _pArgs->size(); i++)
         {
             if ((*_pArgs)[i]->isString())
             {
@@ -345,14 +349,8 @@ private:
         return true;
     }
 
-    bool getOwn()
-    {
-        return ownAdaptee;
-    };
-
 private:
-    const bool ownAdaptee;
-    Adaptee* adaptee;
+    std::shared_ptr<Adaptee> m_adaptee;
 };
 
 
index 50afe48..accc2fd 100644 (file)
@@ -41,13 +41,13 @@ struct graphics
 {
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
-        GraphicsAdapter localAdaptor = GraphicsAdapter(false, adaptor.getAdaptee());
+        GraphicsAdapter localAdaptor = GraphicsAdapter(adaptor.getAdaptee());
         return localAdaptor.getAsTList(new types::MList(), controller);
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        GraphicsAdapter localAdaptor = GraphicsAdapter(false, adaptor.getAdaptee());
+        GraphicsAdapter localAdaptor = GraphicsAdapter(adaptor.getAdaptee());
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -56,13 +56,13 @@ struct model
 {
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
-        ModelAdapter localAdaptor = ModelAdapter(false, adaptor.getAdaptee());
+        ModelAdapter localAdaptor = ModelAdapter(adaptor.getAdaptee());
         return localAdaptor.getAsTList(new types::MList(), controller);
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ModelAdapter localAdaptor = ModelAdapter(false, adaptor.getAdaptee());
+        ModelAdapter localAdaptor = ModelAdapter(adaptor.getAdaptee());
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -72,8 +72,8 @@ struct gui
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         std::string Interface;
-        org_scilab_modules_scicos::model::Block* adaptee = adaptor.getAdaptee();
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), INTERFACE_FUNCTION, Interface);
+        ScicosID adaptee = adaptor.getAdaptee()->id();
+        controller.getObjectProperty(adaptee, BLOCK, INTERFACE_FUNCTION, Interface);
 
         return new types::String(Interface.data());
     }
@@ -96,8 +96,8 @@ struct gui
         std::string stName(name);
         FREE(name);
 
-        org_scilab_modules_scicos::model::Block* adaptee = adaptor.getAdaptee();
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), INTERFACE_FUNCTION, stName);
+        ScicosID adaptee = adaptor.getAdaptee()->id();
+        controller.setObjectProperty(adaptee, BLOCK, INTERFACE_FUNCTION, stName);
         return true;
     }
 };
@@ -126,8 +126,9 @@ struct doc
 
 template<> property<BlockAdapter>::props_t property<BlockAdapter>::fields = property<BlockAdapter>::props_t();
 
-BlockAdapter::BlockAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee) :
-    BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>(ownAdaptee, adaptee)
+BlockAdapter::BlockAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Block> adaptee) :
+    doc_content(new types::List()),
+    BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>(adaptee)
 {
     if (property<BlockAdapter>::properties_have_not_been_set())
     {
@@ -137,13 +138,18 @@ BlockAdapter::BlockAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Bl
         property<BlockAdapter>::add_property(L"gui", &gui::get, &gui::set);
         property<BlockAdapter>::add_property(L"doc", &doc::get, &doc::set);
     }
+}
 
-    doc_content = new types::List();
+BlockAdapter::BlockAdapter(const BlockAdapter& adapter) :
+    doc_content(adapter.getDocContent()),
+    BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>(adapter)
+{
 }
 
 BlockAdapter::~BlockAdapter()
 {
-    delete doc_content;
+    doc_content->DecreaseRef();
+    doc_content->killMe();
 }
 
 std::wstring BlockAdapter::getTypeStr()
@@ -157,13 +163,17 @@ std::wstring BlockAdapter::getShortTypeStr()
 
 types::InternalType* BlockAdapter::getDocContent() const
 {
-    return doc_content->clone();
+    doc_content->IncreaseRef();
+    return doc_content;
 }
 
 void BlockAdapter::setDocContent(types::InternalType* v)
 {
-    delete doc_content;
-    doc_content = v->clone();
+    doc_content->DecreaseRef();
+    doc_content->killMe();
+
+    v->IncreaseRef();
+    doc_content = v;
 }
 
 } /* namespace view_scilab */
index 45295e3..d410f22 100644 (file)
@@ -27,7 +27,8 @@ namespace view_scilab
 class BlockAdapter : public BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>
 {
 public:
-    BlockAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee);
+    BlockAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Block> adaptee);
+    BlockAdapter(const BlockAdapter& adapter);
     ~BlockAdapter();
 
     static const std::wstring getSharedTypeStr()
@@ -40,6 +41,7 @@ public:
 
     types::InternalType* getDocContent() const;
     void setDocContent(types::InternalType* v);
+
 private:
     types::InternalType* doc_content;
 };
index e80fcc7..e20ec64 100644 (file)
@@ -31,8 +31,8 @@ namespace
 
 template<> property<CprAdapter>::props_t property<CprAdapter>::fields = property<CprAdapter>::props_t();
 
-CprAdapter::CprAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
-    BaseAdapter<CprAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
+CprAdapter::CprAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee) :
+    BaseAdapter<CprAdapter, org_scilab_modules_scicos::model::Diagram>(adaptee)
 {
     if (property<CprAdapter>::properties_have_not_been_set())
     {
@@ -40,6 +40,11 @@ CprAdapter::CprAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagra
     }
 }
 
+CprAdapter::CprAdapter(const CprAdapter& adapter) :
+    BaseAdapter<CprAdapter, org_scilab_modules_scicos::model::Diagram>(adapter)
+{
+}
+
 CprAdapter::~CprAdapter()
 {
 }
index 090acb0..bcfd89b 100644 (file)
@@ -27,7 +27,8 @@ namespace view_scilab
 class CprAdapter : public BaseAdapter<CprAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    CprAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
+    CprAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee);
+    CprAdapter(const CprAdapter& adapter);
     ~CprAdapter();
 
     static const std::wstring getSharedTypeStr()
index 69b3a12..e53dee5 100644 (file)
@@ -49,13 +49,13 @@ struct props
 
     static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
-        ParamsAdapter localAdaptor = ParamsAdapter(false, adaptor.getAdaptee());
+        ParamsAdapter localAdaptor = ParamsAdapter(adaptor.getAdaptee());
         return localAdaptor.getAsTList(new types::TList(), controller);
     }
 
     static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ParamsAdapter localAdaptor = ParamsAdapter(false, adaptor.getAdaptee());
+        ParamsAdapter localAdaptor = ParamsAdapter(adaptor.getAdaptee());
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -66,10 +66,10 @@ struct objs
     static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
         // FIXME: get all children of the Diagram and return them as a list
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        model::Diagram* adaptee = adaptor.getAdaptee().get();
 
         std::vector<ScicosID> children;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, children);
+        controller.getObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, children);
 
         types::List* o = new types::List();
 
@@ -77,35 +77,35 @@ struct objs
         Controller newController = Controller();
         for (int i = 0; i < static_cast<int>(children.size()); ++i)
         {
-            model::BaseObject* item = newController.getObject(children[i]);
+            model::BaseObject* item = newController.getObject(children[i]).get();
             switch (item->kind())
             {
                 case ANNOTATION:
                 {
                     model::Annotation* annotation = static_cast<model::Annotation*>(item);
-                    TextAdapter* localAdaptor = new TextAdapter(false, annotation);
+                    TextAdapter* localAdaptor = new TextAdapter(std::shared_ptr<model::Annotation>(annotation));
                     o->set(i, localAdaptor);
                     continue;
                 }
                 case BLOCK:
                 {
                     model::Block* block = static_cast<model::Block*>(item);
-                    BlockAdapter* localAdaptor = new BlockAdapter(false, block);
+                    BlockAdapter* localAdaptor = new BlockAdapter(std::shared_ptr<model::Block>(block));
                     o->set(i, localAdaptor);
                     continue;
                 }
                 case LINK:
                 {
                     model::Link* link = static_cast<model::Link*>(item);
-                    LinkAdapter* localAdaptor = new LinkAdapter(false, link);
+                    LinkAdapter* localAdaptor = new LinkAdapter(std::shared_ptr<model::Link>(link));
 
                     // In case a Link points to a Block that has not been added yet,
                     // retrieve the 'from' and 'to' values from the Diagram Adapter if they have been saved,
                     // without updating the model
                     if (adaptor.getFromSize() != 0)
                     {
-                        localAdaptor->setFrom(link->id(), adaptor.getFrom(link_number), newController, false);
-                        localAdaptor->setTo(link->id(), adaptor.getTo(link_number), newController, false);
+                        localAdaptor->setFrom(children[i], adaptor.getFrom(link_number), newController, false);
+                        localAdaptor->setTo(children[i], adaptor.getTo(link_number), newController, false);
                         link_number++;
                     }
                     o->set(i, localAdaptor);
@@ -126,14 +126,14 @@ struct objs
             return false;
         }
 
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        model::Diagram* adaptee = adaptor.getAdaptee().get();
 
         types::List* list = v->getAs<types::List>();
 
         // Clear the children list before the loop to reset the diagram children
         // and clear the old Links information
         std::vector<ScicosID> diagramChildren;
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, diagramChildren);
+        controller.setObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, diagramChildren);
         adaptor.clearFrom();
         adaptor.clearTo();
         std::vector<LinkAdapter*> linkListView;
@@ -156,45 +156,45 @@ struct objs
                 case Adapters::BLOCK_ADAPTER:
                 {
                     BlockAdapter* modelElement = list->get(i)->getAs<BlockAdapter>();
-                    model::Block* subAdaptee = modelElement->getAdaptee();
+                    model::Block* subAdaptee = modelElement->getAdaptee().get();
 
                     id = subAdaptee->id();
 
-                    controller.setObjectProperty(id, subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
-                    controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, diagramChildren);
+                    controller.setObjectProperty(id, BLOCK, PARENT_DIAGRAM, adaptee);
+                    controller.getObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, diagramChildren);
                     diagramChildren.push_back(id);
-                    controller.setObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, diagramChildren);
+                    controller.setObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, diagramChildren);
                     break;
                 }
                 case Adapters::LINK_ADAPTER:
                 {
                     LinkAdapter* modelElement = list->get(i)->getAs<LinkAdapter>();
-                    model::Link* subAdaptee = modelElement->getAdaptee();
+                    model::Link* subAdaptee = modelElement->getAdaptee().get();
 
                     id = subAdaptee->id();
 
-                    controller.setObjectProperty(id, subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
+                    controller.setObjectProperty(id, LINK, PARENT_DIAGRAM, adaptee);
 
                     // Hold Links information, to try the linking at model-level once all the elements have been added to the Diagram
                     linkListView.push_back(modelElement);
                     linkListModel.push_back(id);
 
-                    controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, diagramChildren);
+                    controller.getObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, diagramChildren);
                     diagramChildren.push_back(id);
-                    controller.setObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, diagramChildren);
+                    controller.setObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, diagramChildren);
                     break;
                 }
                 case Adapters::TEXT_ADAPTER:
                 {
                     TextAdapter* modelElement = list->get(i)->getAs<TextAdapter>();
-                    model::Annotation* subAdaptee = modelElement->getAdaptee();
+                    model::Annotation* subAdaptee = modelElement->getAdaptee().get();
 
                     id = subAdaptee->id();
 
-                    controller.setObjectProperty(id, subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
-                    controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, diagramChildren);
+                    controller.setObjectProperty(id, ANNOTATION, PARENT_DIAGRAM, adaptee->id());
+                    controller.getObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, diagramChildren);
                     diagramChildren.push_back(id);
-                    controller.setObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, diagramChildren);
+                    controller.setObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, diagramChildren);
                     break;
                 }
                 default:
@@ -229,10 +229,10 @@ struct version
 
     static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        model::Diagram* adaptee = adaptor.getAdaptee().get();
 
         std::string version;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
+        controller.getObjectProperty(adaptee->id(), DIAGRAM, VERSION_NUMBER, version);
 
         return new types::String(version.data());
     }
@@ -247,13 +247,13 @@ struct version
                 return false;
             }
 
-            model::Diagram* adaptee = adaptor.getAdaptee();
+            model::Diagram* adaptee = adaptor.getAdaptee().get();
 
             char* c_str = wide_string_to_UTF8(current->get(0));
             std::string version (c_str);
             FREE(c_str);
 
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
+            controller.setObjectProperty(adaptee->id(), DIAGRAM, VERSION_NUMBER, version);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabDouble)
@@ -264,10 +264,10 @@ struct version
                 return false;
             }
 
-            model::Diagram* adaptee = adaptor.getAdaptee();
+            model::Diagram* adaptee = adaptor.getAdaptee().get();
 
             std::string version;
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
+            controller.setObjectProperty(adaptee->id(), DIAGRAM, VERSION_NUMBER, version);
             return true;
         }
 
@@ -301,8 +301,8 @@ struct contrib
 
 template<> property<DiagramAdapter>::props_t property<DiagramAdapter>::fields = property<DiagramAdapter>::props_t();
 
-DiagramAdapter::DiagramAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
-    BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
+DiagramAdapter::DiagramAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee) :
+    BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(adaptee)
 {
     if (property<DiagramAdapter>::properties_have_not_been_set())
     {
@@ -316,6 +316,17 @@ DiagramAdapter::DiagramAdapter(bool ownAdaptee, org_scilab_modules_scicos::model
     contrib_content = new types::List();
 }
 
+DiagramAdapter::DiagramAdapter(const DiagramAdapter& adapter) :
+    BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(adapter)
+{
+    // When cloning a DiagramAdapter, clone its Links information as well
+    for (int i = 0; i < static_cast<int>(from_vec.size()); ++i)
+    {
+        setFrom(adapter.getFrom(i));
+        setTo(adapter.getTo(i));
+    }
+}
+
 DiagramAdapter::~DiagramAdapter()
 {
     delete contrib_content;
@@ -376,20 +387,5 @@ void DiagramAdapter::clearTo()
     to_vec.clear();
 }
 
-types::InternalType* DiagramAdapter::clone()
-{
-    Controller controller = Controller();
-    ScicosID clone = controller.cloneObject(getAdaptee()->id());
-    DiagramAdapter* ret = new DiagramAdapter(false, static_cast<org_scilab_modules_scicos::model::Diagram*>(controller.getObject(clone)));
-
-    // When cloning a DiagramAdapter, clone its Links information as well
-    for (int i = 0; i < static_cast<int>(from_vec.size()); ++i)
-    {
-        ret->setFrom(getFrom(i));
-        ret->setTo(getTo(i));
-    }
-    return ret;
-}
-
 } /* namespace view_scilab */
 } /* namespace org_scilab_modules_scicos */
index 3a2e24e..bcda6af 100644 (file)
@@ -27,7 +27,8 @@ namespace view_scilab
 class DiagramAdapter : public BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    DiagramAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
+    DiagramAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee);
+    DiagramAdapter(const DiagramAdapter& adapter);
     ~DiagramAdapter();
 
     static const std::wstring getSharedTypeStr()
@@ -37,7 +38,6 @@ public:
 
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
-    types::InternalType* clone();
 
     types::InternalType* getContribContent() const;
     void setContribContent(types::InternalType* v);
index 7a4920e..b6cbf4e 100644 (file)
@@ -41,10 +41,10 @@ struct orig
     {
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
 
         data[0] = geom[0];
         data[1] = geom[1];
@@ -66,14 +66,14 @@ struct orig
             return false;
         }
 
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
 
         geom[0] = current->get(0);
         geom[1] = current->get(1);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.setObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
         return true;
     }
 };
@@ -85,10 +85,10 @@ struct sz
     {
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
 
         data[0] = geom[2];
         data[1] = geom[3];
@@ -108,14 +108,14 @@ struct sz
             return false;
         }
 
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
 
         geom[2] = current->get(0);
         geom[3] = current->get(1);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.setObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
         return true;
     }
 };
@@ -127,10 +127,10 @@ struct flip
     {
         int* data;
         types::Bool* o = new types::Bool(1, 1, &data);
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> angle;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
 
         data[0] = static_cast<int>(angle[0]);
         return o;
@@ -149,13 +149,13 @@ struct flip
             return false;
         }
 
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
         std::vector<double> angle;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
 
         angle[0] = (current->get(0) == false) ? 0 : 1;
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.setObjectProperty(adaptee, BLOCK, ANGLE, angle);
         return true;
     }
 };
@@ -167,10 +167,10 @@ struct theta
     {
         double* data;
         types::Double* o = new types::Double(1, 1, &data);
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> angle;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
 
         data[0] = angle[1];
         return o;
@@ -189,13 +189,13 @@ struct theta
             return false;
         }
 
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
         std::vector<double> angle;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
 
         angle[1] = current->get(0);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        controller.setObjectProperty(adaptee, BLOCK, ANGLE, angle);
         return true;
     }
 };
@@ -205,10 +205,10 @@ struct exprs
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<std::string> exprs;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+        controller.getObjectProperty(adaptee, BLOCK, EXPRS, exprs);
 
         types::String* o = new types::String((int)exprs.size(), 1);
         for (int i = 0; i < (int)exprs.size(); ++i)
@@ -221,7 +221,7 @@ struct exprs
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() == types::InternalType::ScilabString)
         {
@@ -239,7 +239,7 @@ struct exprs
                 FREE(c_str);
             }
 
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+            controller.setObjectProperty(adaptee, BLOCK, EXPRS, exprs);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabDouble)
@@ -251,13 +251,13 @@ struct exprs
             }
 
             std::vector<std::string> exprs;
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+            controller.setObjectProperty(adaptee, BLOCK, EXPRS, exprs);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabList)
         {
             std::vector<std::string> exprs;
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+            controller.setObjectProperty(adaptee, BLOCK, EXPRS, exprs);
             return true;
         }
         return false;
@@ -346,10 +346,10 @@ struct id
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string id;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), LABEL, id);
+        controller.getObjectProperty(adaptee, BLOCK, LABEL, id);
 
         types::String* o = new types::String(1, 1);
         o->set(0, id.data());
@@ -370,14 +370,14 @@ struct id
             return false;
         }
 
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string id;
         char* c_str = wide_string_to_UTF8(current->get(0));
         id = std::string(c_str);
         FREE(c_str);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), LABEL, id);
+        controller.setObjectProperty(adaptee, BLOCK, LABEL, id);
         return true;
     }
 };
@@ -471,17 +471,17 @@ struct style
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string style;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
+        controller.getObjectProperty(adaptee, BLOCK, STYLE, style);
 
         return new types::String(style.c_str());
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
         if (v->getType() == types::InternalType::ScilabString)
         {
             types::String* current = v->getAs<types::String>();
@@ -495,7 +495,7 @@ struct style
             style = std::string(c_str);
             FREE(c_str);
 
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
+            controller.setObjectProperty(adaptee, BLOCK, STYLE, style);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabDouble)
@@ -507,7 +507,7 @@ struct style
             }
 
             std::string style;
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
+            controller.setObjectProperty(adaptee, BLOCK, STYLE, style);
             return true;
         }
         return false;
@@ -518,8 +518,9 @@ struct style
 
 template<> property<GraphicsAdapter>::props_t property<GraphicsAdapter>::fields = property<GraphicsAdapter>::props_t();
 
-GraphicsAdapter::GraphicsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee) :
-    BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(ownAdaptee, adaptee)
+GraphicsAdapter::GraphicsAdapter(std::shared_ptr<model::Block> adaptee) :
+    gr_i_content(types::Double::Empty()),
+    BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(adaptee)
 {
     if (property<GraphicsAdapter>::properties_have_not_been_set())
     {
@@ -543,13 +544,18 @@ GraphicsAdapter::GraphicsAdapter(bool ownAdaptee, org_scilab_modules_scicos::mod
         property<GraphicsAdapter>::add_property(L"out_label", &out_label::get, &out_label::set);
         property<GraphicsAdapter>::add_property(L"style", &style::get, &style::set);
     }
+}
 
-    gr_i_content = types::Double::Empty();
+GraphicsAdapter::GraphicsAdapter(const GraphicsAdapter& adapter) :
+    gr_i_content(adapter.getGrIContent()),
+    BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(adapter)
+{
 }
 
 GraphicsAdapter::~GraphicsAdapter()
 {
-    delete gr_i_content;
+    gr_i_content->DecreaseRef();
+    gr_i_content->killMe();
 }
 
 std::wstring GraphicsAdapter::getTypeStr()
@@ -564,13 +570,17 @@ std::wstring GraphicsAdapter::getShortTypeStr()
 
 types::InternalType* GraphicsAdapter::getGrIContent() const
 {
-    return gr_i_content->clone();
+    gr_i_content->IncreaseRef();
+    return gr_i_content;
 }
 
 void GraphicsAdapter::setGrIContent(types::InternalType* v)
 {
-    delete gr_i_content;
-    gr_i_content = v->clone();
+    gr_i_content->DecreaseRef();
+    gr_i_content->killMe();
+
+    v->IncreaseRef();
+    gr_i_content = v;
 }
 
 } /* namespace view_scilab */
index 19555fe..341c4dc 100644 (file)
@@ -26,7 +26,8 @@ namespace view_scilab
 class GraphicsAdapter : public BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>
 {
 public:
-    GraphicsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee);
+    GraphicsAdapter(std::shared_ptr<model::Block> adaptee);
+    GraphicsAdapter(const GraphicsAdapter& adapter);
     ~GraphicsAdapter();
 
     static const std::wstring getSharedTypeStr()
index f9cc811..8cd9934 100644 (file)
@@ -47,10 +47,10 @@ struct xx
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> controlPoints;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CONTROL_POINTS, controlPoints);
+        controller.getObjectProperty(adaptee, LINK, CONTROL_POINTS, controlPoints);
 
         double* data;
         int size = (int)controlPoints.size() / 2;
@@ -66,7 +66,7 @@ struct xx
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -76,7 +76,7 @@ struct xx
         types::Double* current = v->getAs<types::Double>();
 
         std::vector<double> controlPoints;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CONTROL_POINTS, controlPoints);
+        controller.getObjectProperty(adaptee, LINK, CONTROL_POINTS, controlPoints);
 
         int newXSize = current->getSize();
         int oldXSize = static_cast<int>(controlPoints.size() / 2);
@@ -94,7 +94,7 @@ struct xx
             std::copy(controlPoints.begin() + oldXSize, controlPoints.begin() + oldXSize + std::min(newXSize, oldXSize), newControlPoints.begin() + newXSize);
         }
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), CONTROL_POINTS, newControlPoints);
+        controller.setObjectProperty(adaptee, LINK, CONTROL_POINTS, newControlPoints);
         return true;
     }
 };
@@ -104,10 +104,10 @@ struct yy
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> controlPoints;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CONTROL_POINTS, controlPoints);
+        controller.getObjectProperty(adaptee, LINK, CONTROL_POINTS, controlPoints);
 
         double* data;
         int size = (int)controlPoints.size() / 2;
@@ -123,7 +123,7 @@ struct yy
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -133,7 +133,7 @@ struct yy
         types::Double* current = v->getAs<types::Double>();
 
         std::vector<double> controlPoints;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CONTROL_POINTS, controlPoints);
+        controller.getObjectProperty(adaptee, LINK, CONTROL_POINTS, controlPoints);
 
         int newYSize = current->getSize();
         int oldYSize = static_cast<int>(controlPoints.size() / 2);
@@ -154,7 +154,7 @@ struct yy
             }
         }
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), CONTROL_POINTS, newControlPoints);
+        controller.setObjectProperty(adaptee, LINK, CONTROL_POINTS, newControlPoints);
         return true;
     }
 };
@@ -164,10 +164,10 @@ struct id
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string id;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), LABEL, id);
+        controller.getObjectProperty(adaptee, LINK, LABEL, id);
 
         types::String* o = new types::String(1, 1);
         o->set(0, id.data());
@@ -188,14 +188,14 @@ struct id
             return false;
         }
 
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string id;
         char* c_str = wide_string_to_UTF8(current->get(0));
         id = std::string(c_str);
         FREE(c_str);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), LABEL, id);
+        controller.setObjectProperty(adaptee, LINK, LABEL, id);
         return true;
     }
 };
@@ -205,10 +205,10 @@ struct thick
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> thick;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), THICK, thick);
+        controller.getObjectProperty(adaptee, LINK, THICK, thick);
 
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
@@ -220,7 +220,7 @@ struct thick
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -237,7 +237,7 @@ struct thick
         thick[0] = current->get(0);
         thick[1] = current->get(1);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), THICK, thick);
+        controller.setObjectProperty(adaptee, LINK, THICK, thick);
         return true;
     }
 };
@@ -247,12 +247,12 @@ struct ct
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         int color;
         int kind;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), COLOR, color);
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), KIND, kind);
+        controller.getObjectProperty(adaptee, LINK, COLOR, color);
+        controller.getObjectProperty(adaptee, LINK, KIND, kind);
 
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
@@ -264,7 +264,7 @@ struct ct
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -284,15 +284,15 @@ struct ct
         int color = static_cast<int>(current->get(0));
         int kind  = static_cast<int>(current->get(1));
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), COLOR, color);
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), KIND, kind);
+        controller.setObjectProperty(adaptee, LINK, COLOR, color);
+        controller.setObjectProperty(adaptee, LINK, KIND, kind);
         return true;
     }
 };
 
 types::Double* getLinkEnd(const LinkAdapter& adaptor, const Controller& controller, const object_properties_t end)
 {
-    model::Link* adaptee = adaptor.getAdaptee();
+    ScicosID adaptee = adaptor.getAdaptee()->id();
 
     double* data;
     types::Double* o = new types::Double(1, 3, &data);
@@ -301,7 +301,7 @@ types::Double* getLinkEnd(const LinkAdapter& adaptor, const Controller& controll
     data[2] = 0;
 
     ScicosID endID;
-    controller.getObjectProperty(adaptee->id(), adaptee->kind(), end, endID);
+    controller.getObjectProperty(adaptee, LINK, end, endID);
     if (endID != 0)
     {
         ScicosID sourceBlock;
@@ -309,7 +309,7 @@ types::Double* getLinkEnd(const LinkAdapter& adaptor, const Controller& controll
 
         // Looking for the block number among the block IDs
         ScicosID parentDiagram;
-        controller.getObjectProperty(adaptee->id(), BLOCK, PARENT_DIAGRAM, parentDiagram);
+        controller.getObjectProperty(adaptee, BLOCK, PARENT_DIAGRAM, parentDiagram);
         std::vector<ScicosID> children;
         if (parentDiagram == 0)
         {
@@ -674,7 +674,7 @@ struct from
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -699,7 +699,7 @@ struct from
             from_content[2] = current->get(2);
         }
 
-        return adaptor.setFrom(adaptee->id(), from_content, controller);
+        return adaptor.setFrom(adaptee, from_content, controller);
     }
 };
 
@@ -724,7 +724,7 @@ struct to
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Link* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -750,7 +750,7 @@ struct to
             to_content[2] = current->get(2);
         }
 
-        return adaptor.setTo(adaptee->id(), to_content, controller);
+        return adaptor.setTo(adaptee, to_content, controller);
     }
 };
 
@@ -758,8 +758,8 @@ struct to
 
 template<> property<LinkAdapter>::props_t property<LinkAdapter>::fields = property<LinkAdapter>::props_t();
 
-LinkAdapter::LinkAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Link* adaptee) :
-    BaseAdapter<LinkAdapter, org_scilab_modules_scicos::model::Link>(ownAdaptee, adaptee)
+LinkAdapter::LinkAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Link> adaptee) :
+    BaseAdapter<LinkAdapter, org_scilab_modules_scicos::model::Link>(adaptee)
 {
     if (property<LinkAdapter>::properties_have_not_been_set())
     {
@@ -788,6 +788,17 @@ LinkAdapter::LinkAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Link
     to_content[2]   = modelTo->get(2);
 }
 
+LinkAdapter::LinkAdapter(const LinkAdapter& adapter) :
+    BaseAdapter<LinkAdapter, org_scilab_modules_scicos::model::Link>(adapter)
+{
+    Controller controller;
+
+    // When cloning a LinkAdapter, clone its 'from' and 'to' information as well.
+    // setFrom() will propagate the information at model-level if necessary.
+    setFrom(getAdaptee()->id(), adapter.getFrom(), controller);
+    setTo(getAdaptee()->id(), adapter.getTo(), controller);
+}
+
 LinkAdapter::~LinkAdapter()
 {
 }
@@ -891,18 +902,5 @@ bool LinkAdapter::setTo(const ScicosID id, const std::vector<double>& v, Control
     return true;
 }
 
-types::InternalType* LinkAdapter::clone()
-{
-    Controller controller = Controller();
-    ScicosID clone = controller.cloneObject(getAdaptee()->id());
-    LinkAdapter* ret = new LinkAdapter(false, static_cast<org_scilab_modules_scicos::model::Link*>(controller.getObject(clone)));
-
-    // When cloning a LinkAdapter, clone its 'from' and 'to' information as well.
-    // setFrom() will propagate the information at model-level if necessary.
-    ret->setFrom(clone, this->getFrom(), controller);
-    ret->setTo(clone, this->getTo(), controller);
-    return ret;
-}
-
 } /* namespace view_scilab */
 } /* namespace org_scilab_modules_scicos */
index 5545b94..bf763d2 100644 (file)
@@ -27,7 +27,8 @@ namespace view_scilab
 class LinkAdapter : public BaseAdapter<LinkAdapter, org_scilab_modules_scicos::model::Link>
 {
 public:
-    LinkAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Link* adaptee);
+    LinkAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Link> adaptee);
+    LinkAdapter(const LinkAdapter& adapter);
     ~LinkAdapter();
 
     static const std::wstring getSharedTypeStr()
@@ -37,7 +38,6 @@ public:
 
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
-    types::InternalType* clone();
 
     std::vector<double> getFrom() const;
     bool setFrom(const ScicosID id, const std::vector<double>& v, Controller& controller, const bool model_level = true);
index 9d2b055..b92f8de 100644 (file)
@@ -53,17 +53,17 @@ struct sim
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         // First, extract the function Name
         std::string name;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), SIM_FUNCTION_NAME, name);
+        controller.getObjectProperty(adaptee, BLOCK, SIM_FUNCTION_NAME, name);
         types::String* Name = new types::String(1, 1);
         Name->set(0, name.data());
 
         // Then the Api. If it is zero, then just return the Name. Otherwise, return a list containing both.
         int api;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), SIM_FUNCTION_API, api);
+        controller.getObjectProperty(adaptee, BLOCK, SIM_FUNCTION_API, api);
 
         if (api == 0)
         {
@@ -81,7 +81,7 @@ struct sim
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() == types::InternalType::ScilabString)
         {
@@ -98,8 +98,8 @@ struct sim
             // If the input is a scalar string, then the functionApi is 0.
             int api = 0;
 
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_FUNCTION_NAME, name);
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_FUNCTION_API, api);
+            controller.setObjectProperty(adaptee, BLOCK, SIM_FUNCTION_NAME, name);
+            controller.setObjectProperty(adaptee, BLOCK, SIM_FUNCTION_API, api);
         }
         else if (v->getType() == types::InternalType::ScilabList)
         {
@@ -135,8 +135,8 @@ struct sim
             }
             int api_int = static_cast<int>(api);
 
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_FUNCTION_NAME, name);
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_FUNCTION_API, api_int);
+            controller.setObjectProperty(adaptee, BLOCK, SIM_FUNCTION_NAME, name);
+            controller.setObjectProperty(adaptee, BLOCK, SIM_FUNCTION_API, api_int);
         }
         else
         {
@@ -263,10 +263,10 @@ struct state
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> state;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), STATE, state);
+        controller.getObjectProperty(adaptee, BLOCK, STATE, state);
 
         double* data;
         types::Double* o = new types::Double((int)state.size(), 1, &data);
@@ -293,12 +293,12 @@ struct state
             return false;
         }
 
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> state (current->getSize());
         std::copy(current->getReal(), current->getReal() + current->getSize(), state.begin());
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), STATE, state);
+        controller.setObjectProperty(adaptee, BLOCK, STATE, state);
         return true;
     }
 };
@@ -308,10 +308,10 @@ struct dstate
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> dstate;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), DSTATE, dstate);
+        controller.getObjectProperty(adaptee, BLOCK, DSTATE, dstate);
 
         double* data;
         types::Double* o = new types::Double((int)dstate.size(), 1, &data);
@@ -326,7 +326,7 @@ struct dstate
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() == types::InternalType::ScilabString)
         {
@@ -337,7 +337,7 @@ struct dstate
             }
 
             std::vector<double> dstate;
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), DSTATE, dstate);
+            controller.setObjectProperty(adaptee, BLOCK, DSTATE, dstate);
             return true;
         }
 
@@ -354,17 +354,17 @@ struct dstate
         std::vector<double> dstate (current->getSize());
         std::copy(current->getReal(), current->getReal() + current->getSize(), dstate.begin());
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), DSTATE, dstate);
+        controller.setObjectProperty(adaptee, BLOCK, DSTATE, dstate);
         return true;
     }
 };
 
 types::InternalType* getPropList(const ModelAdapter& adaptor, const Controller& controller, const object_properties_t prop)
 {
-    model::Block* adaptee = adaptor.getAdaptee();
+    ScicosID adaptee = adaptor.getAdaptee()->id();
 
     std::vector<int> prop_content;
-    controller.getObjectProperty(adaptee->id(), adaptee->kind(), prop, prop_content);
+    controller.getObjectProperty(adaptee, BLOCK, prop, prop_content);
 
     if (prop_content.empty())
     {
@@ -530,7 +530,7 @@ types::InternalType* getPropList(const ModelAdapter& adaptor, const Controller&
 
 bool setPropList(ModelAdapter& adaptor, Controller& controller, const object_properties_t prop, types::InternalType* v)
 {
-    model::Block* adaptee = adaptor.getAdaptee();
+    ScicosID adaptee = adaptor.getAdaptee()->id();
 
     if (v->getType() == types::InternalType::ScilabDouble)
     {
@@ -541,7 +541,7 @@ bool setPropList(ModelAdapter& adaptor, Controller& controller, const object_pro
         }
 
         std::vector<int> prop_content;
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), prop, prop_content);
+        controller.setObjectProperty(adaptee, BLOCK, prop, prop_content);
         return true;
     }
 
@@ -735,7 +735,7 @@ bool setPropList(ModelAdapter& adaptor, Controller& controller, const object_pro
         index += 3 + numberOfIntNeeded;
     }
 
-    controller.setObjectProperty(adaptee->id(), adaptee->kind(), prop, prop_content);
+    controller.setObjectProperty(adaptee, BLOCK, prop, prop_content);
     return true;
 }
 
@@ -759,7 +759,7 @@ struct odstate
  */
 bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& children, Controller& controller)
 {
-    model::Block* adaptee = adaptor.getAdaptee();
+    ScicosID adaptee = adaptor.getAdaptee()->id();
 
     for (std::vector<ScicosID>::const_iterator it = children.begin(); it != children.end(); ++it)
     {
@@ -808,7 +808,7 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
                 }
 
                 std::vector<ScicosID> superPorts;
-                controller.getObjectProperty(adaptee->id(), adaptee->kind(), kind, superPorts);
+                controller.getObjectProperty(adaptee, BLOCK, kind, superPorts);
                 if (static_cast<int>(superPorts.size()) < portIndex)
                 {
                     return false;
@@ -838,7 +838,7 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
             }
 
             // Regardless of the ports, use the loop to set each Block's 'parent_block' property
-            controller.setObjectProperty(*it, BLOCK, PARENT_BLOCK, adaptee->id());
+            controller.setObjectProperty(*it, BLOCK, PARENT_BLOCK, adaptee);
         }
     }
     return true;
@@ -849,15 +849,15 @@ struct rpar
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<ScicosID> children;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, children);
+        controller.getObjectProperty(adaptee, BLOCK, CHILDREN, children);
 
         if (children.empty())
         {
             std::vector<double> rpar;
-            controller.getObjectProperty(adaptee->id(), adaptee->kind(), RPAR, rpar);
+            controller.getObjectProperty(adaptee, BLOCK, RPAR, rpar);
 
             double *data;
             types::Double* o = new types::Double((int)rpar.size(), 1, &data);
@@ -870,15 +870,15 @@ struct rpar
         }
         else // SuperBlock, return the contained diagram, whose ID is stored in children[0]
         {
-            model::Diagram* diagram = static_cast<model::Diagram*>(Controller().getObject(children[0]));
-            DiagramAdapter* o = new DiagramAdapter(false, diagram);
-            return o;
+            // FIXME : leak memory
+            model::Diagram* super = static_cast<model::Diagram*>(controller.getObject(children[0]).get());
+            return new DiagramAdapter(std::shared_ptr<model::Diagram>(super));
         }
     }
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() == types::InternalType::ScilabDouble)
         {
@@ -890,7 +890,7 @@ struct rpar
                 rpar[i] = current->get(i);
             }
 
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), RPAR, rpar);
+            controller.setObjectProperty(adaptee, BLOCK, RPAR, rpar);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabString)
@@ -910,14 +910,12 @@ struct rpar
             // Translate 'v' to an DiagramAdapter and clone it, updating the new Diagram's children
             DiagramAdapter* diagram = v->getAs<DiagramAdapter>();
             ScicosID clone = controller.cloneObject(diagram->getAdaptee()->id());
-            model::Diagram* newSubAdaptee = static_cast<model::Diagram*>(controller.getObject(clone));
-            DiagramAdapter* newDiagram = new DiagramAdapter(true, newSubAdaptee);
 
             // Save the children list, adding the new diagram ID at the beginning
             std::vector<ScicosID> children;
-            controller.getObjectProperty(newSubAdaptee->id(), newSubAdaptee->kind(), CHILDREN, children);
-            children.insert(children.begin(), newSubAdaptee->id());
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, children);
+            controller.getObjectProperty(clone, DIAGRAM, CHILDREN, children);
+            children.insert(children.begin(), clone);
+            controller.setObjectProperty(adaptee, DIAGRAM, CHILDREN, children);
 
             // Link the Superblock ports to their inner "port blocks"
             return setInnerBlocksRefs(adaptor, children, controller);
@@ -939,10 +937,10 @@ struct ipar
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<int> ipar;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), IPAR, ipar);
+        controller.getObjectProperty(adaptee, BLOCK, IPAR, ipar);
 
         double *data;
         types::Double* o = new types::Double((int)ipar.size(), 1, &data);
@@ -957,12 +955,12 @@ struct ipar
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() == types::InternalType::ScilabList)
         {
             std::vector<int> ipar;
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), IPAR, ipar);
+            controller.setObjectProperty(adaptee, BLOCK, IPAR, ipar);
             return true;
         }
 
@@ -987,7 +985,7 @@ struct ipar
             ipar[i] = static_cast<int>(current->get(i));
         }
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), IPAR, ipar);
+        controller.setObjectProperty(adaptee, BLOCK, IPAR, ipar);
         return true;
     }
 };
@@ -1011,10 +1009,10 @@ struct blocktype
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string type;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), SIM_BLOCKTYPE, type);
+        controller.getObjectProperty(adaptee, BLOCK, SIM_BLOCKTYPE, type);
 
         types::String* o = new types::String(type.c_str());
         return o;
@@ -1022,7 +1020,7 @@ struct blocktype
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabString)
         {
@@ -1040,7 +1038,7 @@ struct blocktype
         FREE(c_str);
 
         // the value validation is performed on the model
-        return controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_BLOCKTYPE, type) != FAIL;
+        return controller.setObjectProperty(adaptee, BLOCK, SIM_BLOCKTYPE, type) != FAIL;
     }
 };
 
@@ -1063,10 +1061,10 @@ struct dep_ut
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<int> dep_ut;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), SIM_DEP_UT, dep_ut);
+        controller.getObjectProperty(adaptee, BLOCK, SIM_DEP_UT, dep_ut);
 
         int* dep;
         types::Bool* o = new types::Bool(1, 2, &dep);
@@ -1079,7 +1077,7 @@ struct dep_ut
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabBool)
         {
@@ -1096,7 +1094,7 @@ struct dep_ut
         dep_ut[0] = current->get(0);
         dep_ut[1] = current->get(1);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_DEP_UT, dep_ut);
+        controller.setObjectProperty(adaptee, BLOCK, SIM_DEP_UT, dep_ut);
         return true;
     }
 };
@@ -1106,10 +1104,10 @@ struct label
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string label;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), LABEL, label);
+        controller.getObjectProperty(adaptee, BLOCK, LABEL, label);
 
         types::String* o = new types::String(1, 1);
         o->set(0, label.data());
@@ -1130,14 +1128,14 @@ struct label
             return false;
         }
 
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string label;
         char* c_str = wide_string_to_UTF8(current->get(0));
         label = std::string(c_str);
         FREE(c_str);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), LABEL, label);
+        controller.setObjectProperty(adaptee, BLOCK, LABEL, label);
         return true;
     }
 };
@@ -1147,10 +1145,10 @@ struct nzcross
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         int nzcross;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), NZCROSS, nzcross);
+        controller.getObjectProperty(adaptee, BLOCK, NZCROSS, nzcross);
 
         types::Double* o = new types::Double(static_cast<double>(nzcross));
 
@@ -1159,7 +1157,7 @@ struct nzcross
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -1183,7 +1181,7 @@ struct nzcross
             nzcross = static_cast<int>(current->get(0));
         }
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), NZCROSS, nzcross);
+        controller.setObjectProperty(adaptee, BLOCK, NZCROSS, nzcross);
         return true;
     }
 };
@@ -1193,10 +1191,10 @@ struct nmode
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         int nmode;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), NMODE, nmode);
+        controller.getObjectProperty(adaptee, BLOCK, NMODE, nmode);
 
         types::Double* o = new types::Double(static_cast<double>(nmode));
 
@@ -1205,7 +1203,7 @@ struct nmode
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -1229,7 +1227,7 @@ struct nmode
             nmode = static_cast<int>(current->get(0));
         }
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), NMODE, nmode);
+        controller.setObjectProperty(adaptee, BLOCK, NMODE, nmode);
         return true;
     }
 };
@@ -1281,10 +1279,10 @@ struct uid
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string uid;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), UID, uid);
+        controller.getObjectProperty(adaptee, BLOCK, UID, uid);
 
         types::String* o = new types::String(1, 1);
         o->set(0, uid.data());
@@ -1305,14 +1303,14 @@ struct uid
             return false;
         }
 
-        model::Block* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string uid;
         char* c_str = wide_string_to_UTF8(current->get(0));
         uid = std::string(c_str);
         FREE(c_str);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), UID, uid);
+        controller.setObjectProperty(adaptee, BLOCK, UID, uid);
         return true;
     }
 };
@@ -1321,8 +1319,8 @@ struct uid
 
 template<> property<ModelAdapter>::props_t property<ModelAdapter>::fields = property<ModelAdapter>::props_t();
 
-ModelAdapter::ModelAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee) :
-    BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>(ownAdaptee, adaptee)
+ModelAdapter::ModelAdapter(std::shared_ptr<model::Block> adaptee) :
+    BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>(adaptee)
 {
     if (property<ModelAdapter>::properties_have_not_been_set())
     {
@@ -1353,6 +1351,11 @@ ModelAdapter::ModelAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Bl
     }
 }
 
+ModelAdapter::ModelAdapter(const ModelAdapter& adapter) :
+    BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>(adapter)
+{
+}
+
 ModelAdapter::~ModelAdapter()
 {
 }
index e5856b8..25f4730 100644 (file)
@@ -26,7 +26,8 @@ namespace view_scilab
 class ModelAdapter : public BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>
 {
 public:
-    ModelAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee);
+    ModelAdapter(std::shared_ptr<model::Block> adaptee);
+    ModelAdapter(const ModelAdapter& adapter);
     ~ModelAdapter();
 
     static const std::wstring getSharedTypeStr()
index a1a894d..9e186f1 100644 (file)
@@ -66,12 +66,12 @@ struct title
 
     static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
     {
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string title;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), TITLE, title);
+        controller.getObjectProperty(adaptee, DIAGRAM, TITLE, title);
         std::string path;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PATH, path);
+        controller.getObjectProperty(adaptee, DIAGRAM, PATH, path);
 
         types::String* o = new types::String(2, 1);
         o->set(0, title.data());
@@ -87,7 +87,7 @@ struct title
             return false;
         }
 
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::string path;
         std::string title;
@@ -111,8 +111,8 @@ struct title
         title = std::string(Title);
         FREE(Title);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), TITLE, title);
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), PATH, path);
+        controller.setObjectProperty(adaptee, DIAGRAM, TITLE, title);
+        controller.setObjectProperty(adaptee, DIAGRAM, PATH, path);
         return true;
     }
 };
@@ -122,13 +122,13 @@ struct tol
 
     static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
     {
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         double* data;
         types::Double* o = new types::Double(1, 7, &data);
 
         std::vector<double> tol;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+        controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
 #ifdef _MSC_VER
         std::copy(tol.begin() + 1, tol.end(), stdext::checked_array_iterator<double*>( data, 7 ));
 #else
@@ -152,14 +152,14 @@ struct tol
             return false;
         }
 
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> tol;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+        controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
 
         std::copy(current->getReal(), current->getReal() + current->getSize(), tol.begin() + 1);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+        controller.setObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
         return true;
     }
 };
@@ -169,10 +169,10 @@ struct tf
 
     static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
     {
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> tf;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tf);
+        controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tf);
 
         return new types::Double(tf[0]);
     }
@@ -191,14 +191,14 @@ struct tf
             return false;
         }
 
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<double> tol;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+        controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
 
         tol[0] = current->get(0);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+        controller.setObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
         return true;
     }
 };
@@ -208,10 +208,10 @@ struct context
 
     static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
     {
-        model::Diagram* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         std::vector<std::string> context;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), DIAGRAM_CONTEXT, context);
+        controller.getObjectProperty(adaptee, DIAGRAM, DIAGRAM_CONTEXT, context);
 
         types::String* o = new types::String((int)context.size(), 1);
         for (int i = 0; i < (int)context.size(); ++i)
@@ -232,7 +232,7 @@ struct context
                 return false;
             }
 
-            model::Diagram* adaptee = adaptor.getAdaptee();
+            ScicosID adaptee = adaptor.getAdaptee()->id();
 
             std::vector<std::string> context (current->getSize());
             for (int i = 0; i < (int)context.size(); ++i)
@@ -242,7 +242,7 @@ struct context
                 FREE(c_str);
             }
 
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), DIAGRAM_CONTEXT, context);
+            controller.setObjectProperty(adaptee, DIAGRAM, DIAGRAM_CONTEXT, context);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabDouble)
@@ -253,10 +253,10 @@ struct context
                 return false;
             }
 
-            model::Diagram* adaptee = adaptor.getAdaptee();
+            ScicosID adaptee = adaptor.getAdaptee()->id();
 
             std::vector<std::string> context;
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), DIAGRAM_CONTEXT, context);
+            controller.setObjectProperty(adaptee, DIAGRAM, DIAGRAM_CONTEXT, context);
             return true;
         }
         return false;
@@ -311,8 +311,8 @@ struct doc
 
 template<> property<ParamsAdapter>::props_t property<ParamsAdapter>::fields = property<ParamsAdapter>::props_t();
 
-ParamsAdapter::ParamsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
-    BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
+ParamsAdapter::ParamsAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee) :
+    BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(adaptee)
 {
     if (property<ParamsAdapter>::properties_have_not_been_set())
     {
@@ -332,9 +332,15 @@ ParamsAdapter::ParamsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::
     doc_content = new types::List();
 }
 
+ParamsAdapter::ParamsAdapter(const ParamsAdapter& adapter) :
+    BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(adapter)
+{
+    doc_content = adapter.doc_content->clone();
+}
+
 ParamsAdapter::~ParamsAdapter()
 {
-    delete doc_content;
+    doc_content->killMe();
 }
 
 std::wstring ParamsAdapter::getTypeStr()
@@ -353,7 +359,7 @@ types::InternalType* ParamsAdapter::getDocContent() const
 
 void ParamsAdapter::setDocContent(types::InternalType* v)
 {
-    delete doc_content;
+    doc_content->killMe();
     doc_content = v->clone();
 }
 
index 1ae40e5..ea23def 100644 (file)
@@ -27,7 +27,8 @@ namespace view_scilab
 class ParamsAdapter : public BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    ParamsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
+    ParamsAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee);
+    ParamsAdapter(const ParamsAdapter& adapter);
     ~ParamsAdapter();
 
     static const std::wstring getSharedTypeStr()
index 00f5523..d08ce18 100644 (file)
@@ -31,8 +31,8 @@ namespace
 
 template<> property<ScsAdapter>::props_t property<ScsAdapter>::fields = property<ScsAdapter>::props_t();
 
-ScsAdapter::ScsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
-    BaseAdapter<ScsAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
+ScsAdapter::ScsAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee) :
+    BaseAdapter<ScsAdapter, org_scilab_modules_scicos::model::Diagram>(adaptee)
 {
     if (property<ScsAdapter>::properties_have_not_been_set())
     {
@@ -40,6 +40,11 @@ ScsAdapter::ScsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagra
     }
 }
 
+ScsAdapter::ScsAdapter(const ScsAdapter& adapter) :
+    BaseAdapter<ScsAdapter, org_scilab_modules_scicos::model::Diagram>(adapter)
+{
+}
+
 ScsAdapter::~ScsAdapter()
 {
 }
index 37d026d..1074d01 100644 (file)
@@ -27,7 +27,8 @@ namespace view_scilab
 class ScsAdapter : public BaseAdapter<ScsAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    ScsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
+    ScsAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee);
+    ScsAdapter(const ScsAdapter& adapter);
     ~ScsAdapter();
 
     static const std::wstring getSharedTypeStr()
index ad4184e..6ed9a9c 100644 (file)
@@ -31,8 +31,8 @@ namespace
 
 template<> property<StateAdapter>::props_t property<StateAdapter>::fields = property<StateAdapter>::props_t();
 
-StateAdapter::StateAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
-    BaseAdapter<StateAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
+StateAdapter::StateAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee) :
+    BaseAdapter<StateAdapter, org_scilab_modules_scicos::model::Diagram>(adaptee)
 {
     if (property<StateAdapter>::properties_have_not_been_set())
     {
@@ -40,6 +40,11 @@ StateAdapter::StateAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Di
     }
 }
 
+StateAdapter::StateAdapter(const StateAdapter& adapter) :
+    BaseAdapter<StateAdapter, org_scilab_modules_scicos::model::Diagram>(adapter)
+{
+}
+
 StateAdapter::~StateAdapter()
 {
 }
index d0df2ea..dad6aca 100644 (file)
@@ -27,7 +27,8 @@ namespace view_scilab
 class StateAdapter : public BaseAdapter<StateAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    StateAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
+    StateAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Diagram> adaptee);
+    StateAdapter(const StateAdapter& adapter);
     ~StateAdapter();
 
     static const std::wstring getSharedTypeStr()
index 30f1fc9..17bf86c 100644 (file)
@@ -47,7 +47,7 @@ struct graphics
 {
     static types::InternalType* get(const TextAdapter& adaptor, const Controller& controller)
     {
-        model::Annotation* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         types::MList* o = new types::MList();
         types::String* MListFields = new types::String(1, 4);
@@ -59,7 +59,7 @@ struct graphics
 
         // orig and sz
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, ANNOTATION, GEOMETRY, geom);
 
         double* dataOrig;
         double* dataSz;
@@ -74,9 +74,9 @@ struct graphics
 
         // exprs
         std::vector<std::string> Exprs (3);
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), DESCRIPTION, Exprs[0]);
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), FONT, Exprs[1]);
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), FONT_SIZE, Exprs[2]);
+        controller.getObjectProperty(adaptee, ANNOTATION, DESCRIPTION, Exprs[0]);
+        controller.getObjectProperty(adaptee, ANNOTATION, FONT, Exprs[1]);
+        controller.getObjectProperty(adaptee, ANNOTATION, FONT_SIZE, Exprs[2]);
 
         types::String* exprsField = new types::String(3, 1);
         for (int i = 0; i < (int) Exprs.size(); ++i)
@@ -105,7 +105,7 @@ struct graphics
         types::Double* currentFieldDouble;
         types::String* currentFieldString;
 
-        model::Annotation* adaptee = adaptor.getAdaptee();
+        ScicosID adaptee = adaptor.getAdaptee()->id();
 
         // orig
         if ((currentField = current->getField(orig.c_str())) == NULL)
@@ -122,10 +122,10 @@ struct graphics
             return false;
         }
         std::vector<double> origField;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, origField);
+        controller.getObjectProperty(adaptee, ANNOTATION, GEOMETRY, origField);
         origField[0] = currentFieldDouble->get(0);
         origField[1] = currentFieldDouble->get(1);
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, origField);
+        controller.setObjectProperty(adaptee, ANNOTATION, GEOMETRY, origField);
 
         // sz
         if ((currentField = current->getField(sz.c_str())) == NULL)
@@ -142,10 +142,10 @@ struct graphics
             return false;
         }
         std::vector<double> szField;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, szField);
+        controller.getObjectProperty(adaptee, ANNOTATION, GEOMETRY, szField);
         szField[2] = currentFieldDouble->get(0);
         szField[3] = currentFieldDouble->get(1);
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, szField);
+        controller.setObjectProperty(adaptee, ANNOTATION, GEOMETRY, szField);
 
         // exprs
         if ((currentField = current->getField(exprs.c_str())) == NULL)
@@ -167,9 +167,9 @@ struct graphics
                 exprsField[i] = std::string(c_str);
                 FREE(c_str);
             }
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), DESCRIPTION, exprsField[0]);
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), FONT, exprsField[1]);
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), FONT_SIZE, exprsField[2]);
+            controller.setObjectProperty(adaptee, ANNOTATION, DESCRIPTION, exprsField[0]);
+            controller.setObjectProperty(adaptee, ANNOTATION, FONT, exprsField[1]);
+            controller.setObjectProperty(adaptee, ANNOTATION, FONT_SIZE, exprsField[2]);
             return true;
         }
         else if (currentField->getType() == types::InternalType::ScilabDouble)
@@ -181,9 +181,9 @@ struct graphics
             }
 
             std::vector<std::string> exprsField (3);
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), DESCRIPTION, exprsField[0]);
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), FONT, exprsField[1]);
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), FONT_SIZE, exprsField[2]);
+            controller.setObjectProperty(adaptee, ANNOTATION, DESCRIPTION, exprsField[0]);
+            controller.setObjectProperty(adaptee, ANNOTATION, FONT, exprsField[1]);
+            controller.setObjectProperty(adaptee, ANNOTATION, FONT_SIZE, exprsField[2]);
             return true;
         }
 
@@ -258,8 +258,8 @@ struct dummy_property
 
 template<> property<TextAdapter>::props_t property<TextAdapter>::fields = property<TextAdapter>::props_t();
 
-TextAdapter::TextAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Annotation* adaptee) :
-    BaseAdapter<TextAdapter, org_scilab_modules_scicos::model::Annotation>(ownAdaptee, adaptee)
+TextAdapter::TextAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Annotation> adaptee) :
+    BaseAdapter<TextAdapter, org_scilab_modules_scicos::model::Annotation>(adaptee)
 {
     if (property<TextAdapter>::properties_have_not_been_set())
     {
@@ -271,6 +271,11 @@ TextAdapter::TextAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Anno
     }
 }
 
+TextAdapter::TextAdapter(const TextAdapter& adapter) :
+    BaseAdapter<TextAdapter, org_scilab_modules_scicos::model::Annotation>(adapter)
+{
+}
+
 TextAdapter::~TextAdapter()
 {
 }
index ed340a5..b077da0 100644 (file)
@@ -27,7 +27,8 @@ namespace view_scilab
 class TextAdapter : public BaseAdapter<TextAdapter, org_scilab_modules_scicos::model::Annotation>
 {
 public:
-    TextAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Annotation* adaptee);
+    TextAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Annotation> adaptee);
+    TextAdapter(const TextAdapter& adapter);
     ~TextAdapter();
 
     static const std::wstring getSharedTypeStr()
index 7cc6d4f..f1040cc 100644 (file)
@@ -42,11 +42,11 @@ namespace view_scilab
 template<typename Adaptor, object_properties_t p>
 types::InternalType* get_ports_property(const Adaptor& adaptor, const object_properties_t port_kind, const Controller& controller)
 {
-    model::Block* adaptee = adaptor.getAdaptee();
+    ScicosID adaptee = adaptor.getAdaptee()->id();
 
     // Retrieve the identifiers
     std::vector<ScicosID> ids;
-    controller.getObjectProperty(adaptee->id(), adaptee->kind(), port_kind, ids);
+    controller.getObjectProperty(adaptee, BLOCK, port_kind, ids);
 
     // Translate identifiers: shared variables
     int i = 0;
@@ -73,10 +73,10 @@ types::InternalType* get_ports_property(const Adaptor& adaptor, const object_pro
                 return new types::Double(1);
             }
             datatypeIndex++;
-            // no break
+        // no break
         case DATATYPE_COLS:
             datatypeIndex++;
-            // no break
+        // no break
         case DATATYPE_ROWS:
         {
             datatypeIndex++;
@@ -117,7 +117,7 @@ types::InternalType* get_ports_property(const Adaptor& adaptor, const object_pro
             types::Double* o = new types::Double((int)ids.size(), 1, &v);
 
             ScicosID diagram;
-            controller.getObjectProperty(adaptee->id(), adaptee->kind(), PARENT_DIAGRAM, diagram);
+            controller.getObjectProperty(adaptee, BLOCK, PARENT_DIAGRAM, diagram);
 
             std::vector<ScicosID> children;
             if (diagram != 0)
@@ -156,11 +156,11 @@ types::InternalType* get_ports_property(const Adaptor& adaptor, const object_pro
 template<typename Adaptor, object_properties_t p>
 bool set_ports_property(const Adaptor& adaptor, const object_properties_t port_kind, Controller& controller, types::InternalType* v)
 {
-    model::Block* adaptee = adaptor.getAdaptee();
+    ScicosID adaptee = adaptor.getAdaptee()->id();
 
     // Retrieve the ports identifiers
     std::vector<ScicosID> ids;
-    controller.getObjectProperty(adaptee->id(), adaptee->kind(), port_kind, ids);
+    controller.getObjectProperty(adaptee, BLOCK, port_kind, ids);
 
     if (v->getType() == types::InternalType::ScilabString)
     {
@@ -193,7 +193,7 @@ bool set_ports_property(const Adaptor& adaptor, const object_properties_t port_k
             }
             case IMPLICIT:
             {
-                if (current->getSize() != ids.size())
+                if (current->getSize() != static_cast<int>(ids.size()))
                 {
                     return false;
                 }
@@ -237,7 +237,7 @@ bool set_ports_property(const Adaptor& adaptor, const object_properties_t port_k
                     return true;
                 }
 
-                if (current->getSize() < ids.size())
+                if (current->getSize() < static_cast<int>(ids.size()))
                 {
                     return false;
                 }
@@ -256,16 +256,16 @@ bool set_ports_property(const Adaptor& adaptor, const object_properties_t port_k
 
             case DATATYPE_TYPE:
                 datatypeIndex++;
-                // no break
+            // no break
             case DATATYPE_COLS:
                 datatypeIndex++;
-                // no break
+            // no break
             case DATATYPE_ROWS:
             {
                 datatypeIndex++;
 
                 // ignore the set without error
-                if (current->getSize() != ids.size())
+                if (current->getSize() != static_cast<int>(ids.size()))
                 {
                     return true;
                 }
@@ -295,8 +295,6 @@ bool set_ports_property(const Adaptor& adaptor, const object_properties_t port_k
     }
     else if (v->getType() == types::InternalType::ScilabBool)
     {
-        types::Bool* current = v->getAs<types::Bool>();
-
         switch (p)
         {
             case FIRING:
@@ -409,10 +407,10 @@ inline bool updateNewPort(const ScicosID oldPort, int newPort, Controller& contr
         {
             case DATATYPE_TYPE:
                 datatypeIndex++;
-                // no break
+            // no break
             case DATATYPE_COLS:
                 datatypeIndex++;
-                // no break
+            // no break
             case DATATYPE_ROWS:
             {
                 datatypeIndex++;
@@ -459,10 +457,10 @@ inline bool addNewPort(const ScicosID newPortID, int newPort, const std::vector<
         {
             case DATATYPE_TYPE:
                 datatypeIndex++;
-                // no break
+            // no break
             case DATATYPE_COLS:
                 datatypeIndex++;
-                // no break
+            // no break
             case DATATYPE_ROWS:
             {
                 datatypeIndex++;
@@ -487,7 +485,7 @@ inline bool addNewPort(const ScicosID newPortID, int newPort, const std::vector<
 template<typename Adaptor, object_properties_t p>
 bool update_ports_property(const Adaptor& adaptor, const object_properties_t port_kind, Controller& controller, types::InternalType* v)
 {
-    model::Block* adaptee = adaptor.getAdaptee();
+    ScicosID adaptee = adaptor.getAdaptee()->id();
 
     if (v->getType() != types::InternalType::ScilabDouble)
     {
@@ -496,7 +494,7 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
     types::Double* value = v->getAs<types::Double>();
 
     ScicosID parentDiagram;
-    controller.getObjectProperty(adaptee->id(), BLOCK, PARENT_DIAGRAM, parentDiagram);
+    controller.getObjectProperty(adaptee, BLOCK, PARENT_DIAGRAM, parentDiagram);
 
     std::vector<ScicosID> children;
     if (parentDiagram != 0)
@@ -508,7 +506,7 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
 
     // retrieve old data
     std::vector<ScicosID> oldPorts;
-    controller.getObjectProperty(adaptee->id(), adaptee->kind(), port_kind, oldPorts);
+    controller.getObjectProperty(adaptee, BLOCK, port_kind, oldPorts);
     std::vector<ScicosID> previousPorts = oldPorts;
 
     double* d = value->getReal();
@@ -570,7 +568,7 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
             deletedObjects.push_back(oldPort);
         }
 
-        controller.setObjectProperty(adaptee->id(), BLOCK, port_kind, previousPorts);
+        controller.setObjectProperty(adaptee, BLOCK, port_kind, previousPorts);
     }
 
     // added ports
@@ -582,7 +580,7 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
             newPorts.pop_back();
 
             ScicosID id = controller.createObject(PORT);
-            controller.setObjectProperty(id, PORT, SOURCE_BLOCK, adaptee->id());
+            controller.setObjectProperty(id, PORT, SOURCE_BLOCK, adaptee);
             switch (port_kind)
             {
                 case INPUTS:
@@ -604,7 +602,7 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
             previousPorts.push_back(id);
         }
 
-        controller.setObjectProperty(adaptee->id(), BLOCK, port_kind, previousPorts);
+        controller.setObjectProperty(adaptee, BLOCK, port_kind, previousPorts);
     }
 
     // remove objects from the model after de-association
index 8dd6f4e..6ca8574 100644 (file)
  */
 // Ignore not applicable methods
 %ignore org_scilab_modules_scicos::Controller::getObject;
-%ignore org_scilab_modules_scicos::Controller::setObject;
 %ignore org_scilab_modules_scicos::Controller::unregister_view;
 %ignore org_scilab_modules_scicos::Controller::register_view;
 %ignore org_scilab_modules_scicos::Controller::delete_all_instances;