Scicos: speedup model transformation 30/19330/14
Clément DAVID [Tue, 11 Jul 2017 14:27:09 +0000 (16:27 +0200)]
 1. Use the C++ model::BaseObject* API for most of the getObjectProperties
and setObjectProperties is an O(1) model property access.
 2. Only install XcosView on block update
 3. Use binary_search Adapter property lookup
     1. std::find is slower
     2. std::unordered_map / std::hash requires a complete type

Change-Id: Iaa2ad470919be725a0ad719da680be3b9a809a2c

37 files changed:
scilab/modules/scicos/includes/Controller.hxx
scilab/modules/scicos/includes/Model.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/view_scilab/Adapters.cpp
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/CprAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/DiagramAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ModelAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ParamsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/StateAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/TextAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ports_management.hxx
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Controller.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/JavaController.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/JavaControllerJNI.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Kind.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/ObjectProperties.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/PortKind.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/UpdateStatus.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfBool.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfDouble.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfInt.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfScicosID.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfString.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/View.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/BlockParametersAction.java
scilab/modules/xcos/src/jni/JavaController.i
scilab/modules/xcos/src/jni/JavaController_wrap.cxx
scilab/modules/xcos/src/jni/JavaController_wrap.h

index df8c42c..a800b9c 100644 (file)
@@ -40,68 +40,111 @@ namespace org_scilab_modules_scicos
 class SCICOS_IMPEXP Controller
 {
 public:
+#if !defined SWIG
     static View* register_view(const std::string& name, View* v);
     static void unregister_view(View* v);
     static View* unregister_view(const std::string& name);
     static View* look_for_view(const std::string& name);
+#endif /* !defined SWIG */
+
+    /*
+     * SWIG mapped API
+     */
 
     static void end_simulation();
 
     Controller();
     ~Controller();
 
-    ScicosID createObject(kind_t k);
-    unsigned referenceObject(const ScicosID uid) const;
-    template<typename T>
-    T* referenceObject(T* o) const
+    ScicosID createObject(kind_t k)
     {
-        referenceObject(o->id());
-        return o;
+        return createBaseObject(k)->id();
     }
-    template<typename T>
-    T* referenceObject(model::BaseObject* o) const
+
+    unsigned referenceObject(const ScicosID uid) const
     {
-        referenceObject(o->id());
-        return static_cast<T*>(o);
+        return referenceBaseObject(getBaseObject(uid))->refCount();
+    }
+
+    void deleteObject(ScicosID uid)
+    {
+        deleteBaseObject(getBaseObject(uid));
     }
-    void deleteObject(ScicosID uid);
+
     ScicosID cloneObject(ScicosID uid, bool cloneChildren, bool clonePorts);
-    model::BaseObject* cloneObject(std::map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, bool cloneChildren, bool clonePorts);
 
     kind_t getKind(ScicosID uid) const;
     std::vector<ScicosID> getAll(kind_t k) const;
     void sortAndFillKind(std::vector<ScicosID>& uids, std::vector<int>& kind);
-    model::BaseObject* getObject(ScicosID uid) const;
-    template<typename T>
-    T* getObject(ScicosID uid) const
-    {
-        return static_cast<T*>(getObject(uid));
-    }
 
     /*
      * C++ API
      */
+#if !defined SWIG
+    model::BaseObject* createBaseObject(kind_t k);
+    template<typename T>
+    T* createBaseObject(kind_t k)
+    {
+        return static_cast<T*>(createBaseObject(k));
+    }
+    model::BaseObject* referenceBaseObject(model::BaseObject* o) const;
+    template<typename T>
+    T* referenceBaseObject(T* o) const
+    {
+        referenceBaseObject(static_cast<model::BaseObject*>(o));
+        return o;
+    }
+    template<typename T>
+    T* referenceBaseObject(model::BaseObject* o) const
+    {
+        referenceBaseObject(o);
+        return static_cast<T*>(o);
+    }
+    void deleteBaseObject(model::BaseObject* o);
 
+    model::BaseObject* getBaseObject(ScicosID uid) const;
     template<typename T>
-    bool getObjectProperty(model::BaseObject* object, object_properties_t p, T& v) const
+    T* getBaseObject(ScicosID uid) const
+    {
+        return static_cast<T*>(getBaseObject(uid));
+    }
+    model::BaseObject* cloneBaseObject(std::unordered_map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, bool cloneChildren, bool clonePorts);
+#endif /* !defined SWIG */
+
+    /*
+     * C++ API: getters and setters
+     */
+    template<typename K, typename T>
+    bool getObjectProperty(K* object, object_properties_t p, T& v) const
     {
+        static_assert(std::is_base_of<model::BaseObject, K>::value, "object should be an MVC object");
+
         lock(&m_instance.onModelStructuralModification);
         bool ret = m_instance.model.getObjectProperty(object, p, v);
         unlock(&m_instance.onModelStructuralModification);
         return ret;
-    }
+    };
 
-    template<typename T>
-    update_status_t setObjectProperty(model::BaseObject* object, object_properties_t p, const T& v)
+    template<typename K, typename T>
+    update_status_t setObjectProperty(K* object, object_properties_t p, T const& v)
     {
+        static_assert(std::is_base_of<model::BaseObject, K>::value, "object should be an MVC object");
+
         lock(&m_instance.onModelStructuralModification);
-        update_status_t ret = m_instance.model.setObjectProperty(object, p, v);
+        update_status_t status = m_instance.model.setObjectProperty(object, p, v);
         unlock(&m_instance.onModelStructuralModification);
-        return ret;
-    }
+
+        lock(&m_instance.onViewsStructuralModification);
+        for (view_set_t::iterator iter = m_instance.allViews.begin(); iter != m_instance.allViews.end(); ++iter)
+        {
+            (*iter)->propertyUpdated(object->id(), object->kind(), p, status);
+        }
+        unlock(&m_instance.onViewsStructuralModification);
+        return status;
+    };
 
     /*
-     * C / Java API
+     * SWIG mapped API: getters and setters
      */
 
     bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, double& v) const;
@@ -127,7 +170,6 @@ public:
     update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<ScicosID>& v);
 
 private:
-
     typedef std::vector<View*> view_set_t;
     typedef std::vector<std::string> view_name_set_t;
 
@@ -147,6 +189,10 @@ private:
         ~SharedData();
     };
 
+    /*
+     * Helpers
+     */
+
     static inline void lock(std::atomic_flag* m)
     {
         while (m->test_and_set(std::memory_order_acquire))  // acquire lock
@@ -166,14 +212,25 @@ private:
     static SharedData m_instance;
 
     /*
+     * per instance data, for performance reasons
+     */
+    std::string _strShared;
+    std::vector<double> _vecDblShared;
+    std::vector<int> _vecIntShared;
+    std::vector<std::string> _vecStrShared;
+    std::vector<ScicosID> _vecIDShared;
+
+    /*
      * Methods
      */
 
     template<typename T> void cloneProperties(model::BaseObject* initial, model::BaseObject* clone);
+    template<typename T> void cloneProperties(model::BaseObject* initial, model::BaseObject* clone, T& temporary);
     template<typename T> bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, T& v) const;
     template<typename T> update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, T v);
-    void deepClone(std::map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, model::BaseObject* clone, object_properties_t p, bool cloneIfNotFound);
-    void deepCloneVector(std::map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, model::BaseObject* clone, object_properties_t p, bool cloneIfNotFound);
+    void deepClone(std::unordered_map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, model::BaseObject* clone, object_properties_t p, bool cloneIfNotFound);
+    void deepCloneVector(std::unordered_map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, model::BaseObject* clone, object_properties_t p, bool cloneIfNotFound);
+    void updateChildrenRelatedPropertiesAfterClone(std::unordered_map<model::BaseObject*, model::BaseObject*>& mapped);
     void unlinkVector(model::BaseObject* o, object_properties_t uid_prop, object_properties_t ref_prop);
     void unlink(model::BaseObject* o, object_properties_t uid_prop, object_properties_t ref_prop);
     void deleteVector(model::BaseObject* o, object_properties_t uid_prop);
index 24bcee7..5ec0fbf 100644 (file)
@@ -38,10 +38,10 @@ public:
      * Controller wrapped methods
      */
 
-    ScicosID createObject(kind_t k);
-    unsigned referenceObject(const ScicosID uid);
-    unsigned& referenceCount(ScicosID uid);
-    void deleteObject(ScicosID uid);
+    model::BaseObject* createObject(kind_t k);
+    unsigned referenceObject(model::BaseObject* object);
+    unsigned& referenceCount(model::BaseObject* object);
+    void deleteObject(model::BaseObject* object);
 
     template<typename T>
     inline bool getObjectProperty(ScicosID uid, kind_t /*k*/, object_properties_t p, T& v) const
@@ -81,13 +81,21 @@ public:
      */
 
     kind_t getKind(ScicosID uid) const;
-    std::vector<ScicosID> getAll(kind_t k) const;
+    std::vector<model::BaseObject*> getAll(kind_t k) const;
     model::BaseObject* getObject(ScicosID uid) const;
     template<typename T>
     T* getObject(ScicosID uid) const
     {
         return static_cast<T*>(getObject(uid));
     };
+    size_t size()
+    {
+        return allObjects.size();
+    }
+    void reserve(size_t count)
+    {
+        allObjects.reserve(count);
+    }
 
     model::Datatype* flyweight(const model::Datatype& d);
     void erase(model::Datatype* d);
@@ -96,8 +104,8 @@ private:
     ScicosID lastId;
     bool has_looped;
 
-    typedef std::unordered_map<ScicosID, model::BaseObject* > objects_map_t;
-    objects_map_t allObjects;
+    typedef std::unordered_map<ScicosID, model::BaseObject*> allobjects_t;
+    allobjects_t allObjects;
 
     typedef std::vector<model::Datatype*> datatypes_set_t;
     datatypes_set_t datatypes;
index a572a76..48ff2bb 100644 (file)
@@ -63,7 +63,7 @@ types::InternalType * alloc_and_set(kind_t k, types::String* type_name, types::t
 
     // create the associated object and own it
     ScicosID uid = controller.createObject(k);
-    Adaptor* adaptor = new Adaptor(controller, controller.getObject<Adaptee>(uid));
+    Adaptor* adaptor = new Adaptor(controller, controller.getBaseObject<Adaptee>(uid));
 
     // the first header entry is the type
     for (int i = 1; i < (int)in.size(); i++)
@@ -251,7 +251,7 @@ static types::Function::ReturnValue get(types::GenericType* UIDs, int _iRetCount
         ScicosID uid = get(UIDs, i);
 
         // create the associated object
-        model::BaseObject* o = controller.getObject(uid);
+        model::BaseObject* o = controller.getBaseObject(uid);
         if (o == nullptr)
         {
             Scierror(999, _("%s: Wrong value for input argument #%d: invalid UID.\n"), funame.data(), 1);
@@ -262,13 +262,13 @@ static types::Function::ReturnValue get(types::GenericType* UIDs, int _iRetCount
         switch (o->kind())
         {
             case DIAGRAM:
-                out.push_back(new view_scilab::DiagramAdapter(controller, static_cast<model::Diagram*>(controller.referenceObject(o))));
+                out.push_back(new view_scilab::DiagramAdapter(controller, controller.referenceBaseObject<model::Diagram>(o)));
                 break;
             case BLOCK:
-                out.push_back(new view_scilab::BlockAdapter(controller, static_cast<model::Block*>(controller.referenceObject(o))));
+                out.push_back(new view_scilab::BlockAdapter(controller, controller.referenceBaseObject<model::Block>(o)));
                 break;
             case LINK:
-                out.push_back(new view_scilab::LinkAdapter(controller, static_cast<model::Link*>(controller.referenceObject(o))));
+                out.push_back(new view_scilab::LinkAdapter(controller, controller.referenceBaseObject<model::Link>(o)));
                 break;
             default:
                 Scierror(999, _("%s: Wrong value for input argument #%d: not handled kind.\n"), funame.data(), 1);
index 1d00597..b9c6543 100644 (file)
@@ -50,9 +50,9 @@ Controller::SharedData::SharedData() :
 Controller::SharedData::~SharedData()
 {
     lock(&onViewsStructuralModification);
-    for (view_set_t::iterator iter = allViews.begin(); iter != allViews.end(); ++iter)
+    for (auto v : m_instance.allViews)
     {
-        delete *iter;
+        delete v;
     }
     unlock(&onViewsStructuralModification);
 }
@@ -61,12 +61,15 @@ Controller::SharedData Controller::m_instance;
 
 View* Controller::register_view(const std::string& name, View* v)
 {
-    lock(&m_instance.onViewsStructuralModification);
+    if (v != nullptr)
+    {
+        lock(&m_instance.onViewsStructuralModification);
 
-    m_instance.allNamedViews.push_back(name);
-    m_instance.allViews.push_back(v);
+        m_instance.allNamedViews.push_back(name);
+        m_instance.allViews.push_back(v);
 
-    unlock(&m_instance.onViewsStructuralModification);
+        unlock(&m_instance.onViewsStructuralModification);
+    }
     return v;
 }
 
@@ -125,7 +128,7 @@ void Controller::end_simulation()
     end_scicos_sim();
 }
 
-Controller::Controller()
+Controller::Controller() : _strShared(), _vecDblShared(), _vecIntShared(), _vecStrShared(), _vecIDShared()
 {
 }
 
@@ -133,29 +136,28 @@ Controller::~Controller()
 {
 }
 
-ScicosID Controller::createObject(kind_t k)
+model::BaseObject* Controller::createBaseObject(kind_t k)
 {
     lock(&m_instance.onModelStructuralModification);
-    ScicosID uid = m_instance.model.createObject(k);
+    model::BaseObject* object = m_instance.model.createObject(k);
     unlock(&m_instance.onModelStructuralModification);
 
     lock(&m_instance.onViewsStructuralModification);
-    for (view_set_t::iterator iter = m_instance.allViews.begin(); iter != m_instance.allViews.end(); ++iter)
+    for (auto v : m_instance.allViews)
     {
-        (*iter)->objectCreated(uid, k);
+        v->objectCreated(object->id(), object->kind());
     }
     unlock(&m_instance.onViewsStructuralModification);
 
-    return uid;
+    return object;
 }
 
-unsigned Controller::referenceObject(const ScicosID uid) const
+model::BaseObject* Controller::referenceBaseObject(model::BaseObject* o) const
 {
     lock(&m_instance.onModelStructuralModification);
 
-    unsigned refCount = m_instance.model.referenceObject(uid);
+    unsigned refCount = m_instance.model.referenceObject(o);
 
-    auto o = m_instance.model.getObject(uid);
     unlock(&m_instance.onModelStructuralModification);
     if (o == nullptr)
     {
@@ -164,26 +166,25 @@ unsigned Controller::referenceObject(const ScicosID uid) const
     }
 
     lock(&m_instance.onViewsStructuralModification);
-    for (view_set_t::iterator iter = m_instance.allViews.begin(); iter != m_instance.allViews.end(); ++iter)
+    for (auto v : m_instance.allViews)
     {
-        (*iter)->objectReferenced(uid, o->kind(), refCount);
+        v->objectReferenced(o->id(), o->kind(), refCount);
     }
     unlock(&m_instance.onViewsStructuralModification);
 
-    return refCount;
+    return o;
 }
 
-void Controller::deleteObject(ScicosID uid)
+void Controller::deleteBaseObject(model::BaseObject* initial)
 {
     // if this object is the empty uid, ignore it : is is not stored in the model
-    if (uid == ScicosID())
+    if (initial == nullptr || initial->id() == ScicosID())
     {
         return;
     }
 
     lock(&m_instance.onModelStructuralModification);
 
-    auto initial = m_instance.model.getObject(uid);
     if (initial == nullptr)
     {
         // defensive programming
@@ -193,16 +194,16 @@ void Controller::deleteObject(ScicosID uid)
     const kind_t k = initial->kind();
 
     // if this object has been referenced somewhere else do not delete it but decrement the reference counter
-    unsigned& refCount = m_instance.model.referenceCount(uid);
+    unsigned& refCount = m_instance.model.referenceCount(initial);
     unlock(&m_instance.onModelStructuralModification);
     if (refCount > 0)
     {
         --refCount;
 
         lock(&m_instance.onViewsStructuralModification);
-        for (view_set_t::iterator iter = m_instance.allViews.begin(); iter != m_instance.allViews.end(); ++iter)
+        for (auto v : m_instance.allViews)
         {
-            (*iter)->objectUnreferenced(uid, k, refCount);
+            v->objectUnreferenced(initial->id(), initial->kind(), refCount);
         }
         unlock(&m_instance.onViewsStructuralModification);
         return;
@@ -260,13 +261,13 @@ void Controller::deleteObject(ScicosID uid)
 
     // delete the object
     lock(&m_instance.onModelStructuralModification);
-    m_instance.model.deleteObject(uid);
+    m_instance.model.deleteObject(initial);
     unlock(&m_instance.onModelStructuralModification);
 
     lock(&m_instance.onViewsStructuralModification);
-    for (view_set_t::iterator iter = m_instance.allViews.begin(); iter != m_instance.allViews.end(); ++iter)
+    for (auto v : m_instance.allViews)
     {
-        (*iter)->objectDeleted(uid, k);
+        v->objectDeleted(initial->id(), k);
     }
     unlock(&m_instance.onViewsStructuralModification);
 }
@@ -274,17 +275,17 @@ void Controller::deleteObject(ScicosID uid)
 void Controller::unlinkVector(model::BaseObject* initial, object_properties_t uid_prop, object_properties_t ref_prop)
 {
     ScicosID v;
-    getObjectProperty(initial->id(), initial->kind(), uid_prop, v);
+    getObjectProperty(initial, uid_prop, v);
     if (v != ScicosID())
     {
-        auto o = getObject(v);
+        auto o = getBaseObject(v);
         if (o == nullptr)
         {
             return;
         }
 
-        std::vector<ScicosID> children;
-        getObjectProperty(o->id(), o->kind(), ref_prop, children);
+        std::vector<ScicosID>& children = _vecIDShared;
+        getObjectProperty(o, ref_prop, children);
 
         std::vector<ScicosID>::iterator it = std::find(children.begin(), children.end(), initial->id());
         if (it != children.end())
@@ -292,19 +293,19 @@ void Controller::unlinkVector(model::BaseObject* initial, object_properties_t ui
             children.erase(it);
         }
 
-        setObjectProperty(o->id(), o->kind(), ref_prop, children);
+        setObjectProperty(o, ref_prop, children);
     }
 }
 
 void Controller::unlink(model::BaseObject* initial, object_properties_t uid_prop, object_properties_t ref_prop)
 {
     std::vector<ScicosID> v;
-    getObjectProperty(initial->id(), initial->kind(), uid_prop, v);
+    getObjectProperty(initial, uid_prop, v);
     for (const ScicosID id : v)
     {
         if (id != ScicosID())
         {
-            auto o = getObject(id);
+            auto o = getBaseObject(id);
             if (o == nullptr)
             {
                 continue;
@@ -315,7 +316,7 @@ void Controller::unlink(model::BaseObject* initial, object_properties_t uid_prop
             getObjectProperty(o->id(), o->kind(), ref_prop, oppositeRef);
             if (oppositeRef == initial->id())
             {
-                setObjectProperty(o->id(), o->kind(), ref_prop, ScicosID());
+                setObjectProperty(o, ref_prop, ScicosID());
             }
         }
     }
@@ -324,7 +325,7 @@ void Controller::unlink(model::BaseObject* initial, object_properties_t uid_prop
 void Controller::deleteVector(model::BaseObject* initial, object_properties_t uid_prop)
 {
     std::vector<ScicosID> children;
-    getObjectProperty(initial->id(), initial->kind(), uid_prop, children);
+    getObjectProperty(initial, uid_prop, children);
 
     for (ScicosID id : children)
     {
@@ -335,7 +336,7 @@ void Controller::deleteVector(model::BaseObject* initial, object_properties_t ui
 void Controller::deleteOwnedReference(model::BaseObject* o, object_properties_t uid_prop)
 {
     ScicosID ref;
-    getObjectProperty(o->id(), o->kind(), uid_prop, ref);
+    getObjectProperty(o, uid_prop, ref);
 
     deleteObject(ref);
 }
@@ -356,17 +357,33 @@ void Controller::cloneProperties(model::BaseObject* initial, model::BaseObject*
     }
 }
 
-model::BaseObject* Controller::cloneObject(std::map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, bool cloneChildren, bool clonePorts)
+template<typename T>
+void Controller::cloneProperties(model::BaseObject* initial, model::BaseObject* clone, T& temporary)
+{
+    for (int i = 0; i < MAX_OBJECT_PROPERTIES; ++i)
+    {
+        enum object_properties_t p = static_cast<enum object_properties_t>(i);
+
+        temporary.clear();
+        bool status = getObjectProperty(initial, p, temporary);
+        if (status)
+        {
+            setObjectProperty(clone, p, temporary);
+        }
+    }
+}
+
+model::BaseObject* Controller::cloneBaseObject(std::unordered_map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, bool cloneChildren, bool clonePorts)
 {
     const kind_t k = initial->kind();
     ScicosID o = createObject(k);
-    model::BaseObject* cloned = getObject(o);
+    model::BaseObject* cloned = getBaseObject(o);
     mapped.insert(std::make_pair(initial, cloned));
 
     lock(&m_instance.onViewsStructuralModification);
-    for (view_set_t::iterator iter = m_instance.allViews.begin(); iter != m_instance.allViews.end(); ++iter)
+    for (auto v : m_instance.allViews)
     {
-        (*iter)->objectCloned(initial->id(), o, k);
+        v->objectCloned(initial->id(), o, k);
     }
     unlock(&m_instance.onViewsStructuralModification);
 
@@ -374,10 +391,10 @@ model::BaseObject* Controller::cloneObject(std::map<model::BaseObject*, model::B
     cloneProperties<double>(initial, cloned);
     cloneProperties<int>(initial, cloned);
     cloneProperties<bool>(initial, cloned);
-    cloneProperties<std::string>(initial, cloned);
-    cloneProperties<std::vector<double> >(initial, cloned);
-    cloneProperties<std::vector<int> >(initial, cloned);
-    cloneProperties<std::vector<std::string> >(initial, cloned);
+    cloneProperties<std::string>(initial, cloned, _strShared);
+    cloneProperties<std::vector<double> >(initial, cloned, _vecDblShared);
+    cloneProperties<std::vector<int> >(initial, cloned, _vecIntShared);
+    cloneProperties<std::vector<std::string> >(initial, cloned, _vecStrShared);
 
     // deep copy children, manage ScicosID and std::vector<ScicosID>
     if (k == ANNOTATION)
@@ -427,15 +444,15 @@ model::BaseObject* Controller::cloneObject(std::map<model::BaseObject*, model::B
     return cloned;
 }
 
-void Controller::deepClone(std::map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, model::BaseObject* clone, object_properties_t p, bool cloneIfNotFound)
+void Controller::deepClone(std::unordered_map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, model::BaseObject* clone, object_properties_t p, bool cloneIfNotFound)
 {
     ScicosID v;
     getObjectProperty(initial, p, v);
 
-    model::BaseObject* opposite = getObject(v);
+    model::BaseObject* opposite = getBaseObject(v);
     model::BaseObject* cloned;
 
-    std::map<model::BaseObject*, model::BaseObject*>::iterator it = mapped.find(opposite);
+    std::unordered_map<model::BaseObject*, model::BaseObject*>::iterator it = mapped.find(opposite);
     if (it != mapped.end())
     {
         cloned = it->second;
@@ -446,7 +463,7 @@ void Controller::deepClone(std::map<model::BaseObject*, model::BaseObject*>& map
         {
             if (v != ScicosID())
             {
-                cloned = cloneObject(mapped, opposite, true, true);
+                cloned = cloneBaseObject(mapped, opposite, true, true);
             }
             else
             {
@@ -469,7 +486,7 @@ void Controller::deepClone(std::map<model::BaseObject*, model::BaseObject*>& map
     }
 }
 
-void Controller::deepCloneVector(std::map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, model::BaseObject* clone, object_properties_t p, bool cloneIfNotFound)
+void Controller::deepCloneVector(std::unordered_map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, model::BaseObject* clone, object_properties_t p, bool cloneIfNotFound)
 {
     std::vector<ScicosID> v;
     getObjectProperty(initial, p, v);
@@ -486,8 +503,8 @@ void Controller::deepCloneVector(std::map<model::BaseObject*, model::BaseObject*
             continue;
         }
 
-        model::BaseObject* opposite = getObject(id);
-        std::map<model::BaseObject*, model::BaseObject*>::iterator it = mapped.find(opposite);
+        model::BaseObject* opposite = getBaseObject(id);
+        std::unordered_map<model::BaseObject*, model::BaseObject*>::iterator it = mapped.find(opposite);
         if (it != mapped.end())
         {
             cloned.push_back(it->second);
@@ -498,7 +515,7 @@ void Controller::deepCloneVector(std::map<model::BaseObject*, model::BaseObject*
             {
                 if (id != ScicosID())
                 {
-                    model::BaseObject* clone = cloneObject(mapped, opposite, true, true);
+                    model::BaseObject* clone = cloneBaseObject(mapped, opposite, true, true);
                     cloned.push_back(clone);
                 }
                 else
@@ -516,24 +533,7 @@ void Controller::deepCloneVector(std::map<model::BaseObject*, model::BaseObject*
     // update the ScicosID related properties after cloning all the objects
     if (p == CHILDREN)
     {
-        for (auto const & it : mapped)
-        {
-            model::BaseObject* initial = it.first;
-            model::BaseObject* cloned = it.second;
-
-            switch (initial->kind())
-            {
-                case PORT:
-                    deepCloneVector(mapped, initial, cloned, CONNECTED_SIGNALS, false);
-                    break;
-                case LINK:
-                    deepClone(mapped, initial, cloned, SOURCE_PORT, false);
-                    deepClone(mapped, initial, cloned, DESTINATION_PORT, false);
-                    break;
-                default:
-                    break;
-            }
-        }
+        updateChildrenRelatedPropertiesAfterClone(mapped);
     }
 
     // set the main object vector property
@@ -553,10 +553,32 @@ void Controller::deepCloneVector(std::map<model::BaseObject*, model::BaseObject*
     setObjectProperty(clone, p, clonedUIDs);
 }
 
+void Controller::updateChildrenRelatedPropertiesAfterClone(std::unordered_map<model::BaseObject*, model::BaseObject*>& mapped)
+{
+    for (auto const & it : mapped)
+    {
+        model::BaseObject* initial = it.first;
+        model::BaseObject* cloned = it.second;
+
+        switch (initial->kind())
+        {
+            case PORT:
+                deepCloneVector(mapped, initial, cloned, CONNECTED_SIGNALS, false);
+                break;
+            case LINK:
+                deepClone(mapped, initial, cloned, SOURCE_PORT, false);
+                deepClone(mapped, initial, cloned, DESTINATION_PORT, false);
+                break;
+            default:
+                break;
+        }
+    }
+}
+
 ScicosID Controller::cloneObject(ScicosID uid, bool cloneChildren, bool clonePorts)
 {
-    std::map<model::BaseObject*, model::BaseObject*> mapped;
-    model::BaseObject* clone = cloneObject(mapped, getObject(uid), cloneChildren, clonePorts);
+    std::unordered_map<model::BaseObject*, model::BaseObject*> mapped;
+    model::BaseObject* clone = cloneBaseObject(mapped, getBaseObject(uid), cloneChildren, clonePorts);
 
     return clone->id();
 }
@@ -575,10 +597,16 @@ std::vector<ScicosID> Controller::getAll(kind_t k) const
 {
     lock(&m_instance.onModelStructuralModification);
 
-    auto vec = m_instance.model.getAll(k);
+    std::vector<model::BaseObject*> vec = m_instance.model.getAll(k);
+    std::vector<ScicosID> ret;
+    ret.reserve(vec.size());
+    for (model::BaseObject* o : vec)
+    {
+        ret.push_back(o->id());
+    }
 
     unlock(&m_instance.onModelStructuralModification);
-    return vec;
+    return ret;
 }
 
 void Controller::sortAndFillKind(std::vector<ScicosID>& uids, std::vector<int>& kinds)
@@ -620,10 +648,7 @@ void Controller::sortAndFillKind(std::vector<ScicosID>& uids, std::vector<int>&
 template<typename T>
 bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, T& v) const
 {
-    lock(&m_instance.onModelStructuralModification);
-    bool ret = m_instance.model.getObjectProperty(uid, k, p, v);
-    unlock(&m_instance.onModelStructuralModification);
-    return ret;
+    return getObjectProperty(getBaseObject(uid), p, v);
 }
 
 bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, double& v) const
@@ -670,17 +695,7 @@ bool Controller::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p
 template<typename T>
 update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, T v)
 {
-    lock(&m_instance.onModelStructuralModification);
-    update_status_t status = m_instance.model.setObjectProperty(uid, k, p, v);
-    unlock(&m_instance.onModelStructuralModification);
-
-    lock(&m_instance.onViewsStructuralModification);
-    for (view_set_t::iterator iter = m_instance.allViews.begin(); iter != m_instance.allViews.end(); ++iter)
-    {
-        (*iter)->propertyUpdated(uid, k, p, status);
-    }
-    unlock(&m_instance.onViewsStructuralModification);
-    return status;
+    return setObjectProperty(getBaseObject(uid), p, v);
 }
 
 update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, double v)
@@ -724,7 +739,7 @@ update_status_t Controller::setObjectProperty(ScicosID uid, kind_t k, object_pro
     return setObjectProperty<>(uid, k, p, v);
 }
 
-model::BaseObject* Controller::getObject(ScicosID uid) const
+model::BaseObject* Controller::getBaseObject(ScicosID uid) const
 {
     lock(&m_instance.onModelStructuralModification);
     model::BaseObject* o = m_instance.model.getObject(uid);
index c12aeb0..2bab787 100644 (file)
@@ -74,7 +74,7 @@ static inline void deleteBaseObject(model::BaseObject* o)
 };
 
 
-ScicosID Model::createObject(kind_t k)
+model::BaseObject* Model::createObject(kind_t k)
 {
     /*
      * Allocate the object per kind
@@ -98,7 +98,7 @@ ScicosID Model::createObject(kind_t k)
             o = new model::Port();
             break;
         default:
-            return ScicosID();
+            return nullptr;
     }
 
     /*
@@ -116,7 +116,7 @@ ScicosID Model::createObject(kind_t k)
         bool has_looped_twice = false;
 
         // while key is found
-        for (objects_map_t::iterator iter = allObjects.find(lastId);
+        for (allobjects_t::iterator iter = allObjects.find(lastId);
                 iter != allObjects.end();
                 iter = allObjects.find(lastId))
         {
@@ -130,7 +130,7 @@ ScicosID Model::createObject(kind_t k)
                 if (has_looped_twice)
                 {
                     deleteBaseObject(o);
-                    return ScicosID();
+                    return nullptr;
                 }
                 else
                 {
@@ -143,53 +143,31 @@ ScicosID Model::createObject(kind_t k)
     /*
      * Insert then return
      */
-    allObjects.emplace(lastId, o);
     o->id(lastId);
-    return lastId;
+    allObjects.emplace(lastId, o);
+    return o;
 }
 
-unsigned Model::referenceObject(const ScicosID uid)
+unsigned Model::referenceObject(model::BaseObject* object)
 {
-    objects_map_t::iterator iter = allObjects.find(uid);
-    if (iter == allObjects.end())
-    {
-        return 0;
-    }
-
-    model::BaseObject* modelObject = iter->second;
-    return ++modelObject->refCount();
+    return ++object->refCount();
 }
 
-unsigned& Model::referenceCount(ScicosID uid)
+unsigned& Model::referenceCount(model::BaseObject* object)
 {
-    objects_map_t::iterator iter = allObjects.find(uid);
-    if (iter == allObjects.end())
-    {
-        throw std::string("key has not been found");
-    }
-
-    model::BaseObject* modelObject = iter->second;
-    return modelObject->refCount();
-
+    return object->refCount();
 }
 
-void Model::deleteObject(ScicosID uid)
+void Model::deleteObject(model::BaseObject* object)
 {
-    objects_map_t::iterator iter = allObjects.find(uid);
-    if (iter == allObjects.end())
+    if (object->refCount() == 0)
     {
-        throw std::string("key has not been found");
-    }
-
-    model::BaseObject* modelObject = iter->second;
-    if (modelObject->refCount() == 0)
-    {
-        allObjects.erase(iter);
-        deleteBaseObject(modelObject);
+        allObjects.erase(object->id());
+        deleteBaseObject(object);
     }
     else
     {
-        --modelObject->refCount();
+        --object->refCount();
     }
 }
 
@@ -207,24 +185,21 @@ kind_t Model::getKind(ScicosID uid) const
     }
 }
 
-std::vector<ScicosID> Model::getAll(kind_t k) const
+std::vector<model::BaseObject*> Model::getAll(kind_t k) const
 {
-    std::vector<ScicosID> all;
-
-    for (objects_map_t::const_iterator it = allObjects.begin(); it != allObjects.end(); ++it)
-    {
-        if (it->second->kind() == k)
+    std::vector<model::BaseObject*> all;
+    for (auto it : allObjects)
+        if (it.second->kind() == k)
         {
-            all.push_back(it->second->id());
+            all.emplace_back(it.second);
         }
-    }
 
     return all;
 }
 
 model::BaseObject* Model::getObject(ScicosID uid) const
 {
-    objects_map_t::const_iterator iter = allObjects.find(uid);
+    allobjects_t::const_iterator iter = allObjects.find(uid);
     if (iter == allObjects.end())
     {
         return nullptr;
index bdd37bf..97f9a6d 100644 (file)
@@ -139,11 +139,11 @@ types::InternalType* Adapters::allocate_view(ScicosID id, kind_t kind)
     switch (kind)
     {
         case BLOCK:
-            return new view_scilab::BlockAdapter(controller, static_cast<model::Block*>(controller.getObject(id)));
+            return new view_scilab::BlockAdapter(controller, controller.getBaseObject<model::Block>(id));
         case LINK:
-            return new view_scilab::LinkAdapter(controller, static_cast<model::Link*>(controller.getObject(id)));
+            return new view_scilab::LinkAdapter(controller, controller.getBaseObject<model::Link>(id));
         case DIAGRAM:
-            return new view_scilab::DiagramAdapter(controller, static_cast<model::Diagram*>(controller.getObject(id)));
+            return new view_scilab::DiagramAdapter(controller, controller.getBaseObject<model::Diagram>(id));
         default:
             return nullptr;
     }
index 1eb67bb..154c6f5 100644 (file)
@@ -1,6 +1,7 @@
 /*
- *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2014-2016 - Scilab Enterprises - Clement DAVID
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2014-2016 - Scilab Enterprises - Clement DAVID
+ * Copyright (C) 2017 - ESI Group - Clement DAVID
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
 #include <cstring>
 
 #include <algorithm>
+#include <functional>
 #include <string>
 #include <vector>
+#include <unordered_map>
 #include <sstream>
 
 #include "bool.hxx"
@@ -65,6 +68,10 @@ public:
     typedef std::vector< property<Adaptor> > props_t;
     typedef typename props_t::iterator props_t_it;
 
+    /*
+     * Static properties accessors
+     */
+    static props_t fields;
 
     property(const std::wstring& prop, getter_t g, setter_t s) : original_index(fields.size()), name(prop), get(g), set(s) {};
     ~property() {};
@@ -74,20 +81,7 @@ public:
     getter_t get;
     setter_t set;
 
-    bool operator< (const std::wstring& v) const
-    {
-        return name < v;
-    }
-
-    static bool original_index_cmp(property<Adaptor> p1, property<Adaptor> p2)
-    {
-        return p1.original_index < p2.original_index;
-    }
-
-    /*
-     * Static properties accessors
-     */
-    static props_t fields;
+public:
 
     /**
      * @return true if the properties have already been setup, false otherwise.
@@ -97,16 +91,68 @@ public:
         return fields.empty();
     }
 
-    /**
-     * Add a property to an Adaptor
-     */
+    /** reserve an amount of property */
+    static void reserve_properties(size_t count)
+    {
+        fields.reserve(count);
+    }
+
+    /** compact the properties and setup for a fast lookup */
+    static void shrink_to_fit()
+    {
+        fields.shrink_to_fit();
+        std::sort(fields.begin(), fields.end());
+    }
+
+    /** add a property to an Adaptor */
     static void add_property(const std::wstring& name, getter_t g, setter_t s)
     {
-        property<Adaptor>::props_t_it pos = std::lower_bound(fields.begin(), fields.end(), name);
-        fields.insert(pos, property(name, g, s));
+        fields.emplace_back(property(name, g, s));
+    }
+
+    /** lookup for a name */
+    static props_t_it find(const std::wstring& name)
+    {
+        props_t_it found = std::lower_bound(fields.begin(), fields.end(), name);
+        if (found != fields.end() && *found == name)
+        {
+            return found;
+        }
+        else
+        {
+            return fields.end();
+        }
     }
 };
 
+template<typename Adaptor>
+inline bool
+operator<(const property<Adaptor>& x, const property<Adaptor>& y)
+{
+    return x.name < y.name;
+}
+
+template<typename Adaptor>
+inline bool
+operator<(const property<Adaptor>& x, const std::wstring& y)
+{
+    return x.name < y;
+}
+
+template<typename Adaptor>
+inline bool
+operator==(const property<Adaptor>& x, const property<Adaptor>& y)
+{
+    return x.name == y.name;
+}
+
+template<typename Adaptor>
+inline bool
+operator==(const property<Adaptor>& x, const std::wstring& y)
+{
+    return x.name == y;
+}
+
 /**
  * Base definition of the adapter pattern, implement the get / set dispatch.
  *
@@ -115,6 +161,7 @@ public:
 template<typename Adaptor, typename Adaptee>
 class BaseAdapter : public types::UserType
 {
+private:
     using BaseObject = org_scilab_modules_scicos::model::BaseObject;
 
 public:
@@ -127,8 +174,8 @@ public:
         {
             Controller controller;
 
-            std::map<BaseObject*, BaseObject*> mapped;
-            BaseObject* clone = controller.cloneObject(mapped, adapter.getAdaptee(), cloneChildren, true);
+            std::unordered_map<BaseObject*, BaseObject*> mapped;
+            BaseObject* clone = controller.cloneBaseObject(mapped, adapter.getAdaptee(), cloneChildren, true);
             m_adaptee = static_cast<Adaptee*>(clone);
         }
     };
@@ -148,24 +195,24 @@ public:
 
     bool hasProperty(const std::wstring& _sKey) const
     {
-        typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
-        return found != property<Adaptor>::fields.end() && !(_sKey < found->name);
+        typename property<Adaptor>::props_t_it found = property<Adaptor>::find(_sKey);
+        return found != property<Adaptor>::fields.end();
     }
 
     types::InternalType* getProperty(const std::wstring& _sKey, Controller controller = Controller()) const
     {
-        typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
-        if (found != property<Adaptor>::fields.end() && !(_sKey < found->name))
+        typename property<Adaptor>::props_t_it found = property<Adaptor>::find(_sKey);
+        if (found != property<Adaptor>::fields.end())
         {
             return found->get(*static_cast<Adaptor*>(this), controller);
         }
-        return 0;
+        return nullptr;
     }
 
     bool setProperty(const std::wstring& _sKey, types::InternalType* v, Controller controller = Controller())
     {
-        typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), _sKey);
-        if (found != property<Adaptor>::fields.end() && !(_sKey < found->name))
+        typename property<Adaptor>::props_t_it found = property<Adaptor>::find(_sKey);
+        if (found != property<Adaptor>::fields.end())
         {
             return found->set(*static_cast<Adaptor*>(this), v, controller);
         }
@@ -188,29 +235,24 @@ public:
 
     types::InternalType* getAsTList(types::TList* tlist, const Controller& controller)
     {
-        typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
-        std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
+        const typename property<Adaptor>::props_t& properties = property<Adaptor>::fields;
 
         // create the header
         types::String* header = new types::String(1, 1 + (int)properties.size());
         header->set(0, Adaptor::getSharedTypeStr().c_str());
-        int index = 1;
-        for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it, ++index)
+        for (const auto& p : properties)
         {
-            header->set(index, it->name.c_str());
-        }
-        tlist->append(header);
+            header->set(1 + p.original_index, p.name.c_str());
 
-        // set the tlist field value
-        for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it)
-        {
-            types::InternalType* field = it->get(*static_cast<Adaptor*>(this), controller);
-            tlist->append(field);
+            types::InternalType* field = p.get(*static_cast<Adaptor*>(this), controller);
+            tlist->set(1 + p.original_index, field);
             if (field->isList())
             {
                 field->killMe();
             }
+
         }
+        tlist->set(0, header);
 
         return tlist;
     }
@@ -219,14 +261,14 @@ public:
     {
         if (v->getType() != types::InternalType::ScilabTList && v->getType() != types::InternalType::ScilabMList)
         {
-            get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %s: Tlist or Mlist expected.\n"), Adaptor::getSharedTypeStr().c_str());
+            get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %ls: Tlist or Mlist expected.\n"), Adaptor::getSharedTypeStr().c_str());
             return false;
         }
         types::TList* current = v->getAs<types::TList>();
         // The input TList cannot be empty
         if (current->getSize() < 1)
         {
-            get_or_allocate_logger()->log(LOG_ERROR, _("Wrong length for field %s: at least %d element expected.\n"), Adaptor::getSharedTypeStr().c_str(), 1);
+            get_or_allocate_logger()->log(LOG_ERROR, _("Wrong length for field %ls: at least %d element expected.\n"), Adaptor::getSharedTypeStr().c_str(), 1);
             return false;
         }
 
@@ -234,24 +276,25 @@ public:
         types::String* header = current->getFieldNames();
         if (header->getSize() < 1)
         {
-            get_or_allocate_logger()->log(LOG_ERROR, _("Wrong length for header of field %s: at least %d element expected.\n"), Adaptor::getSharedTypeStr().c_str(), 1);
+            get_or_allocate_logger()->log(LOG_ERROR, _("Wrong length for header of field \"%ls\": at least %d element expected.\n"), Adaptor::getSharedTypeStr().c_str(), 1);
             return false;
         }
         // Make sure it is the same type as the Adapter
         if (header->get(0) != Adaptor::getSharedTypeStr())
         {
-            get_or_allocate_logger()->log(LOG_ERROR, _("Wrong value for header of field %s: %s expected.\n"), Adaptor::getSharedTypeStr().c_str(), Adaptor::getSharedTypeStr().c_str());
+            get_or_allocate_logger()->log(LOG_ERROR, _("Wrong value for header of field \"%ls\": \"%ls\" expected.\n"), Adaptor::getSharedTypeStr().c_str(), Adaptor::getSharedTypeStr().c_str());
             return false;
         }
 
         // Retrieve the Adapter's properties
-        typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
+        const typename property<Adaptor>::props_t& properties = property<Adaptor>::fields;
 
         // For each input property, if it corresponds to an Adapter's property, set it.
         for (int index = 1; index < header->getSize(); ++index)
         {
-            typename property<Adaptor>::props_t_it found = std::lower_bound(properties.begin(), properties.end(), header->get(index));
-            if (found != properties.end() && !(header->get(index) < found->name))
+            std::wstring name(header->get(index));
+            typename property<Adaptor>::props_t_it found = property<Adaptor>::find(name);
+            if (found != properties.end())
             {
                 bool status = found->set(*static_cast<Adaptor*>(this), current->get(index), controller);
                 if (!status)
@@ -282,15 +325,14 @@ public:
             return false;
         }
 
-        typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
-        std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
+        const typename property<Adaptor>::props_t& properties = property<Adaptor>::fields;
 
-        bool internal_equal = true;
+        bool internal_equal;
         Controller controller;
-        for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end() && internal_equal; ++it)
+        for (const auto& p : properties)
         {
-            types::InternalType* ith_prop1 = it->get(*static_cast<const Adaptor*>(this), controller);
-            types::InternalType* ith_prop2 = it->get(*static_cast<const Adaptor*>(&o), controller);
+            types::InternalType* ith_prop1 = p.get(*static_cast<const Adaptor*>(this), controller);
+            types::InternalType* ith_prop2 = p.get(*static_cast<const Adaptor*>(&o), controller);
 
             // loop while the inner types are equals
             internal_equal = *ith_prop1 == *ith_prop2;
@@ -298,9 +340,14 @@ public:
             // Getting a property allocates data, so free it
             ith_prop1->killMe();
             ith_prop2->killMe();
+
+            if (!internal_equal)
+            {
+                return false;
+            }
         }
 
-        return internal_equal;
+        return true;
     }
 
     types::Bool* equal(types::UserType*& ut) override final
@@ -316,21 +363,19 @@ public:
             return new types::Bool(false);
         }
 
-        typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
-        std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
+        const typename property<Adaptor>::props_t& properties = property<Adaptor>::fields;
 
         types::Bool* ret = new types::Bool(1, 1 + (int)properties.size());
         ret->set(0, true); // First field is just the Adapter's name, which has been checked by the above conditions
 
         Controller controller;
-        int index = 1;
-        for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it, ++index)
+        for (const auto& p : properties)
         {
-            types::InternalType* ith_prop1 = it->get(*static_cast<Adaptor*>(this), controller);
-            types::InternalType* ith_prop2 = it->get(*static_cast<Adaptor*>(ut), controller);
-            ret->set(index, *ith_prop1 == *ith_prop2);
+            types::InternalType* ith_prop1 = p.get(*static_cast<Adaptor*>(this), controller);
+            types::InternalType* ith_prop2 = p.get(*static_cast<Adaptor*>(ut), controller);
+            ret->set(p.original_index, *ith_prop1 == *ith_prop2);
 
-            // Getting a property allocates data, so free it
+            // Getting a property allocates data, so free them
             ith_prop1->killMe();
             ith_prop2->killMe();
         }
@@ -398,8 +443,8 @@ private:
 
     bool extract(const std::wstring & name, types::InternalType *& out) override final
     {
-        typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), name);
-        if (found != property<Adaptor>::fields.end() && !(name < found->name))
+        typename property<Adaptor>::props_t_it found = property<Adaptor>::find(name);
+        if (found != property<Adaptor>::fields.end())
         {
             Controller controller;
             types::InternalType* value = found->get(*static_cast<Adaptor*>(this), controller);
@@ -447,17 +492,14 @@ private:
                 {
                     // When _pArgs is '1', return the list of the property names of the Adaptor
 
-                    // Sort the properties before extracting them
-                    typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
-                    std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
+                    const typename property<Adaptor>::props_t& properties = property<Adaptor>::fields;
 
                     // Allocate the return
                     types::String* pOut = new types::String(1, static_cast<int>(properties.size()));
 
-                    int i = 0;
-                    for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it, ++i)
+                    for (const auto& p : properties)
                     {
-                        pOut->set(i, it->name.data());
+                        pOut->set(p.original_index, p.name.data());
                     }
                     return pOut;
                 }
@@ -480,7 +522,6 @@ private:
                 Controller controller;
 
                 types::String* pStr = (*_pArgs)[i]->getAs<types::String>();
-                std::wstring name = pStr->get(0);
 
                 Adaptor* work;
                 if (getAdaptee()->refCount() > 0)
@@ -493,8 +534,8 @@ private:
                     work = static_cast<Adaptor*>(this);
                 }
 
-                typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), name);
-                if (found != property<Adaptor>::fields.end() && !(name < found->name))
+                typename property<Adaptor>::props_t_it found = property<Adaptor>::find(std::wstring(pStr->get(0)));
+                if (found != property<Adaptor>::fields.end())
                 {
                     found->set(*work, _pSource, controller);
                 }
@@ -525,13 +566,12 @@ private:
     bool toString(std::wostringstream& ostr) override final
     {
         // Deprecated, use the overload instead
-        typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
-        std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
+        const typename property<Adaptor>::props_t& properties = property<Adaptor>::fields;
 
         ostr << L"scicos_" <<  getTypeStr() << L" type :" << '\n';
-        for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it)
+        for (const auto& p : properties)
         {
-            ostr << L"  " << it->name << '\n';
+            ostr << L"  " << p.name << '\n';
         }
         return true;
     }
index 2e639ab..2f90940 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  *  Copyright (C) 2014-2016 - Scilab Enterprises - Clement DAVID
+ *  Copyright (C) 2017 - ESI Group - Clement DAVID
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -27,6 +28,7 @@
 #include "utilities.hxx"
 #include "adapters_utilities.hxx"
 #include "Controller.hxx"
+#include "model/BaseObject.hxx"
 #include "model/Block.hxx"
 #include "BlockAdapter.hxx"
 #include "DiagramAdapter.hxx"
@@ -51,13 +53,13 @@ struct graphics
 {
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
-        GraphicsAdapter localAdaptor(controller, controller.referenceObject(adaptor.getAdaptee()));
+        GraphicsAdapter localAdaptor(controller, controller.referenceBaseObject(adaptor.getAdaptee()));
         return localAdaptor.getAsTList(new types::MList(), controller);
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        GraphicsAdapter localAdaptor(controller, controller.referenceObject(adaptor.getAdaptee()));
+        GraphicsAdapter localAdaptor(controller, controller.referenceBaseObject(adaptor.getAdaptee()));
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -66,13 +68,13 @@ struct model
 {
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
-        ModelAdapter localAdaptor(controller, controller.referenceObject(adaptor.getAdaptee()));
+        ModelAdapter localAdaptor(controller, controller.referenceBaseObject(adaptor.getAdaptee()));
         return localAdaptor.getAsTList(new types::MList(), controller);
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ModelAdapter localAdaptor(controller, controller.referenceObject(adaptor.getAdaptee()));
+        ModelAdapter localAdaptor(controller, controller.referenceBaseObject(adaptor.getAdaptee()));
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -82,8 +84,7 @@ struct gui
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         std::string Interface;
-        ScicosID adaptee = adaptor.getAdaptee()->id();
-        controller.getObjectProperty(adaptee, BLOCK, INTERFACE_FUNCTION, Interface);
+        controller.getObjectProperty(adaptor.getAdaptee(), INTERFACE_FUNCTION, Interface);
 
         return new types::String(Interface.data());
     }
@@ -106,8 +107,7 @@ struct gui
         std::string stName(name);
         FREE(name);
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
-        controller.setObjectProperty(adaptee, BLOCK, INTERFACE_FUNCTION, stName);
+        controller.setObjectProperty(adaptor.getAdaptee(), INTERFACE_FUNCTION, stName);
         return true;
     }
 };
@@ -130,11 +130,11 @@ link_indices_t getPortEnd(const Controller& controller, org_scilab_modules_scico
 {
     ScicosID parent;
     kind_t parentKind = BLOCK;
-    controller.getObjectProperty(adaptee->id(), adaptee->kind(), PARENT_BLOCK, parent);
+    controller.getObjectProperty(adaptee, PARENT_BLOCK, parent);
     if (parent == ScicosID())
     {
         parentKind = DIAGRAM;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PARENT_DIAGRAM, parent);
+        controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parent);
     }
 
     // early return if this block is out of a hierarchy
@@ -143,11 +143,13 @@ link_indices_t getPortEnd(const Controller& controller, org_scilab_modules_scico
         return link_indices_t();
     }
 
+    org_scilab_modules_scicos::model::BaseObject* parentObject = controller.getBaseObject(parent);
+
     std::vector<ScicosID> children;
-    controller.getObjectProperty(parent, parentKind, CHILDREN, children);
+    controller.getObjectProperty(parentObject, CHILDREN, children);
 
     std::vector<ScicosID> ports;
-    controller.getObjectProperty(parent, parentKind, property_from_port(port), children);
+    controller.getObjectProperty(parentObject, property_from_port(port), children);
 
     // store the index of the connected signal, 0 if absent
     link_indices_t portIndices(ports.size());
@@ -179,11 +181,12 @@ BlockAdapter::BlockAdapter(const Controller& c, org_scilab_modules_scicos::model
 {
     if (property<BlockAdapter>::properties_have_not_been_set())
     {
-        property<BlockAdapter>::fields.reserve(4);
+        property<BlockAdapter>::reserve_properties(4);
         property<BlockAdapter>::add_property(L"graphics", &graphics::get, &graphics::set);
         property<BlockAdapter>::add_property(L"model", &model::get, &model::set);
         property<BlockAdapter>::add_property(L"gui", &gui::get, &gui::set);
         property<BlockAdapter>::add_property(L"doc", &doc::get, &doc::set);
+        property<BlockAdapter>::shrink_to_fit();
     }
 }
 
index 498ce78..b4bb0fa 100644 (file)
@@ -52,11 +52,12 @@ static void initialize_fields()
 {
     if (property<CprAdapter>::properties_have_not_been_set())
     {
-        property<CprAdapter>::fields.reserve(4);
+        property<CprAdapter>::reserve_properties(4);
         property<CprAdapter>::add_property(L"state", &dummy_property::get, &dummy_property::set);
         property<CprAdapter>::add_property(L"sim", &dummy_property::get, &dummy_property::set);
         property<CprAdapter>::add_property(L"cor", &dummy_property::get, &dummy_property::set);
         property<CprAdapter>::add_property(L"corinv", &dummy_property::get, &dummy_property::set);
+        property<CprAdapter>::shrink_to_fit();
     }
 }
 
index cb7f5eb..ed8c232 100644 (file)
@@ -68,13 +68,13 @@ struct props
 
     static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
-        ParamsAdapter localAdaptor(controller, controller.referenceObject(adaptor.getAdaptee()));
+        ParamsAdapter localAdaptor(controller, controller.referenceBaseObject<model::BaseObject>(adaptor.getAdaptee()));
         return localAdaptor.getAsTList(new types::TList(), controller);
     }
 
     static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ParamsAdapter localAdaptor(controller, controller.referenceObject(adaptor.getAdaptee()));
+        ParamsAdapter localAdaptor(controller, controller.referenceBaseObject<model::BaseObject>(adaptor.getAdaptee()));
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -86,7 +86,7 @@ struct objs
         model::BaseObject* adaptee = adaptor.getAdaptee();
 
         std::vector<ScicosID> children;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, children);
+        controller.getObjectProperty(adaptee, CHILDREN, children);
         types::List* ret = new types::List();
         // TODO: ret.reserve(children.size());
         for (int i = 0; i < static_cast<int>(children.size()); ++i)
@@ -100,18 +100,18 @@ struct objs
                 continue;
             }
 
-            model::BaseObject* o = controller.getObject(children[i]);
+            model::BaseObject* o = controller.getBaseObject(children[i]);
             switch (o->kind())
             {
                 case ANNOTATION :
-                    ret->append(new TextAdapter(controller, controller.referenceObject<model::Annotation>(o)));
+                    ret->append(new TextAdapter(controller, controller.referenceBaseObject<model::Annotation>(o)));
                     break;
                 case BLOCK :
-                    ret->append(new BlockAdapter(controller, controller.referenceObject<model::Block>(o)));
+                    ret->append(new BlockAdapter(controller, controller.referenceBaseObject<model::Block>(o)));
                     break;
                 case LINK :
                 {
-                    ret->append(new LinkAdapter(controller, controller.referenceObject<model::Link>(o)));
+                    ret->append(new LinkAdapter(controller, controller.referenceBaseObject<model::Link>(o)));
                     break;
                 }
                 default:
@@ -131,7 +131,7 @@ struct objs
     static Adapter* allocAndSet(types::MList* modelElement, Controller& controller)
     {
         ScicosID id = controller.createObject(kind);
-        Adaptee* localAdaptee = controller.getObject<Adaptee>(id);
+        Adaptee* localAdaptee = controller.getBaseObject<Adaptee>(id);
 
         Adapter* localAdaptor = new Adapter(controller, localAdaptee);
         localAdaptor->setAsTList(modelElement, controller);
@@ -206,7 +206,7 @@ struct objs
             {
                 if (u.adaptee != nullptr)
                 {
-                    controller.referenceObject(u.adaptee->id());
+                    controller.referenceBaseObject(u.adaptee);
                 }
             });
         }
@@ -240,7 +240,7 @@ struct objs
 
         // retrieve the current children to update
         std::vector<ScicosID> children;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, children);
+        controller.getObjectProperty(adaptee, CHILDREN, children);
 
         // A boolean to know if we are removing an object
         bool deletion = children.size() > static_cast<size_t>(argumentList->getSize());
@@ -324,7 +324,7 @@ struct objs
 
         // Process the children / parent relationship
         ScicosID parentDiagram;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PARENT_DIAGRAM, parentDiagram);
+        controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parentDiagram);
         int offset = 0;
         for (const auto & update : childrenToUpdate)
         {
@@ -335,7 +335,7 @@ struct objs
             }
             else
             {
-                controller.referenceObject(update.adaptee->id());
+                controller.referenceBaseObject(update.adaptee);
                 if (deletion && children[update.index] == ScicosID())
                 {
                     // This object is the one being deleted in the diagram:
@@ -359,13 +359,13 @@ struct objs
 
                 if (adaptee->kind() == BLOCK)
                 {
-                    controller.setObjectProperty(update.adaptee->id(), update.adaptee->kind(), PARENT_DIAGRAM, parentDiagram);
-                    controller.setObjectProperty(update.adaptee->id(), update.adaptee->kind(), PARENT_BLOCK, adaptee->id());
+                    controller.setObjectProperty(update.adaptee, PARENT_DIAGRAM, parentDiagram);
+                    controller.setObjectProperty(update.adaptee, PARENT_BLOCK, adaptee->id());
                 }
                 else
                 {
-                    controller.setObjectProperty(update.adaptee->id(), update.adaptee->kind(), PARENT_DIAGRAM, adaptee->id());
-                    controller.setObjectProperty(update.adaptee->id(), update.adaptee->kind(), PARENT_BLOCK, ScicosID());
+                    controller.setObjectProperty(update.adaptee, PARENT_DIAGRAM, adaptee->id());
+                    controller.setObjectProperty(update.adaptee, PARENT_BLOCK, ScicosID());
                 }
             }
         }
@@ -383,14 +383,14 @@ struct objs
         {
             if (update.adaptee != nullptr && update.adaptee->kind() == LINK)
             {
-                LinkAdapter::relink(controller, update.adaptee, children);
+                LinkAdapter::relink(controller, static_cast<model::Link*>(update.adaptee), children);
             }
         }
         for (const auto & update : childrenToUpdate)
         {
             if (update.adaptee != nullptr && update.adaptee->kind() == BLOCK)
             {
-                GraphicsAdapter::relink(controller, update.adaptee, children);
+                GraphicsAdapter::relink(controller, static_cast<model::Block*>(update.adaptee), children);
             }
         }
 
@@ -405,7 +405,7 @@ struct objs
         }
 
         // set the children after update
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, children);
+        controller.setObjectProperty(adaptee, CHILDREN, children);
 
         return true;
     }
@@ -422,13 +422,13 @@ struct version
             model::Block* adaptee = static_cast<model::Block*>(adaptor.getAdaptee());
 
             ScicosID parentDiagram;
-            controller.getObjectProperty(adaptee->id(), adaptee->kind(), PARENT_DIAGRAM, parentDiagram);
+            controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parentDiagram);
             controller.getObjectProperty(parentDiagram, DIAGRAM, VERSION_NUMBER, version);
         }
         else
         {
             model::Diagram* adaptee = static_cast<model::Diagram*>(adaptor.getAdaptee());
-            controller.getObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
+            controller.getObjectProperty(adaptee, VERSION_NUMBER, version);
         }
 
         return new types::String(version.data());
@@ -456,7 +456,7 @@ struct version
             std::string version (c_str);
             FREE(c_str);
 
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
+            controller.setObjectProperty(adaptee, VERSION_NUMBER, version);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabDouble)
@@ -476,7 +476,7 @@ struct version
             model::Diagram* adaptee = static_cast<model::Diagram*>(adaptor.getAdaptee());
 
             std::string version;
-            controller.setObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
+            controller.setObjectProperty(adaptee, VERSION_NUMBER, version);
             return true;
         }
 
@@ -510,11 +510,12 @@ DiagramAdapter::DiagramAdapter(const Controller& c, org_scilab_modules_scicos::m
 {
     if (property<DiagramAdapter>::properties_have_not_been_set())
     {
-        property<DiagramAdapter>::fields.reserve(4);
+        property<DiagramAdapter>::reserve_properties(4);
         property<DiagramAdapter>::add_property(L"props", &props::get, &props::set);
         property<DiagramAdapter>::add_property(L"objs", &objs::get, &objs::set);
         property<DiagramAdapter>::add_property(L"version", &version::get, &version::set);
         property<DiagramAdapter>::add_property(L"contrib", &contrib::get, &contrib::set);
+        property<DiagramAdapter>::shrink_to_fit();
     }
 }
 
index 28c70e0..e7aa4af 100644 (file)
@@ -74,10 +74,10 @@ struct orig
     {
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, GEOMETRY, geom);
 
         data[0] = geom[0];
         data[1] = geom[1];
@@ -101,14 +101,14 @@ struct orig
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, GEOMETRY, geom);
 
         geom[0] = current->get(0);
         geom[1] = current->get(1);
 
-        controller.setObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
+        controller.setObjectProperty(adaptee, GEOMETRY, geom);
         return true;
     }
 };
@@ -120,10 +120,10 @@ struct sz
     {
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, GEOMETRY, geom);
 
         data[0] = geom[2];
         data[1] = geom[3];
@@ -145,14 +145,14 @@ struct sz
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
         std::vector<double> geom;
-        controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
+        controller.getObjectProperty(adaptee, GEOMETRY, geom);
 
         geom[2] = current->get(0);
         geom[3] = current->get(1);
 
-        controller.setObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
+        controller.setObjectProperty(adaptee, GEOMETRY, geom);
         return true;
     }
 };
@@ -162,10 +162,10 @@ struct exprs
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> exprs;
-        controller.getObjectProperty(adaptee, BLOCK, EXPRS, exprs);
+        controller.getObjectProperty(adaptee, EXPRS, exprs);
 
         types::InternalType* res;
         if (!vec2var(exprs, res))
@@ -177,7 +177,7 @@ struct exprs
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         // Corner-case the content is an empty matrix
         if (v->getType() == types::InternalType::ScilabDouble)
@@ -194,12 +194,12 @@ struct exprs
         {
             return false;
         }
-        controller.setObjectProperty(adaptee, BLOCK, EXPRS, exprs);
+        controller.setObjectProperty(adaptee, EXPRS, exprs);
         return true;
     }
 };
 
-std::vector<int> cached_ports_init(std::map<ScicosID, std::vector<int> >& cache, const model::Block* adaptee, const object_properties_t port_kind, const Controller& controller)
+std::vector<int> cached_ports_init(std::map<ScicosID, std::vector<int> >& cache, model::Block* adaptee, const object_properties_t port_kind, const Controller& controller)
 {
     auto it = cache.find(adaptee->id());
     if (it != cache.end())
@@ -209,16 +209,16 @@ std::vector<int> cached_ports_init(std::map<ScicosID, std::vector<int> >& cache,
     }
 
     std::vector<ScicosID> ids;
-    controller.getObjectProperty(adaptee->id(), BLOCK, port_kind, ids);
+    controller.getObjectProperty(adaptee, port_kind, ids);
 
     std::vector<ScicosID> children;
     ScicosID parentBlock;
-    controller.getObjectProperty(adaptee->id(), BLOCK, PARENT_BLOCK, parentBlock);
+    controller.getObjectProperty(adaptee, PARENT_BLOCK, parentBlock);
     if (parentBlock == ScicosID())
     {
         // Adding to a diagram
         ScicosID parentDiagram;
-        controller.getObjectProperty(adaptee->id(), BLOCK, PARENT_DIAGRAM, parentDiagram);
+        controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parentDiagram);
 
         controller.getObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
     }
@@ -317,7 +317,7 @@ bool cached_ports_set(std::map<ScicosID, std::vector<int> >& cache, GraphicsAdap
         const std::vector<int>& ports = it->second;
 
         std::vector<ScicosID> objects;
-        controller.getObjectProperty(adaptor.getAdaptee()->id(), BLOCK, port_kind, objects);
+        controller.getObjectProperty(adaptor.getAdaptee(), port_kind, objects);
 
         if (ports.size() < objects.size())
         {
@@ -330,16 +330,17 @@ bool cached_ports_set(std::map<ScicosID, std::vector<int> >& cache, GraphicsAdap
                 controller.getObjectProperty(p, PORT, CONNECTED_SIGNALS, signal);
                 if (signal != ScicosID())
                 {
+                    model::Link* link = controller.getBaseObject<model::Link>(signal);
                     ScicosID opposite;
-                    controller.getObjectProperty(signal, LINK, DESTINATION_PORT, opposite);
+                    controller.getObjectProperty(link, DESTINATION_PORT, opposite);
                     if (opposite == p)
                     {
-                        controller.setObjectProperty(signal, LINK, DESTINATION_PORT, ScicosID());
+                        controller.setObjectProperty(link, DESTINATION_PORT, ScicosID());
                     }
-                    controller.getObjectProperty(signal, LINK, SOURCE_PORT, opposite);
+                    controller.getObjectProperty(link, SOURCE_PORT, opposite);
                     if (opposite == p)
                     {
-                        controller.setObjectProperty(signal, LINK, SOURCE_PORT, ScicosID());
+                        controller.setObjectProperty(link, SOURCE_PORT, ScicosID());
                     }
                 }
                 controller.deleteObject(p);
@@ -351,15 +352,15 @@ bool cached_ports_set(std::map<ScicosID, std::vector<int> >& cache, GraphicsAdap
             // add missing ports
             for (size_t i = objects.size(); i < ports.size(); ++i)
             {
-                ScicosID p = controller.createObject(PORT);
+                model::Port* p = controller.createBaseObject<model::Port>(PORT);
 
-                controller.setObjectProperty(p, PORT, SOURCE_BLOCK, adaptor.getAdaptee()->id());
-                controller.setObjectProperty(p, PORT, PORT_KIND, port_from_property(port_kind));
+                controller.setObjectProperty(p, SOURCE_BLOCK, adaptor.getAdaptee()->id());
+                controller.setObjectProperty(p, PORT_KIND, port_from_property(port_kind));
 
-                objects.push_back(p);
+                objects.push_back(p->id());
             }
         }
-        controller.setObjectProperty(adaptor.getAdaptee()->id(), BLOCK, port_kind, objects);
+        controller.setObjectProperty(adaptor.getAdaptee(), port_kind, objects);
     }
     return true;
 }
@@ -566,17 +567,17 @@ struct style
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::string style;
-        controller.getObjectProperty(adaptee, BLOCK, STYLE, style);
+        controller.getObjectProperty(adaptee, STYLE, style);
 
         return new types::String(style.c_str());
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
         if (v->getType() == types::InternalType::ScilabString)
         {
             types::String* current = v->getAs<types::String>();
@@ -590,7 +591,7 @@ struct style
             std::string style(c_str);
             FREE(c_str);
 
-            controller.setObjectProperty(adaptee, BLOCK, STYLE, style);
+            controller.setObjectProperty(adaptee, STYLE, style);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabDouble)
@@ -603,7 +604,7 @@ struct style
             }
 
             std::string style;
-            controller.setObjectProperty(adaptee, BLOCK, STYLE, style);
+            controller.setObjectProperty(adaptee, STYLE, style);
             return true;
         }
 
@@ -619,7 +620,7 @@ static void initialize_fields()
 {
     if (property<GraphicsAdapter>::properties_have_not_been_set())
     {
-        property<GraphicsAdapter>::fields.reserve(16);
+        property<GraphicsAdapter>::reserve_properties(16);
         property<GraphicsAdapter>::add_property(L"orig", &orig::get, &orig::set);
         property<GraphicsAdapter>::add_property(L"sz", &sz::get, &sz::set);
         property<GraphicsAdapter>::add_property(L"exprs", &exprs::get, &exprs::set);
@@ -636,6 +637,7 @@ static void initialize_fields()
         property<GraphicsAdapter>::add_property(L"in_label", &in_label::get, &in_label::set);
         property<GraphicsAdapter>::add_property(L"out_label", &out_label::get, &out_label::set);
         property<GraphicsAdapter>::add_property(L"style", &style::get, &style::set);
+        property<GraphicsAdapter>::shrink_to_fit();
     }
 }
 
@@ -710,7 +712,7 @@ static void relink_cached(Controller& controller, model::BaseObject* adaptee, co
     std::vector<int>& cached_information = it->second;
 
     std::vector<ScicosID> ports;
-    controller.getObjectProperty(adaptee->id(), BLOCK, p, ports);
+    controller.getObjectProperty(adaptee, p, ports);
 
     if (cached_information.size() != ports.size())
     {
@@ -740,7 +742,7 @@ static void relink_cached(Controller& controller, model::BaseObject* adaptee, co
     }
 }
 
-void GraphicsAdapter::relink(Controller& controller, model::BaseObject* adaptee, const std::vector<ScicosID>& children)
+void GraphicsAdapter::relink(Controller& controller, model::Block* adaptee, const std::vector<ScicosID>& children)
 {
     relink_cached(controller, adaptee, children, partial_pin, INPUTS);
     relink_cached(controller, adaptee, children, partial_pout, OUTPUTS);
@@ -775,14 +777,14 @@ void GraphicsAdapter::add_partial_links_information(Controller& controller, mode
 
     switch (original->kind())
     {
-            // handle recursion
+        // handle recursion
         case DIAGRAM:
         case BLOCK:
         {
             std::vector<ScicosID> originalChildren;
-            controller.getObjectProperty(original->id(), original->kind(), CHILDREN, originalChildren);
+            controller.getObjectProperty(original, CHILDREN, originalChildren);
             std::vector<ScicosID> clonedChildren;
-            controller.getObjectProperty(cloned->id(), cloned->kind(), CHILDREN, clonedChildren);
+            controller.getObjectProperty(cloned, CHILDREN, clonedChildren);
 
             for (size_t i = 0; i < originalChildren.size(); ++i)
             {
@@ -790,7 +792,7 @@ void GraphicsAdapter::add_partial_links_information(Controller& controller, mode
                 // this loop
                 if (originalChildren[i] != ScicosID())
                 {
-                    add_partial_links_information(controller, controller.getObject(originalChildren[i]), controller.getObject(clonedChildren[i]));
+                    add_partial_links_information(controller, controller.getBaseObject(originalChildren[i]), controller.getBaseObject(clonedChildren[i]));
                 }
             }
             break;
@@ -801,7 +803,7 @@ void GraphicsAdapter::add_partial_links_information(Controller& controller, mode
     }
 }
 
-void GraphicsAdapter::remove_partial_links_information(model::BaseObject* o)
+void GraphicsAdapter::remove_partial_links_information(model::Block* o)
 {
     partial_pin.erase(o->id());
     partial_pout.erase(o->id());
index edbb320..a6731d6 100644 (file)
@@ -48,11 +48,11 @@ public:
     void setGrIContent(types::InternalType* v);
 
     // move (if possible) the partial information to the model
-    static void relink(Controller& controller, model::BaseObject* adaptee, const std::vector<ScicosID>& children);
+    static void relink(Controller& controller, model::Block* adaptee, const std::vector<ScicosID>& children);
     // manage partial information after a model clone
     static void add_partial_links_information(Controller& controller, model::BaseObject* original, model::BaseObject* cloned);
     // remove partial links information (on delete)
-    static void remove_partial_links_information(model::BaseObject* o);
+    static void remove_partial_links_information(model::Block* o);
 
 private:
     types::InternalType* gr_i_content;
index 77f8b35..93762bc 100644 (file)
@@ -33,6 +33,7 @@
 #include "controller_helpers.hxx"
 #include "model/Link.hxx"
 #include "model/Port.hxx"
+#include "model/Block.hxx"
 
 extern "C" {
 #include "sci_malloc.h"
@@ -59,10 +60,10 @@ struct xx
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         std::vector<double> controlPoints;
-        controller.getObjectProperty(adaptee, LINK, CONTROL_POINTS, controlPoints);
+        controller.getObjectProperty(adaptee, CONTROL_POINTS, controlPoints);
 
         double* data;
         int size = (int)controlPoints.size() / 2;
@@ -77,7 +78,7 @@ struct xx
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -88,7 +89,7 @@ struct xx
         types::Double* current = v->getAs<types::Double>();
 
         std::vector<double> controlPoints;
-        controller.getObjectProperty(adaptee, LINK, CONTROL_POINTS, controlPoints);
+        controller.getObjectProperty(adaptee, CONTROL_POINTS, controlPoints);
 
         int newXSize = current->getSize();
         int oldXSize = static_cast<int>(controlPoints.size() / 2);
@@ -111,7 +112,7 @@ struct xx
             }
         }
 
-        controller.setObjectProperty(adaptee, LINK, CONTROL_POINTS, newControlPoints);
+        controller.setObjectProperty(adaptee, CONTROL_POINTS, newControlPoints);
         return true;
     }
 };
@@ -121,10 +122,10 @@ struct yy
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         std::vector<double> controlPoints;
-        controller.getObjectProperty(adaptee, LINK, CONTROL_POINTS, controlPoints);
+        controller.getObjectProperty(adaptee, CONTROL_POINTS, controlPoints);
 
         double* data;
         int size = (int)controlPoints.size() / 2;
@@ -139,7 +140,7 @@ struct yy
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -150,7 +151,7 @@ struct yy
         types::Double* current = v->getAs<types::Double>();
 
         std::vector<double> controlPoints;
-        controller.getObjectProperty(adaptee, LINK, CONTROL_POINTS, controlPoints);
+        controller.getObjectProperty(adaptee, CONTROL_POINTS, controlPoints);
 
         int newYSize = current->getSize();
         int oldYSize = static_cast<int>(controlPoints.size() / 2);
@@ -173,7 +174,7 @@ struct yy
             }
         }
 
-        controller.setObjectProperty(adaptee, LINK, CONTROL_POINTS, newControlPoints);
+        controller.setObjectProperty(adaptee, CONTROL_POINTS, newControlPoints);
         return true;
     }
 };
@@ -183,10 +184,10 @@ struct id
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         std::string id;
-        controller.getObjectProperty(adaptee, LINK, DESCRIPTION, id);
+        controller.getObjectProperty(adaptee, DESCRIPTION, id);
 
         types::String* o = new types::String(id.data());
         return o;
@@ -207,13 +208,13 @@ struct id
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         char* c_str = wide_string_to_UTF8(current->get(0));
         std::string description(c_str);
         FREE(c_str);
 
-        controller.setObjectProperty(adaptee, LINK, DESCRIPTION, description);
+        controller.setObjectProperty(adaptee, DESCRIPTION, description);
         return true;
     }
 };
@@ -223,10 +224,10 @@ struct thick
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         std::vector<double> thick;
-        controller.getObjectProperty(adaptee, LINK, THICK, thick);
+        controller.getObjectProperty(adaptee, THICK, thick);
 
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
@@ -238,7 +239,7 @@ struct thick
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -257,7 +258,7 @@ struct thick
         thick[0] = current->get(0);
         thick[1] = current->get(1);
 
-        controller.setObjectProperty(adaptee, LINK, THICK, thick);
+        controller.setObjectProperty(adaptee, THICK, thick);
         return true;
     }
 };
@@ -267,12 +268,12 @@ struct ct
 
     static types::InternalType* get(const LinkAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         int color;
         int kind;
-        controller.getObjectProperty(adaptee, LINK, COLOR, color);
-        controller.getObjectProperty(adaptee, LINK, KIND, kind);
+        controller.getObjectProperty(adaptee, COLOR, color);
+        controller.getObjectProperty(adaptee, KIND, kind);
 
         double* data;
         types::Double* o = new types::Double(1, 2, &data);
@@ -284,7 +285,7 @@ struct ct
 
     static bool set(LinkAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Link* adaptee = adaptor.getAdaptee();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -304,13 +305,13 @@ struct ct
         int color = static_cast<int>(current->get(0));
         int kind  = static_cast<int>(current->get(1));
 
-        controller.setObjectProperty(adaptee, LINK, COLOR, color);
-        controller.setObjectProperty(adaptee, LINK, KIND, kind);
+        controller.setObjectProperty(adaptee, COLOR, color);
+        controller.setObjectProperty(adaptee, KIND, kind);
         return true;
     }
 };
 
-link_t getLinkEnd(ScicosID adaptee, const Controller& controller, const object_properties_t end)
+link_t getLinkEnd(model::Link* adaptee, const Controller& controller, const object_properties_t end)
 {
     link_t ret {0, 0, Start};
     if (end == DESTINATION_PORT)
@@ -319,22 +320,23 @@ link_t getLinkEnd(ScicosID adaptee, const Controller& controller, const object_p
     }
 
     ScicosID endID;
-    controller.getObjectProperty(adaptee, LINK, end, endID);
+    controller.getObjectProperty(adaptee, end, endID);
     if (endID != ScicosID())
     {
         ScicosID sourceBlock;
         controller.getObjectProperty(endID, PORT, SOURCE_BLOCK, sourceBlock);
+        model::Block* sourceBlockObject = controller.getBaseObject<model::Block>(sourceBlock);
 
         // Looking for the block number among the block IDs
         ScicosID parent;
         kind_t parentKind = BLOCK;
-        controller.getObjectProperty(adaptee, LINK, PARENT_BLOCK, parent);
+        controller.getObjectProperty(adaptee, PARENT_BLOCK, parent);
         std::vector<ScicosID> children;
         // Added to a superblock
         if (parent == ScicosID())
         {
             // Added to a diagram
-            controller.getObjectProperty(adaptee, LINK, PARENT_DIAGRAM, parent);
+            controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parent);
             parentKind = DIAGRAM;
             if (parent == ScicosID())
             {
@@ -347,23 +349,23 @@ link_t getLinkEnd(ScicosID adaptee, const Controller& controller, const object_p
 
         // To find the port index from its 'endID' ID, search through all the block's ports lists
         std::vector<ScicosID> sourceBlockPorts;
-        controller.getObjectProperty(sourceBlock, BLOCK, INPUTS, sourceBlockPorts);
+        controller.getObjectProperty(sourceBlockObject, INPUTS, sourceBlockPorts);
 
         std::vector<ScicosID>::iterator found = std::find(sourceBlockPorts.begin(), sourceBlockPorts.end(), endID);
         if (found == sourceBlockPorts.end()) // Not found in the data inputs
         {
             sourceBlockPorts.clear();
-            controller.getObjectProperty(sourceBlock, BLOCK, OUTPUTS, sourceBlockPorts);
+            controller.getObjectProperty(sourceBlockObject, OUTPUTS, sourceBlockPorts);
             found = std::find(sourceBlockPorts.begin(), sourceBlockPorts.end(), endID);
             if (found == sourceBlockPorts.end()) // Not found in the data outputs
             {
                 sourceBlockPorts.clear();
-                controller.getObjectProperty(sourceBlock, BLOCK, EVENT_INPUTS, sourceBlockPorts);
+                controller.getObjectProperty(sourceBlockObject, EVENT_INPUTS, sourceBlockPorts);
                 found = std::find(sourceBlockPorts.begin(), sourceBlockPorts.end(), endID);
                 if (found == sourceBlockPorts.end()) // Not found in the event inputs
                 {
                     sourceBlockPorts.clear();
-                    controller.getObjectProperty(sourceBlock, BLOCK, EVENT_OUTPUTS, sourceBlockPorts);
+                    controller.getObjectProperty(sourceBlockObject, EVENT_OUTPUTS, sourceBlockPorts);
                     found = std::find(sourceBlockPorts.begin(), sourceBlockPorts.end(), endID);
                     if (found == sourceBlockPorts.end()) // Not found in the event outputs
                     {
@@ -393,7 +395,7 @@ link_t getLinkEnd(ScicosID adaptee, const Controller& controller, const object_p
  * Connectivity is ensured if 'port' is of the desired type or if either of the concerned blocks is a split block,
  * because they are connectable to anything
  */
-bool checkConnectivity(const int neededType, const ScicosID port, const ScicosID blk1, Controller& controller)
+bool checkConnectivity(const int neededType, const ScicosID port, model::Block* blk1, Controller& controller)
 {
     int portKind;
     controller.getObjectProperty(port, PORT, PORT_KIND, portKind);
@@ -402,7 +404,7 @@ bool checkConnectivity(const int neededType, const ScicosID port, const ScicosID
     {
         // Last chance if one of the connecting blocks is just a split block
         std::string name1;
-        controller.getObjectProperty(blk1, BLOCK, SIM_FUNCTION_NAME, name1);
+        controller.getObjectProperty(blk1, SIM_FUNCTION_NAME, name1);
         if (name1 != split && name1 != lsplit && name1 != limpsplit)
         {
             ScicosID blk2;
@@ -418,12 +420,12 @@ bool checkConnectivity(const int neededType, const ScicosID port, const ScicosID
     return true;
 }
 
-void setLinkEnd(const ScicosID id, Controller& controller, const object_properties_t end, const link_t& v, const std::vector<ScicosID>& children)
+void setLinkEnd(model::Link* linkObject, Controller& controller, const object_properties_t end, const link_t& v, const std::vector<ScicosID>& children)
 {
     ScicosID from;
-    controller.getObjectProperty(id, LINK, SOURCE_PORT, from);
+    controller.getObjectProperty(linkObject, SOURCE_PORT, from);
     ScicosID to;
-    controller.getObjectProperty(id, LINK, DESTINATION_PORT, to);
+    controller.getObjectProperty(linkObject, DESTINATION_PORT, to);
     ScicosID concernedPort;
     ScicosID otherPort;
     switch (end)
@@ -446,13 +448,13 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
         if (concernedPort == ScicosID())
         {
             // In this case, the link was already empty, do a dummy call to display the console status.
-            controller.setObjectProperty(id, LINK, end, concernedPort);
+            controller.setObjectProperty(linkObject, end, concernedPort);
         }
         else
         {
             // Untie the old link on the concerned end and set its port as unconnected
             controller.setObjectProperty(concernedPort, PORT, CONNECTED_SIGNALS, ScicosID());
-            controller.setObjectProperty(id, LINK, end, ScicosID());
+            controller.setObjectProperty(linkObject, end, ScicosID());
         }
         return;
     }
@@ -479,7 +481,8 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
     }
 
     // Check that the ID designates a BLOCK (and not an ANNOTATION)
-    if (controller.getObject(blkID)->kind() != BLOCK)
+    model::Block* blkObject = controller.getBaseObject<model::Block>(blkID);
+    if (blkObject->kind() != BLOCK)
     {
         return;
     }
@@ -491,19 +494,19 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
     bool newPortIsImplicit = false;
     enum portKind newPortKind = PORT_UNDEF;
     int linkType;
-    controller.getObjectProperty(id, LINK, KIND, linkType);
+    controller.getObjectProperty(linkObject, KIND, linkType);
     if (linkType == model::activation)
     {
         std::vector<ScicosID> evtin;
         std::vector<ScicosID> evtout;
-        controller.getObjectProperty(blkID, BLOCK, EVENT_INPUTS, evtin);
-        controller.getObjectProperty(blkID, BLOCK, EVENT_OUTPUTS, evtout);
+        controller.getObjectProperty(blkObject, EVENT_INPUTS, evtin);
+        controller.getObjectProperty(blkObject, EVENT_OUTPUTS, evtout);
 
         if (v.kind == Start)
         {
             if (otherPort != ScicosID())
             {
-                if (!checkConnectivity(PORT_EIN, otherPort, blkID, controller))
+                if (!checkConnectivity(PORT_EIN, otherPort, blkObject, controller))
                 {
                     return;
                 }
@@ -515,7 +518,7 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
         {
             if (otherPort != ScicosID())
             {
-                if (!checkConnectivity(PORT_EOUT, otherPort, blkID, controller))
+                if (!checkConnectivity(PORT_EOUT, otherPort, blkObject, controller))
                 {
                     return;
                 }
@@ -529,8 +532,8 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
     {
         std::vector<ScicosID> in;
         std::vector<ScicosID> out;
-        controller.getObjectProperty(blkID, BLOCK, INPUTS, in);
-        controller.getObjectProperty(blkID, BLOCK, OUTPUTS, out);
+        controller.getObjectProperty(blkObject, INPUTS, in);
+        controller.getObjectProperty(blkObject, OUTPUTS, out);
 
         if (linkType == model::regular)
         {
@@ -538,7 +541,7 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
             {
                 if (otherPort != ScicosID())
                 {
-                    if (!checkConnectivity(PORT_IN, otherPort, blkID, controller))
+                    if (!checkConnectivity(PORT_IN, otherPort, blkObject, controller))
                     {
                         return;
                     }
@@ -550,7 +553,7 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
             {
                 if (otherPort != ScicosID())
                 {
-                    if (!checkConnectivity(PORT_OUT, otherPort, blkID, controller))
+                    if (!checkConnectivity(PORT_OUT, otherPort, blkObject, controller))
                     {
                         return;
                     }
@@ -609,54 +612,57 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
         controller.setObjectProperty(concernedPort, PORT, CONNECTED_SIGNALS, ScicosID());
     }
 
+    model::Port* concernedPortObject;
     int nBlockPorts = static_cast<int>(sourceBlockPorts.size());
     if (nBlockPorts >= portIndex)
     {
         concernedPort = sourceBlockPorts[portIndex - 1];
+        concernedPortObject = controller.getBaseObject<model::Port>(concernedPort);
     }
     else
     {
         while (nBlockPorts < portIndex) // Create as many ports as necessary
         {
-            concernedPort = controller.createObject(PORT);
-            controller.setObjectProperty(concernedPort, PORT, IMPLICIT, newPortIsImplicit);
-            controller.setObjectProperty(concernedPort, PORT, PORT_KIND, static_cast<int>(newPortKind));
-            controller.setObjectProperty(concernedPort, PORT, SOURCE_BLOCK, blkID);
-            controller.setObjectProperty(concernedPort, PORT, CONNECTED_SIGNALS, ScicosID());
+            concernedPortObject = controller.createBaseObject<model::Port>(PORT);
+            concernedPort = concernedPortObject->id();
+            controller.setObjectProperty(concernedPortObject, IMPLICIT, newPortIsImplicit);
+            controller.setObjectProperty(concernedPortObject, PORT_KIND, static_cast<int>(newPortKind));
+            controller.setObjectProperty(concernedPortObject, SOURCE_BLOCK, blkID);
+            controller.setObjectProperty(concernedPortObject, CONNECTED_SIGNALS, ScicosID());
             // Set the default dataType so it is saved in the model
             std::vector<int> dataType;
-            controller.getObjectProperty(concernedPort, PORT, DATATYPE, dataType);
-            controller.setObjectProperty(concernedPort, PORT, DATATYPE, dataType);
+            controller.getObjectProperty(concernedPortObject, DATATYPE, dataType);
+            controller.setObjectProperty(concernedPortObject, DATATYPE, dataType);
 
             std::vector<ScicosID> concernedPorts;
             if (linkType == model::activation)
             {
                 if (v.kind == Start)
                 {
-                    controller.getObjectProperty(blkID, BLOCK, EVENT_OUTPUTS, concernedPorts);
+                    controller.getObjectProperty(blkObject, EVENT_OUTPUTS, concernedPorts);
                     concernedPorts.push_back(concernedPort);
-                    controller.setObjectProperty(blkID, BLOCK, EVENT_OUTPUTS, concernedPorts);
+                    controller.setObjectProperty(blkObject, EVENT_OUTPUTS, concernedPorts);
                 }
                 else
                 {
-                    controller.getObjectProperty(blkID, BLOCK, EVENT_INPUTS, concernedPorts);
+                    controller.getObjectProperty(blkObject, EVENT_INPUTS, concernedPorts);
                     concernedPorts.push_back(concernedPort);
-                    controller.setObjectProperty(blkID, BLOCK, EVENT_INPUTS, concernedPorts);
+                    controller.setObjectProperty(blkObject, EVENT_INPUTS, concernedPorts);
                 }
             }
             else // model::regular || model::implicit
             {
                 if (v.kind == Start)
                 {
-                    controller.getObjectProperty(blkID, BLOCK, OUTPUTS, concernedPorts);
+                    controller.getObjectProperty(blkObject, OUTPUTS, concernedPorts);
                     concernedPorts.push_back(concernedPort);
-                    controller.setObjectProperty(blkID, BLOCK, OUTPUTS, concernedPorts);
+                    controller.setObjectProperty(blkObject, OUTPUTS, concernedPorts);
                 }
                 else
                 {
-                    controller.getObjectProperty(blkID, BLOCK, INPUTS, concernedPorts);
+                    controller.getObjectProperty(blkObject, INPUTS, concernedPorts);
                     concernedPorts.push_back(concernedPort);
-                    controller.setObjectProperty(blkID, BLOCK, INPUTS, concernedPorts);
+                    controller.setObjectProperty(blkObject, INPUTS, concernedPorts);
                 }
             }
 
@@ -664,7 +670,7 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
         }
     }
     ScicosID oldLink;
-    controller.getObjectProperty(concernedPort, PORT, CONNECTED_SIGNALS, oldLink);
+    controller.getObjectProperty(concernedPortObject, CONNECTED_SIGNALS, oldLink);
     if (oldLink != ScicosID())
     {
         // Disconnect the old link if it was indeed connected to the concerned port
@@ -677,8 +683,8 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
     }
 
     // Connect the new source and destination ports together
-    controller.setObjectProperty(concernedPort, PORT, CONNECTED_SIGNALS, id);
-    controller.setObjectProperty(id, LINK, end, concernedPort);
+    controller.setObjectProperty(concernedPortObject, CONNECTED_SIGNALS, linkObject->id());
+    controller.setObjectProperty(linkObject, end, concernedPort);
 }
 
 // Check if the Link is valid
@@ -729,7 +735,7 @@ struct from
         if (it == partial_links.end())
         {
             // if not found use the connected value
-            from_content = getLinkEnd(adaptor.getAdaptee()->id(), controller, SOURCE_PORT);
+            from_content = getLinkEnd(adaptor.getAdaptee(), controller, SOURCE_PORT);
         }
         else
         {
@@ -779,7 +785,7 @@ struct from
         {
             partial_link_t l;
             l.from = from_content;
-            l.to = getLinkEnd(adaptor.getAdaptee()->id(), controller, DESTINATION_PORT);
+            l.to = getLinkEnd(adaptor.getAdaptee(), controller, DESTINATION_PORT);
             partial_links.insert({adaptor.getAdaptee()->id(), l});
         }
         else
@@ -801,7 +807,7 @@ struct to
         if (it == partial_links.end())
         {
             // if not found use the connected value
-            to_content = getLinkEnd(adaptor.getAdaptee()->id(), controller, DESTINATION_PORT);
+            to_content = getLinkEnd(adaptor.getAdaptee(), controller, DESTINATION_PORT);
         }
         else
         {
@@ -855,7 +861,7 @@ struct to
         if (it == partial_links.end())
         {
             partial_link_t l;
-            l.from = getLinkEnd(adaptor.getAdaptee()->id(), controller, SOURCE_PORT);
+            l.from = getLinkEnd(adaptor.getAdaptee(), controller, SOURCE_PORT);
             l.to = to_content;
             partial_links.insert({adaptor.getAdaptee()->id(), l});
         }
@@ -876,7 +882,7 @@ LinkAdapter::LinkAdapter(const Controller& c, org_scilab_modules_scicos::model::
 {
     if (property<LinkAdapter>::properties_have_not_been_set())
     {
-        property<LinkAdapter>::fields.reserve(7);
+        property<LinkAdapter>::reserve_properties(7);
         property<LinkAdapter>::add_property(L"xx", &xx::get, &xx::set);
         property<LinkAdapter>::add_property(L"yy", &yy::get, &yy::set);
         property<LinkAdapter>::add_property(L"id", &id::get, &id::set);
@@ -884,6 +890,7 @@ LinkAdapter::LinkAdapter(const Controller& c, org_scilab_modules_scicos::model::
         property<LinkAdapter>::add_property(L"ct", &ct::get, &ct::set);
         property<LinkAdapter>::add_property(L"from", &from::get, &from::set);
         property<LinkAdapter>::add_property(L"to", &to::get, &to::set);
+        property<LinkAdapter>::shrink_to_fit();
     }
 }
 
@@ -911,7 +918,7 @@ std::wstring LinkAdapter::getShortTypeStr() const
     return getSharedTypeStr();
 }
 
-void LinkAdapter::relink(Controller& controller, model::BaseObject* adaptee, const std::vector<ScicosID>& children)
+void LinkAdapter::relink(Controller& controller, model::Link* adaptee, const std::vector<ScicosID>& children)
 {
     auto it = partial_links.find(adaptee->id());
     if (it == partial_links.end())
@@ -921,14 +928,14 @@ void LinkAdapter::relink(Controller& controller, model::BaseObject* adaptee, con
     }
     partial_link_t l = it->second;
 
-    setLinkEnd(adaptee->id(), controller, SOURCE_PORT, l.from, children);
-    setLinkEnd(adaptee->id(), controller, DESTINATION_PORT, l.to, children);
+    setLinkEnd(adaptee, controller, SOURCE_PORT, l.from, children);
+    setLinkEnd(adaptee, controller, DESTINATION_PORT, l.to, children);
 
     // refresh the shared values
     ScicosID from;
-    controller.getObjectProperty(adaptee->id(), LINK, SOURCE_PORT, from);
+    controller.getObjectProperty(adaptee, SOURCE_PORT, from);
     ScicosID to;
-    controller.getObjectProperty(adaptee->id(), LINK, DESTINATION_PORT, to);
+    controller.getObjectProperty(adaptee, DESTINATION_PORT, to);
 
     bool isConnected = from != ScicosID() && to != ScicosID();
     if (isConnected)
@@ -958,8 +965,8 @@ void LinkAdapter::add_partial_links_information(Controller& controller, model::B
             else
             {
                 partial_link_t l;
-                l.from = getLinkEnd(original->id(), controller, SOURCE_PORT);
-                l.to = getLinkEnd(original->id(), controller, DESTINATION_PORT);
+                l.from = getLinkEnd(static_cast<model::Link*>(original), controller, SOURCE_PORT);
+                l.to = getLinkEnd(static_cast<model::Link*>(original), controller, DESTINATION_PORT);
                 partial_links.insert({cloned->id(), l});
             }
             break;
@@ -976,7 +983,7 @@ void LinkAdapter::add_partial_links_information(Controller& controller, model::B
 
             for (size_t i = 0; i < originalChildren.size(); ++i)
             {
-                add_partial_links_information(controller, controller.getObject(originalChildren[i]), controller.getObject(clonedChildren[i]));
+                add_partial_links_information(controller, controller.getBaseObject(originalChildren[i]), controller.getBaseObject(clonedChildren[i]));
             }
             break;
         }
index 84fbf87..801d891 100644 (file)
@@ -43,9 +43,9 @@ public:
     std::wstring getShortTypeStr() const;
 
     // move (if possible) the partial informatios to the model
-    static void relink(Controller& controller, model::BaseObject* adaptee, const std::vector<ScicosID>& children);
+    static void relink(Controller& controller, model::Link* adaptee, const std::vector<ScicosID>& children);
     // manage partial information after a model clone
-    static void add_partial_links_information(Controller& controller, model::BaseObject* original, model::BaseObject* cloned);
+       static void add_partial_links_information(Controller& controller, model::BaseObject* original, model::BaseObject* cloned);
 
 };
 
index 75cc7d1..c0921ea 100644 (file)
@@ -64,10 +64,10 @@ const std::wstring parameters (L"parameters");
 
 types::InternalType* get_with_vec2var(const ModelAdapter& adaptor, const Controller& controller, object_properties_t p)
 {
-    ScicosID adaptee = adaptor.getAdaptee()->id();
+    model::Block* adaptee = adaptor.getAdaptee();
 
     std::vector<double> prop_content;
-    controller.getObjectProperty(adaptee, BLOCK, p, prop_content);
+    controller.getObjectProperty(adaptee, p, prop_content);
 
     // Corner-case, the empty content is an empty double
     if (prop_content.empty())
@@ -87,7 +87,7 @@ types::InternalType* get_with_vec2var(const ModelAdapter& adaptor, const Control
 
 bool set_with_var2vec(ModelAdapter& adaptor, types::InternalType* v, Controller& controller, object_properties_t p)
 {
-    ScicosID adaptee = adaptor.getAdaptee()->id();
+    model::Block* adaptee = adaptor.getAdaptee();
 
     // corner-case the empty content is an empty-double
     if (v->getType() == types::InternalType::ScilabDouble)
@@ -100,7 +100,7 @@ bool set_with_var2vec(ModelAdapter& adaptor, types::InternalType* v, Controller&
 
         // prop_content should be empty
         std::vector<double> prop_content;
-        controller.setObjectProperty(adaptee, BLOCK, p, prop_content);
+        controller.setObjectProperty(adaptee, p, prop_content);
         return true;
     }
 
@@ -110,7 +110,7 @@ bool set_with_var2vec(ModelAdapter& adaptor, types::InternalType* v, Controller&
         return false;
     }
 
-    controller.setObjectProperty(adaptee, BLOCK, p, prop_content);
+    controller.setObjectProperty(adaptee, p, prop_content);
     return true;
 }
 
@@ -119,17 +119,17 @@ struct sim
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         // First, extract the function Name
         std::string name;
-        controller.getObjectProperty(adaptee, BLOCK, SIM_FUNCTION_NAME, name);
+        controller.getObjectProperty(adaptee, 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, BLOCK, SIM_FUNCTION_API, api);
+        controller.getObjectProperty(adaptee, SIM_FUNCTION_API, api);
 
         if (api == 0)
         {
@@ -147,7 +147,7 @@ struct sim
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         if (v->getType() == types::InternalType::ScilabString)
         {
@@ -165,8 +165,8 @@ struct sim
             // If the input is a scalar string, then the functionApi is 0.
             int api = 0;
 
-            controller.setObjectProperty(adaptee, BLOCK, SIM_FUNCTION_NAME, name);
-            controller.setObjectProperty(adaptee, BLOCK, SIM_FUNCTION_API, api);
+            controller.setObjectProperty(adaptee, SIM_FUNCTION_NAME, name);
+            controller.setObjectProperty(adaptee, SIM_FUNCTION_API, api);
         }
         else if (v->getType() == types::InternalType::ScilabList)
         {
@@ -207,8 +207,8 @@ struct sim
             }
             int api_int = static_cast<int>(api);
 
-            controller.setObjectProperty(adaptee, BLOCK, SIM_FUNCTION_NAME, name);
-            controller.setObjectProperty(adaptee, BLOCK, SIM_FUNCTION_API, api_int);
+            controller.setObjectProperty(adaptee, SIM_FUNCTION_NAME, name);
+            controller.setObjectProperty(adaptee, SIM_FUNCTION_API, api_int);
         }
         else
         {
@@ -336,10 +336,10 @@ struct state
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> state;
-        controller.getObjectProperty(adaptee, BLOCK, STATE, state);
+        controller.getObjectProperty(adaptee, STATE, state);
 
         double* data;
         types::Double* o = new types::Double((int)state.size(), 1, &data);
@@ -369,12 +369,12 @@ struct state
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> state (current->getSize());
         std::copy(current->getReal(), current->getReal() + current->getSize(), state.begin());
 
-        controller.setObjectProperty(adaptee, BLOCK, STATE, state);
+        controller.setObjectProperty(adaptee, STATE, state);
         return true;
     }
 };
@@ -384,10 +384,10 @@ struct dstate
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<double> dstate;
-        controller.getObjectProperty(adaptee, BLOCK, DSTATE, dstate);
+        controller.getObjectProperty(adaptee, DSTATE, dstate);
 
         double* data;
         types::Double* o = new types::Double((int)dstate.size(), 1, &data);
@@ -402,7 +402,7 @@ struct dstate
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         if (v->getType() == types::InternalType::ScilabString)
         {
@@ -418,7 +418,7 @@ struct dstate
             }
 
             std::vector<double> dstate;
-            controller.setObjectProperty(adaptee, BLOCK, DSTATE, dstate);
+            controller.setObjectProperty(adaptee, DSTATE, dstate);
             return true;
         }
 
@@ -438,7 +438,7 @@ struct dstate
         std::vector<double> dstate (current->getSize());
         std::copy(current->getReal(), current->getReal() + current->getSize(), dstate.begin());
 
-        controller.setObjectProperty(adaptee, BLOCK, DSTATE, dstate);
+        controller.setObjectProperty(adaptee, DSTATE, dstate);
         return true;
     }
 };
@@ -761,7 +761,7 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
     const std::string inimpl ("inimpl");
     const std::string outimpl ("outimpl");
 
-    ScicosID adaptee = adaptor.getAdaptee()->id();
+    model::Block* adaptee = adaptor.getAdaptee();
 
     for (std::vector<ScicosID>::const_iterator it = children.begin(); it != children.end(); ++it)
     {
@@ -770,20 +770,21 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
             continue; // Rule out mlists (Deleted or Annotations)
         }
 
-        if (controller.getObject(*it)->kind() == BLOCK) // Rule out Annotations and Links
+        model::BaseObject* child = controller.getBaseObject(*it);
+        if (child->kind() == BLOCK) // Rule out Annotations and Links
         {
             std::string name;
-            controller.getObjectProperty(*it, BLOCK, SIM_FUNCTION_NAME, name);
+            controller.getObjectProperty(child, SIM_FUNCTION_NAME, name);
 
             // Find the "port blocks"
             if (name == input || name == inimpl || name == output || name == outimpl)
             {
                 std::vector<int> ipar;
-                controller.getObjectProperty(*it, BLOCK, IPAR, ipar);
+                controller.getObjectProperty(child, IPAR, ipar);
                 if (ipar.size() != 1)
                 {
                     std::string uid;
-                    controller.getObjectProperty(*it, BLOCK, UID, uid);
+                    controller.getObjectProperty(child, UID, uid);
                     get_or_allocate_logger()->log(LOG_ERROR, _("Wrong value for field %s.%s : %s (%s) has an invalid port number.\n"), "model", "rpar", name.c_str(), uid.c_str());
                     return false;
                 }
@@ -794,7 +795,7 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
                 std::vector<ScicosID> innerPort;
                 if (name == input || name == inimpl)
                 {
-                    controller.getObjectProperty(*it, BLOCK, OUTPUTS, innerPort);
+                    controller.getObjectProperty(child, OUTPUTS, innerPort);
                     if (!innerPort.empty())
                     {
                         kind = INPUTS;
@@ -806,7 +807,7 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
                 }
                 else
                 {
-                    controller.getObjectProperty(*it, BLOCK, INPUTS, innerPort);
+                    controller.getObjectProperty(child, INPUTS, innerPort);
                     if (!innerPort.empty())
                     {
                         kind = OUTPUTS;
@@ -818,7 +819,7 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
                 }
 
                 std::vector<ScicosID> superPorts;
-                controller.getObjectProperty(adaptee, BLOCK, kind, superPorts);
+                controller.getObjectProperty(adaptee, kind, superPorts);
                 if (static_cast<int>(superPorts.size()) < portIndex)
                 {
                     if (!superPorts.empty())
@@ -829,7 +830,7 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
                     else
                     {
                         std::string uid;
-                        controller.getObjectProperty(*it, BLOCK, UID, uid);
+                        controller.getObjectProperty(child, UID, uid);
                         get_or_allocate_logger()->log(LOG_ERROR, _("Wrong value for field %s.%s : %s (%s) has an invalid port number.\n"), "model", "rpar", name.c_str(), uid.c_str());
                         return false;
                     }
@@ -845,7 +846,7 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
                     if (isImplicit)
                     {
                         std::string uid;
-                        controller.getObjectProperty(*it, BLOCK, UID, uid);
+                        controller.getObjectProperty(child, UID, uid);
                         get_or_allocate_logger()->log(LOG_ERROR, _("Wrong value for field %s.%s : %s (%s) has an invalid implicit port.\n"), "model", "rpar", name.c_str(), uid.c_str());
                         return false;
                     }
@@ -855,13 +856,13 @@ bool setInnerBlocksRefs(ModelAdapter& adaptor, const std::vector<ScicosID>& chil
                     if (!isImplicit)
                     {
                         std::string uid;
-                        controller.getObjectProperty(*it, BLOCK, UID, uid);
+                        controller.getObjectProperty(child, UID, uid);
                         get_or_allocate_logger()->log(LOG_ERROR, _("Wrong value for field %s.%s : %s (%s) has an invalid explicit port.\n"), "model", "rpar", name.c_str(), uid.c_str());
                         return false;
                     }
                 }
 
-                controller.setObjectProperty(*it, BLOCK, PORT_REFERENCE, port);
+                controller.setObjectProperty(child, PORT_REFERENCE, port);
             }
         }
     }
@@ -873,15 +874,15 @@ struct rpar
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<ScicosID> diagramChildren;
-        controller.getObjectProperty(adaptee, BLOCK, CHILDREN, diagramChildren);
+        controller.getObjectProperty(adaptee, CHILDREN, diagramChildren);
 
         if (diagramChildren.empty())
         {
             std::vector<double> rpar;
-            controller.getObjectProperty(adaptee, BLOCK, RPAR, rpar);
+            controller.getObjectProperty(adaptee, RPAR, rpar);
 
             double *data;
             types::Double* o = new types::Double((int)rpar.size(), 1, &data);
@@ -894,14 +895,14 @@ struct rpar
         }
         else // SuperBlock, return the contained diagram (allocating it on demand)
         {
-            DiagramAdapter* d = new DiagramAdapter(controller, controller.referenceObject(adaptor.getAdaptee()));
+            DiagramAdapter* d = new DiagramAdapter(controller, controller.referenceBaseObject(adaptee));
             return d;
         }
     }
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         if (v->getType() == types::InternalType::ScilabDouble)
         {
@@ -913,7 +914,7 @@ struct rpar
                 rpar[i] = current->get(i);
             }
 
-            controller.setObjectProperty(adaptee, BLOCK, RPAR, rpar);
+            controller.setObjectProperty(adaptee, RPAR, rpar);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabString)
@@ -931,7 +932,7 @@ struct rpar
                 return false;
             }
             const DiagramAdapter* diagram = v->getAs<DiagramAdapter>();
-            DiagramAdapter* superblock = new DiagramAdapter(controller, controller.referenceObject(adaptor.getAdaptee()));
+            DiagramAdapter* superblock = new DiagramAdapter(controller, controller.referenceBaseObject(adaptee));
 
             // copy the values by name to preserve adaptors specific properties
             superblock->copyProperties(*diagram, controller);
@@ -941,7 +942,7 @@ struct rpar
         }
         else if (v->getType() == types::InternalType::ScilabMList)
         {
-            DiagramAdapter* diagram = new DiagramAdapter(controller, controller.referenceObject(adaptor.getAdaptee()));
+            DiagramAdapter* diagram = new DiagramAdapter(controller, controller.referenceBaseObject(adaptee));
             if (!diagram->setAsTList(v, controller))
             {
                 diagram->killMe();
@@ -969,10 +970,10 @@ struct ipar
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<int> ipar;
-        controller.getObjectProperty(adaptee, BLOCK, IPAR, ipar);
+        controller.getObjectProperty(adaptee, IPAR, ipar);
 
         double *data;
         types::Double* o = new types::Double((int)ipar.size(), 1, &data);
@@ -987,12 +988,12 @@ struct ipar
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         if (v->getType() == types::InternalType::ScilabList)
         {
             std::vector<int> ipar;
-            controller.setObjectProperty(adaptee, BLOCK, IPAR, ipar);
+            controller.setObjectProperty(adaptee, IPAR, ipar);
             get_or_allocate_logger()->log(LOG_TRACE, _("Wrong type for field %s.%s : List clear previous value.\n"), "model", "ipar");
             return true;
         }
@@ -1022,7 +1023,7 @@ struct ipar
             ipar[i] = static_cast<int>(current->get(i));
         }
 
-        controller.setObjectProperty(adaptee, BLOCK, IPAR, ipar);
+        controller.setObjectProperty(adaptee, IPAR, ipar);
         return true;
     }
 };
@@ -1046,10 +1047,10 @@ struct blocktype
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::string type;
-        controller.getObjectProperty(adaptee, BLOCK, SIM_BLOCKTYPE, type);
+        controller.getObjectProperty(adaptee, SIM_BLOCKTYPE, type);
 
         types::String* o = new types::String(type.c_str());
         return o;
@@ -1057,7 +1058,7 @@ struct blocktype
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         if (v->getType() != types::InternalType::ScilabString)
         {
@@ -1077,7 +1078,7 @@ struct blocktype
         FREE(c_str);
 
         // the value validation is performed on the model
-        return controller.setObjectProperty(adaptee, BLOCK, SIM_BLOCKTYPE, type) != FAIL;
+        return controller.setObjectProperty(adaptee, SIM_BLOCKTYPE, type) != FAIL;
     }
 };
 
@@ -1100,10 +1101,10 @@ struct dep_ut
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<int> dep_ut;
-        controller.getObjectProperty(adaptee, BLOCK, SIM_DEP_UT, dep_ut);
+        controller.getObjectProperty(adaptee, SIM_DEP_UT, dep_ut);
 
         int* dep;
         types::Bool* o = new types::Bool(1, 2, &dep);
@@ -1116,7 +1117,7 @@ struct dep_ut
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         if (v->getType() != types::InternalType::ScilabBool)
         {
@@ -1135,7 +1136,7 @@ struct dep_ut
         dep_ut[0] = current->get(0);
         dep_ut[1] = current->get(1);
 
-        controller.setObjectProperty(adaptee, BLOCK, SIM_DEP_UT, dep_ut);
+        controller.setObjectProperty(adaptee, SIM_DEP_UT, dep_ut);
         return true;
     }
 };
@@ -1175,19 +1176,19 @@ struct label
 {
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         ScicosID label;
         std::string description;
 
-        controller.getObjectProperty(adaptee, BLOCK, LABEL, label);
+        controller.getObjectProperty(adaptee, LABEL, label);
         if (label != ScicosID())
         {
             controller.getObjectProperty(label, ANNOTATION, DESCRIPTION, description);
         }
         else
         {
-            controller.getObjectProperty(adaptee, BLOCK, DESCRIPTION, description);
+            controller.getObjectProperty(adaptee, DESCRIPTION, description);
         }
 
         types::String* o = new types::String(1, 1);
@@ -1219,7 +1220,7 @@ struct label
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         char* c_str = wide_string_to_UTF8(current->get(0));
         std::string description(c_str);
@@ -1232,7 +1233,7 @@ struct label
         //            return false;
         //        }
 
-        controller.setObjectProperty(adaptee, BLOCK, DESCRIPTION, description);
+        controller.setObjectProperty(adaptee, DESCRIPTION, description);
         return true;
     }
 };
@@ -1242,10 +1243,10 @@ struct nzcross
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<int> nzcross;
-        controller.getObjectProperty(adaptee, BLOCK, NZCROSS, nzcross);
+        controller.getObjectProperty(adaptee, NZCROSS, nzcross);
 
         double *data;
         types::Double* o = new types::Double((int)nzcross.size(), 1, &data);
@@ -1260,7 +1261,7 @@ struct nzcross
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -1287,7 +1288,7 @@ struct nzcross
             nzcross[i] = static_cast<int>(current->get(i));
         }
 
-        controller.setObjectProperty(adaptee, BLOCK, NZCROSS, nzcross);
+        controller.setObjectProperty(adaptee, NZCROSS, nzcross);
         return true;
     }
 };
@@ -1297,10 +1298,10 @@ struct nmode
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::vector<int> nmode;
-        controller.getObjectProperty(adaptee, BLOCK, NMODE, nmode);
+        controller.getObjectProperty(adaptee, NMODE, nmode);
 
         double *data;
         types::Double* o = new types::Double((int)nmode.size(), 1, &data);
@@ -1315,7 +1316,7 @@ struct nmode
 
     static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         if (v->getType() != types::InternalType::ScilabDouble)
         {
@@ -1342,7 +1343,7 @@ struct nmode
             nmode[i] = static_cast<int>(current->get(i));
         }
 
-        controller.setObjectProperty(adaptee, BLOCK, NMODE, nmode);
+        controller.setObjectProperty(adaptee, NMODE, nmode);
         return true;
     }
 };
@@ -1366,10 +1367,10 @@ struct uid
 
     static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         std::string uid;
-        controller.getObjectProperty(adaptee, BLOCK, UID, uid);
+        controller.getObjectProperty(adaptee, UID, uid);
 
         types::String* o = new types::String(1, 1);
         o->set(0, uid.data());
@@ -1392,13 +1393,13 @@ struct uid
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Block* adaptee = adaptor.getAdaptee();
 
         char* c_str = wide_string_to_UTF8(current->get(0));
         std::string uid(c_str);
         FREE(c_str);
 
-        controller.setObjectProperty(adaptee, BLOCK, UID, uid);
+        controller.setObjectProperty(adaptee, UID, uid);
         return true;
     }
 };
@@ -1410,7 +1411,7 @@ static void initialize_fields()
 {
     if (property<ModelAdapter>::properties_have_not_been_set())
     {
-        property<ModelAdapter>::fields.reserve(23);
+        property<ModelAdapter>::reserve_properties(23);
         property<ModelAdapter>::add_property(L"sim", &sim::get, &sim::set);
         property<ModelAdapter>::add_property(L"in", &in::get, &in::set);
         property<ModelAdapter>::add_property(L"in2", &in2::get, &in2::set);
@@ -1434,6 +1435,7 @@ static void initialize_fields()
         property<ModelAdapter>::add_property(L"nmode", &nmode::get, &nmode::set);
         property<ModelAdapter>::add_property(L"equations", &equations::get, &equations::set);
         property<ModelAdapter>::add_property(L"uid", &uid::get, &uid::set);
+        property<ModelAdapter>::shrink_to_fit();
     }
 }
 
index ea8dd9f..79b8df6 100644 (file)
@@ -28,6 +28,8 @@
 #include "Controller.hxx"
 #include "controller_helpers.hxx"
 #include "ParamsAdapter.hxx"
+#include "model/Block.hxx"
+#include "model/Diagram.hxx"
 
 extern "C" {
 #include "sci_malloc.h"
@@ -92,18 +94,18 @@ struct title
 
     static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::BaseObject* adaptee = adaptor.getAdaptee();
 
         std::string title;
         std::string path;
-        if (adaptor.getAdaptee()->kind() == DIAGRAM)
+        if (adaptee->kind() == DIAGRAM)
         {
-            controller.getObjectProperty(adaptee, DIAGRAM, TITLE, title);
-            controller.getObjectProperty(adaptee, DIAGRAM, PATH, path);
+            controller.getObjectProperty(adaptee, TITLE, title);
+            controller.getObjectProperty(adaptee, PATH, path);
         }
         else
         {
-            controller.getObjectProperty(adaptee, BLOCK, DESCRIPTION, title);
+            controller.getObjectProperty(adaptee, DESCRIPTION, title);
         }
 
         types::String* o = new types::String(2, 1);
@@ -121,7 +123,7 @@ struct title
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::BaseObject* adaptee = adaptor.getAdaptee();
 
         std::string path;
         std::string title;
@@ -147,14 +149,14 @@ struct title
         FREE(Title);
 
 
-        if (adaptor.getAdaptee()->kind() == DIAGRAM)
+        if (adaptee->kind() == DIAGRAM)
         {
-            controller.setObjectProperty(adaptee, DIAGRAM, TITLE, title);
-            controller.setObjectProperty(adaptee, DIAGRAM, PATH, path);
+            controller.setObjectProperty(adaptee, TITLE, title);
+            controller.setObjectProperty(adaptee, PATH, path);
         }
         else
         {
-            controller.setObjectProperty(adaptee, BLOCK, DESCRIPTION, title);
+            controller.setObjectProperty(adaptee, DESCRIPTION, title);
         }
         return true;
     }
@@ -165,21 +167,26 @@ struct tol
 
     static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
-        if (adaptor.getAdaptee()->kind() == BLOCK)
+        model::BaseObject* adaptee = adaptor.getAdaptee();
+        if (adaptee->kind() == BLOCK)
         {
-            controller.getObjectProperty(adaptee, BLOCK, PARENT_DIAGRAM, adaptee);
-            if (adaptee == ScicosID())
+            ScicosID parent;
+            controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parent);
+            if (parent == ScicosID())
             {
                 return types::Double::Empty();
             }
+            else
+            {
+                adaptee = controller.getBaseObject(parent);
+            }
         }
 
         double* data;
         types::Double* o = new types::Double(1, 7, &data);
 
         std::vector<double> tol;
-        controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
+        controller.getObjectProperty(adaptee, PROPERTIES, tol);
 #ifdef _MSC_VER
         std::copy(tol.begin() + 1, tol.end(), stdext::checked_array_iterator<double*>( data, 7 ));
 #else
@@ -215,10 +222,10 @@ struct tol
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Diagram* adaptee = static_cast<model::Diagram*>(adaptor.getAdaptee());
 
         std::vector<double> tol;
-        controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
+        controller.getObjectProperty(adaptee, PROPERTIES, tol);
 
         std::copy(current->getReal(), current->getReal() + current->getSize(), tol.begin() + 1);
 
@@ -228,7 +235,7 @@ struct tol
             tol[7] = 0;
         }
 
-        controller.setObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
+        controller.setObjectProperty(adaptee, PROPERTIES, tol);
         return true;
     }
 };
@@ -238,18 +245,23 @@ struct tf
 
     static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
-        if (adaptor.getAdaptee()->kind() == BLOCK)
+        model::BaseObject* adaptee = adaptor.getAdaptee();
+        if (adaptee->kind() == BLOCK)
         {
-            controller.getObjectProperty(adaptee, BLOCK, PARENT_DIAGRAM, adaptee);
-            if (adaptee == ScicosID())
+            ScicosID parent;
+            controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parent);
+            if (parent == ScicosID())
             {
                 return types::Double::Empty();
             }
+            else
+            {
+                adaptee = controller.getBaseObject(parent);
+            }
         }
 
         std::vector<double> tf;
-        controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tf);
+        controller.getObjectProperty(adaptee, PROPERTIES, tf);
 
         return new types::Double(tf[0]);
     }
@@ -275,14 +287,14 @@ struct tf
             return false;
         }
 
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::Diagram* adaptee = static_cast<model::Diagram*>(adaptor.getAdaptee());
 
         std::vector<double> tol;
-        controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
+        controller.getObjectProperty(adaptee, PROPERTIES, tol);
 
         tol[0] = current->get(0);
 
-        controller.setObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
+        controller.setObjectProperty(adaptee, PROPERTIES, tol);
         return true;
     }
 };
@@ -292,10 +304,10 @@ struct context
 
     static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
     {
-        ScicosID adaptee = adaptor.getAdaptee()->id();
+        model::BaseObject* adaptee = adaptor.getAdaptee();
 
         std::vector<std::string> context;
-        controller.getObjectProperty(adaptee, adaptor.getAdaptee()->kind(), DIAGRAM_CONTEXT, context);
+        controller.getObjectProperty(adaptee, DIAGRAM_CONTEXT, context);
 
         if (context.size() == 0)
         {
@@ -324,7 +336,7 @@ struct context
                 return false;
             }
 
-            ScicosID adaptee = adaptor.getAdaptee()->id();
+            model::BaseObject* adaptee = adaptor.getAdaptee();
 
             std::vector<std::string> context (current->getSize());
             for (int i = 0; i < (int)context.size(); ++i)
@@ -334,7 +346,7 @@ struct context
                 FREE(c_str);
             }
 
-            controller.setObjectProperty(adaptee, adaptor.getAdaptee()->kind(), DIAGRAM_CONTEXT, context);
+            controller.setObjectProperty(adaptee, DIAGRAM_CONTEXT, context);
             return true;
         }
         else if (v->getType() == types::InternalType::ScilabDouble)
@@ -346,10 +358,10 @@ struct context
                 return false;
             }
 
-            ScicosID adaptee = adaptor.getAdaptee()->id();
+            model::BaseObject* adaptee = adaptor.getAdaptee();
 
             std::vector<std::string> context;
-            controller.setObjectProperty(adaptee, adaptor.getAdaptee()->kind(), DIAGRAM_CONTEXT, context);
+            controller.setObjectProperty(adaptee, DIAGRAM_CONTEXT, context);
             return true;
         }
 
@@ -446,7 +458,7 @@ static void initialize_fields()
 {
     if (property<ParamsAdapter>::properties_have_not_been_set())
     {
-        property<ParamsAdapter>::fields.reserve(10);
+        property<ParamsAdapter>::reserve_properties(10);
         property<ParamsAdapter>::add_property(L"wpar", &wpar::get, &wpar::set);
         property<ParamsAdapter>::add_property(L"title", &title::get, &title::set);
         property<ParamsAdapter>::add_property(L"tol", &tol::get, &tol::set);
@@ -457,6 +469,7 @@ static void initialize_fields()
         property<ParamsAdapter>::add_property(L"void2", &dummy_property::get, &dummy_property::set);
         property<ParamsAdapter>::add_property(L"void3", &dummy_property::get, &dummy_property::set);
         property<ParamsAdapter>::add_property(L"doc", &doc::get, &doc::set);
+        property<ParamsAdapter>::shrink_to_fit();
     }
 }
 
index 7633c4b..42d93a7 100644 (file)
@@ -52,7 +52,7 @@ static void initialize_fields()
 {
     if (property<StateAdapter>::properties_have_not_been_set())
     {
-        property<StateAdapter>::fields.reserve(8);
+        property<StateAdapter>::reserve_properties(8);
         property<StateAdapter>::add_property(L"x", &dummy_property::get, &dummy_property::set);
         property<StateAdapter>::add_property(L"z", &dummy_property::get, &dummy_property::set);
         property<StateAdapter>::add_property(L"oz", &dummy_property::get, &dummy_property::set);
@@ -61,6 +61,7 @@ static void initialize_fields()
         property<StateAdapter>::add_property(L"evtspt", &dummy_property::get, &dummy_property::set);
         property<StateAdapter>::add_property(L"pointi", &dummy_property::get, &dummy_property::set);
         property<StateAdapter>::add_property(L"outtb", &dummy_property::get, &dummy_property::set);
+        property<StateAdapter>::shrink_to_fit();
     }
 }
 
index 820a29a..9d734b2 100644 (file)
@@ -279,11 +279,12 @@ TextAdapter::TextAdapter(const Controller& c, org_scilab_modules_scicos::model::
 {
     if (property<TextAdapter>::properties_have_not_been_set())
     {
-        property<TextAdapter>::fields.reserve(4);
-        property<TextAdapter>::add_property(Graphics, &graphics::get, &graphics::set);
+        property<TextAdapter>::reserve_properties(4);
+        property<TextAdapter>::add_property(L"graphics", &graphics::get, &graphics::set);
         property<TextAdapter>::add_property(L"model", &dummy_property::get, &dummy_property::set);
         property<TextAdapter>::add_property(L"void", &dummy_property::get, &dummy_property::set);
         property<TextAdapter>::add_property(L"gui", &gui::get, &dummy_property::set);
+        property<TextAdapter>::shrink_to_fit();
     }
 }
 
index 020af54..c789a1f 100644 (file)
@@ -66,6 +66,8 @@ std::string adapterName(const object_properties_t /*port_kind*/)
         case DATATYPE_TYPE:
         case FIRING:
             return "model";
+        default:
+            return "";
     }
 }
 
@@ -143,11 +145,11 @@ std::string adapterFieldName(const object_properties_t port_kind)
 template<typename Adaptor, object_properties_t p>
 types::InternalType* get_ports_property(const Adaptor& adaptor, const object_properties_t port_kind, const Controller& controller)
 {
-    ScicosID adaptee = adaptor.getAdaptee()->id();
+    model::Block* adaptee = adaptor.getAdaptee();
 
     // Retrieve the identifiers
     std::vector<ScicosID> ids;
-    controller.getObjectProperty(adaptee, BLOCK, port_kind, ids);
+    controller.getObjectProperty(adaptee, port_kind, ids);
 
     // Translate identifiers: shared variables
     int i = 0;
@@ -230,12 +232,12 @@ types::InternalType* get_ports_property(const Adaptor& adaptor, const object_pro
             std::vector<ScicosID> children;
 
             ScicosID parentBlock;
-            controller.getObjectProperty(adaptee, BLOCK, PARENT_BLOCK, parentBlock);
+            controller.getObjectProperty(adaptee, PARENT_BLOCK, parentBlock);
             if (parentBlock == ScicosID())
             {
                 // Adding to a diagram
                 ScicosID parentDiagram;
-                controller.getObjectProperty(adaptee, BLOCK, PARENT_DIAGRAM, parentDiagram);
+                controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parentDiagram);
 
                 controller.getObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
             }
@@ -286,11 +288,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)
 {
-    ScicosID adaptee = adaptor.getAdaptee()->id();
+    model::Block* adaptee = adaptor.getAdaptee();
 
     // Retrieve the ports identifiers
     std::vector<ScicosID> ids;
-    controller.getObjectProperty(adaptee, BLOCK, port_kind, ids);
+    controller.getObjectProperty(adaptee, port_kind, ids);
 
     if (v->getType() == types::InternalType::ScilabString)
     {
@@ -489,12 +491,12 @@ inline void fillNewPorts(std::deque<int>& newPorts, const double* d)
 /**
  * Set the port value
  *
- * \param oldPort the old port object ID
+ * \param oldPortObject the old port object
  * \param controller current transaction instance
  * \param children all object in the current layer (diagram or superblock)
  */
 template<object_properties_t p>
-inline bool updateNewPort(const ScicosID oldPort, int newPort, Controller& controller)
+inline bool updateNewPort(model::Port* oldPortObject, int newPort, Controller& controller)
 {
     // update the p property, using newPort as a value
     int datatypeIndex = -1;
@@ -510,25 +512,25 @@ inline bool updateNewPort(const ScicosID oldPort, int newPort, Controller& contr
         {
             datatypeIndex++;
             std::vector<int> datatype;
-            controller.getObjectProperty(oldPort, PORT, DATATYPE, datatype);
+            controller.getObjectProperty(oldPortObject, DATATYPE, datatype);
             datatype[datatypeIndex] = newPort;
-            return controller.setObjectProperty(oldPort, PORT, DATATYPE, datatype) != FAIL;
+            return controller.setObjectProperty(oldPortObject, DATATYPE, datatype) != FAIL;
         }
         default:
-            return controller.setObjectProperty(oldPort, PORT, p, newPort) != FAIL;
+            return controller.setObjectProperty(oldPortObject, p, newPort) != FAIL;
     }
 }
 
 /**
  * Add a new port
  *
- * \param newPortID the old port object ID
+ * \param newPortObject the old port object
  * \param newPort new port children's index or value
  * \param controller current transaction instance
  * \return true on success, false otherwise
  */
 template<object_properties_t p>
-inline bool addNewPort(const ScicosID newPortID, int newPort, Controller& controller)
+inline bool addNewPort(model::Port* newPortObject, int newPort, Controller& controller)
 {
     // set the requested property, using newPort as a value
     int datatypeIndex = -1;
@@ -544,12 +546,12 @@ inline bool addNewPort(const ScicosID newPortID, int newPort, Controller& contro
         {
             datatypeIndex++;
             std::vector<int> datatype;
-            controller.getObjectProperty(newPortID, PORT, DATATYPE, datatype);
+            controller.getObjectProperty(newPortObject, DATATYPE, datatype);
             datatype[datatypeIndex] = newPort;
-            return controller.setObjectProperty(newPortID, PORT, DATATYPE, datatype) != FAIL;
+            return controller.setObjectProperty(newPortObject, DATATYPE, datatype) != FAIL;
         }
         default:
-            return controller.setObjectProperty(newPortID, PORT, p, newPort) != FAIL;
+            return controller.setObjectProperty(newPortObject, p, newPort) != FAIL;
     }
 }
 
@@ -561,7 +563,7 @@ inline bool addNewPort(const ScicosID newPortID, int newPort, Controller& contro
 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)
 {
-    ScicosID adaptee = adaptor.getAdaptee()->id();
+    model::Block* adaptee = adaptor.getAdaptee();
 
     if (v->getType() != types::InternalType::ScilabDouble)
     {
@@ -573,9 +575,9 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
     types::Double* value = v->getAs<types::Double>();
 
     ScicosID parentBlock;
-    controller.getObjectProperty(adaptee, BLOCK, PARENT_BLOCK, parentBlock);
+    controller.getObjectProperty(adaptee, PARENT_BLOCK, parentBlock);
     ScicosID parentDiagram;
-    controller.getObjectProperty(adaptee, BLOCK, PARENT_DIAGRAM, parentDiagram);
+    controller.getObjectProperty(adaptee, PARENT_DIAGRAM, parentDiagram);
 
     std::vector<ScicosID> children;
     if (parentBlock != ScicosID())
@@ -593,18 +595,22 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
 
     // retrieve old data
     std::vector<ScicosID> previousPorts;
-    controller.getObjectProperty(adaptee, BLOCK, port_kind, previousPorts);
-    std::deque<ScicosID> oldPorts(previousPorts.begin(), previousPorts.end());
+    controller.getObjectProperty(adaptee, port_kind, previousPorts);
+    std::deque<model::Port*> oldPorts;
+    for (ScicosID pre : previousPorts)
+    {
+        oldPorts.emplace_back(controller.getBaseObject<model::Port>(pre));
+    }
 
     double* d = value->getReal();
     fillNewPorts(newPorts, d);
 
-    std::vector<ScicosID> deletedObjects;
+    std::vector<model::BaseObject*> deletedObjects;
 
     // updated ports
     while (!oldPorts.empty() && !newPorts.empty())
     {
-        ScicosID oldPort = oldPorts.front();
+        model::Port* oldPort = oldPorts.front();
         oldPorts.pop_front();
         int newPort = newPorts.front();
         newPorts.pop_front();
@@ -625,21 +631,23 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
 
         while (!oldPorts.empty())
         {
-            ScicosID oldPort = oldPorts.front();
+            model::Port* oldPort = oldPorts.front();
             oldPorts.pop_front();
 
             ScicosID signal;
-            controller.getObjectProperty(oldPort, PORT, CONNECTED_SIGNALS, signal);
+            controller.getObjectProperty(oldPort, CONNECTED_SIGNALS, signal);
             if (signal != ScicosID())
             {
+                model::Link* signalObject = controller.getBaseObject<model::Link>(signal);
+
                 // the link is connected, disconnect the other side
                 ScicosID oldSignalSrc;
-                controller.getObjectProperty(signal, LINK, SOURCE_PORT, oldSignalSrc);
+                controller.getObjectProperty(signalObject, SOURCE_PORT, oldSignalSrc);
                 ScicosID oldSignalDst;
-                controller.getObjectProperty(signal, LINK, DESTINATION_PORT, oldSignalDst);
+                controller.getObjectProperty(signalObject, DESTINATION_PORT, oldSignalDst);
 
                 ScicosID unconnected = 0;
-                if (oldSignalSrc == oldPort)
+                if (oldSignalSrc == oldPort->id())
                 {
                     controller.setObjectProperty(oldSignalDst, PORT, CONNECTED_SIGNALS, unconnected);
                 }
@@ -648,14 +656,14 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
                     controller.setObjectProperty(oldSignalSrc, PORT, CONNECTED_SIGNALS, unconnected);
                 }
 
-                children.erase(std::find(children.begin(), children.end(), signal));
-                deletedObjects.push_back(signal);
+                children.erase(std::find(children.begin(), children.end(), signalObject->id()));
+                deletedObjects.push_back(signalObject);
             }
 
             deletedObjects.push_back(oldPort);
         }
 
-        controller.setObjectProperty(adaptee, BLOCK, port_kind, previousPorts);
+        controller.setObjectProperty(adaptee, port_kind, previousPorts);
     }
 
     // added ports
@@ -666,38 +674,38 @@ bool update_ports_property(const Adaptor& adaptor, const object_properties_t por
             int newPort = newPorts.front();
             newPorts.pop_front();
 
-            ScicosID id = controller.createObject(PORT);
-            controller.setObjectProperty(id, PORT, SOURCE_BLOCK, adaptee);
+            model::Port* createdPort = controller.createBaseObject<model::Port>(PORT);
+            controller.setObjectProperty(createdPort, SOURCE_BLOCK, adaptee->id());
             switch (port_kind)
             {
                 case INPUTS:
-                    controller.setObjectProperty(id, PORT, PORT_KIND, static_cast<int>(PORT_IN));
+                    controller.setObjectProperty(createdPort, PORT_KIND, static_cast<int>(PORT_IN));
                     break;
                 case OUTPUTS:
-                    controller.setObjectProperty(id, PORT, PORT_KIND, static_cast<int>(PORT_OUT));
+                    controller.setObjectProperty(createdPort, PORT_KIND, static_cast<int>(PORT_OUT));
                     break;
                 case EVENT_INPUTS:
-                    controller.setObjectProperty(id, PORT, PORT_KIND, static_cast<int>(PORT_EIN));
+                    controller.setObjectProperty(createdPort, PORT_KIND, static_cast<int>(PORT_EIN));
                     break;
                 case EVENT_OUTPUTS:
-                    controller.setObjectProperty(id, PORT, PORT_KIND, static_cast<int>(PORT_EOUT));
+                    controller.setObjectProperty(createdPort, PORT_KIND, static_cast<int>(PORT_EOUT));
                     break;
                 default:
                     // should never happen
                     assert(!"Not managed kind of port");
                     return false;
             }
-            addNewPort<p>(id, newPort, controller);
-            previousPorts.push_back(id);
+            addNewPort<p>(createdPort, newPort, controller);
+            previousPorts.push_back(createdPort->id());
         }
 
-        controller.setObjectProperty(adaptee, BLOCK, port_kind, previousPorts);
+        controller.setObjectProperty(adaptee, port_kind, previousPorts);
     }
 
     // remove objects from the model after de-association
-    for (std::vector<ScicosID>::iterator it = deletedObjects.begin(); it != deletedObjects.end(); ++it)
+    for (auto o : deletedObjects)
     {
-        controller.deleteObject(*it);
+        controller.deleteBaseObject(o);
     }
 
     return true;
index 8d3e9e4..0790460 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
@@ -35,11 +35,6 @@ public class Controller {
     }
   }
 
-  public static View look_for_view(String name) {
-    long cPtr = JavaControllerJNI.Controller_look_for_view(name);
-    return (cPtr == 0) ? null : new View(cPtr, false);
-  }
-
   public static void end_simulation() {
     JavaControllerJNI.Controller_end_simulation();
   }
index 481cf99..d97db63 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
@@ -46,4 +46,5 @@ public class JavaController extends Controller {
     JavaControllerJNI.unregister_view(View.getCPtr(view), view);
     remove_reference(view);
   }
+
 }
index 3ae4901..0d16a77 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
@@ -21,7 +21,6 @@ public class JavaControllerJNI {
   public final static native void View_propertyUpdated(long jarg1, View jarg1_, long jarg2, int jarg3, int jarg4, int jarg5);
   public final static native void View_director_connect(View obj, long cptr, boolean mem_own, boolean weak_global);
   public final static native void View_change_ownership(View obj, long cptr, boolean take_or_release);
-  public final static native long Controller_look_for_view(String jarg1);
   public final static native void Controller_end_simulation();
   public final static native long new_Controller();
   public final static native void delete_Controller(long jarg1);
index 4181ad0..58a63a4 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index 52c490a..11bd72f 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index 09cd7c3..4166c89 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index a78b3c9..a5c3569 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index 0486e01..47d9862 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index b430032..846d3bd 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index 09f97ab..bd7be4f 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index f076bac..2c6343c 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index f630d6e..f22ace3 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index 7f99546..727baad 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
index e79dae1..55cdbfd 100644 (file)
@@ -173,7 +173,6 @@ public final class Xcos {
         diagrams = new HashMap<>();
 
         view = new XcosView();
-        JavaController.register_view(Xcos.class.getName(), view);
         // allocate and install the browser view on demand to avoid any cost
         browser = null;
 
index b1fb45b..0035c37 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright (C) 2009 - DIGITEO - Vincent COUVERT
  * Copyright (C) 2010 - DIGITEO - Clement DAVID
  * Copyright (C) 2011-2015 - Scilab Enterprises - Clement DAVID
+ * Copyright (C) 2017 - ESI Group - Clement DAVID
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -44,6 +45,7 @@ import org.scilab.modules.xcos.utils.XcosMessages;
 
 import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.buildCall;
 import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.asynchronousScilabExec;
+import org.scilab.modules.xcos.io.HandledElement;
 
 /**
  * Open dialog to set block parameters
@@ -134,6 +136,7 @@ public class BlockParametersAction extends VertexSelectionDependantAction {
 
                 graph.setCellsLocked(true);
                 graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+                JavaController.register_view(Xcos.class.getName(), Xcos.getInstance().getXcosView());
 
                 try {
 
@@ -160,6 +163,7 @@ public class BlockParametersAction extends VertexSelectionDependantAction {
 
                                 graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                                 graph.setCellsLocked(false);
+                                JavaController.unregister_view(Xcos.getInstance().getXcosView());
                             }
                         }
                     };
index 095a913..17be571 100644 (file)
@@ -269,11 +269,7 @@ namespace std {
 /*
  * Generate a Controller class
  */
-// Ignore not applicable methods
-%ignore org_scilab_modules_scicos::Controller::register_view;
-%ignore org_scilab_modules_scicos::Controller::unregister_view;
-%ignore org_scilab_modules_scicos::Controller::cloneObject(std::map<model::BaseObject*, model::BaseObject*>& mapped, model::BaseObject* initial, bool cloneChildren, bool clonePorts);
-%ignore org_scilab_modules_scicos::Controller::getObject;
+// not applicable methods are ignored thanks to the SWIG 
 %include "../scicos/includes/Controller.hxx";
 
 /*
index f2393b7..802b3c4 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * This file is not intended to be easily readable and contains a number of
  * coding conventions designed to improve portability and efficiency. Do not make
@@ -677,6 +677,7 @@ namespace Swig {
 #include "scicos.h"
 
 
+#include <typeinfo>
 #include <stdexcept>
 
 
@@ -1361,23 +1362,6 @@ SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_View_1cha
 }
 
 
-SWIGEXPORT jlong JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_Controller_1look_1for_1view(JNIEnv *jenv, jclass jcls, jstring jarg1) {
-  jlong jresult = 0 ;
-  std::string *arg1 = 0 ;
-  org_scilab_modules_scicos::View *result = 0 ;
-  
-  (void)jenv;
-  (void)jcls;
-  Swig::JavaString javaString(jenv, jarg1);
-  std::string arg1_str(javaString.c_str());
-  arg1 = &arg1_str;
-  result = (org_scilab_modules_scicos::View *)org_scilab_modules_scicos::Controller::look_for_view((std::string const &)*arg1);
-  *(org_scilab_modules_scicos::View **)&jresult = result; 
-  
-  return jresult;
-}
-
-
 SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_Controller_1end_1simulation(JNIEnv *jenv, jclass jcls) {
   (void)jenv;
   (void)jcls;
index dd9756d..4a8dc46 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 3.0.10
+ * Version 3.0.11
  *
  * This file is not intended to be easily readable and contains a number of
  * coding conventions designed to improve portability and efficiency. Do not make