Преглед на файлове

Remove dynamic allocation of simulators and coordinators

Eric Ramat преди 11 години
родител
ревизия
23feb3cbe9
променени са 5 файла, в които са добавени 93 реда и са изтрити 107 реда
  1. 1 5
      src/dtss/GraphManager.hpp
  2. 1 5
      src/pdevs/GraphManager.hpp
  3. 13 14
      src/tests/dtss_tests.cpp
  4. 28 31
      src/tests/mixed_tests.cpp
  5. 50 52
      src/tests/pdevs_tests.cpp

+ 1 - 5
src/dtss/GraphManager.hpp

@@ -42,11 +42,7 @@ public:
     { }
 
     virtual ~GraphManager()
-    {
-        for (auto & child : _child_list) {
-            delete child;
-        }
-    }
+    { }
 
     void add_child(common::Model < Time >* child)
     {

+ 1 - 5
src/pdevs/GraphManager.hpp

@@ -42,11 +42,7 @@ public:
     { }
 
     virtual ~GraphManager()
-    {
-        for (auto & child : _child_list) {
-            delete child;
-        }
-    }
+    { }
 
     void add_child(common::Model < Time >* child)
     {

+ 13 - 14
src/tests/dtss_tests.cpp

@@ -128,36 +128,35 @@ class OnlyOneGraphManager : public dtss::GraphManager < MyTime >
 {
 public:
     OnlyOneGraphManager(common::Coordinator < MyTime >* coordinator) :
-        dtss::GraphManager < MyTime >(coordinator)
+        dtss::GraphManager < MyTime >(coordinator), a("a", 1)
     {
-        dtss::Simulator < MyTime, A >* a =
-            new dtss::Simulator < MyTime, A >("a", 1);
-
-        add_child(a);
+        add_child(&a);
     }
 
     virtual ~OnlyOneGraphManager()
     { }
+
+private:
+    dtss::Simulator < MyTime, A > a;
 };
 
 class TwoGraphManager : public dtss::GraphManager < MyTime >
 {
 public:
     TwoGraphManager(common::Coordinator < MyTime >* coordinator) :
-        dtss::GraphManager < MyTime >(coordinator)
+        dtss::GraphManager < MyTime >(coordinator), a("a", 1), b("b", 1)
     {
-        dtss::Simulator < MyTime, A >* a =
-            new dtss::Simulator < MyTime, A >("a", 1);
-        dtss::Simulator < MyTime, B >* b =
-            new dtss::Simulator < MyTime, B >("b", 1);
-
-        add_child(a);
-        add_child(b);
-        add_link(a, "out", b, "in");
+        add_child(&a);
+        add_child(&b);
+        add_link(&a, "out", &b, "in");
     }
 
     virtual ~TwoGraphManager()
     { }
+
+private:
+    dtss::Simulator < MyTime, A > a;
+    dtss::Simulator < MyTime, B > b;
 };
 
 } } // namespace paradevs dtss

+ 28 - 31
src/tests/mixed_tests.cpp

@@ -305,64 +305,61 @@ class S1GraphManager : public pdevs::GraphManager < MyTime >
 {
 public:
     S1GraphManager(common::Coordinator < MyTime >* coordinator) :
-        pdevs::GraphManager < MyTime >(coordinator)
+        pdevs::GraphManager < MyTime >(coordinator), a("a1"), b("b1")
     {
-        pdevs::Simulator < MyTime, A1 >* a =
-            new pdevs::Simulator < MyTime, A1 >("a1");
-        pdevs::Simulator < MyTime, B1 >* b =
-            new pdevs::Simulator < MyTime, B1 >("b1");
-
-        add_child(a);
-        add_child(b);
-        add_link(a, "out", b, "in");
-        add_link(b, "out", coordinator, "out");
+        add_child(&a);
+        add_child(&b);
+        add_link(&a, "out", &b, "in");
+        add_link(&b, "out", coordinator, "out");
     }
 
     virtual ~S1GraphManager()
     { }
+
+private:
+    pdevs::Simulator < MyTime, A1 > a;
+    pdevs::Simulator < MyTime, B1 > b;
 };
 
 class S2GraphManager : public dtss::GraphManager < MyTime >
 {
 public:
     S2GraphManager(common::Coordinator < MyTime >* coordinator) :
-        dtss::GraphManager < MyTime >(coordinator)
+        dtss::GraphManager < MyTime >(coordinator), a("a2", 20), b("b2", 20)
     {
-        dtss::Simulator < MyTime, A2 >* a =
-            new dtss::Simulator < MyTime, A2 >("a2", 20);
-        dtss::Simulator < MyTime, B2 >* b =
-            new dtss::Simulator < MyTime, B2 >("b2", 20);
-
-        add_child(a);
-        add_child(b);
-        add_link(a, "out", b, "in");
-        add_link(coordinator, "in", a, "in");
+        add_child(&a);
+        add_child(&b);
+        add_link(&a, "out", &b, "in");
+        add_link(coordinator, "in", &a, "in");
     }
 
     virtual ~S2GraphManager()
     { }
+
+private:
+    dtss::Simulator < MyTime, A2 > a;
+    dtss::Simulator < MyTime, B2 > b;
 };
 
 class RootGraphManager : public pdevs::GraphManager < MyTime >
 {
 public:
     RootGraphManager(common::Coordinator < MyTime >* coordinator) :
-        pdevs::GraphManager < MyTime >(coordinator)
+        pdevs::GraphManager < MyTime >(coordinator),
+        S1("S1", paradevs::pdevs::Parameters()),
+        S2("S2", paradevs::dtss::Parameters < MyTime >(20))
     {
-        pdevs::Coordinator < MyTime, S1GraphManager >* S1 =
-            new pdevs::Coordinator < MyTime, S1GraphManager >(
-                "S1", paradevs::pdevs::Parameters());
-        dtss::Coordinator < MyTime, LastBagPolicy, S2GraphManager >* S2 =
-            new dtss::Coordinator < MyTime, LastBagPolicy, S2GraphManager >(
-                "S2", paradevs::dtss::Parameters < MyTime >(20));
-
-        add_child(S1);
-        add_child(S2);
-        add_link(S1, "out", S2, "in");
+        add_child(&S1);
+        add_child(&S2);
+        add_link(&S1, "out", &S2, "in");
     }
 
     virtual ~RootGraphManager()
     { }
+
+private:
+    pdevs::Coordinator < MyTime, S1GraphManager > S1;
+    dtss::Coordinator < MyTime, LastBagPolicy, S2GraphManager > S2;
 };
 
 } // namespace paradevs

+ 50 - 52
src/tests/pdevs_tests.cpp

@@ -205,106 +205,103 @@ class S1GraphManager : public pdevs::GraphManager < MyTime >
 {
 public:
     S1GraphManager(common::Coordinator < MyTime >* coordinator) :
-        pdevs::GraphManager < MyTime >(coordinator)
+        pdevs::GraphManager < MyTime >(coordinator), a("a1"), b("b1")
     {
-        pdevs::Simulator < MyTime, A >* a =
-            new pdevs::Simulator < MyTime, A >("a1");
-        pdevs::Simulator < MyTime, B >* b =
-            new pdevs::Simulator < MyTime, B >("b1");
-
-        add_child(a);
-        add_child(b);
-        add_link(a, "out", b, "in");
-        add_link(b, "out", coordinator, "out");
+        add_child(&a);
+        add_child(&b);
+        add_link(&a, "out", &b, "in");
+        add_link(&b, "out", coordinator, "out");
     }
 
     virtual ~S1GraphManager()
     { }
+
+private:
+    pdevs::Simulator < MyTime, A > a;
+    pdevs::Simulator < MyTime, B > b;
 };
 
 class S2GraphManager : public pdevs::GraphManager < MyTime >
 {
 public:
     S2GraphManager(common::Coordinator < MyTime >* coordinator) :
-        pdevs::GraphManager < MyTime >(coordinator)
+        pdevs::GraphManager < MyTime >(coordinator), a("a2"), b("b2")
     {
-        pdevs::Simulator < MyTime, A >* a =
-            new pdevs::Simulator < MyTime, A >("a2");
-        pdevs::Simulator < MyTime, B >* b =
-            new pdevs::Simulator < MyTime, B >("b2");
-
-        add_child(a);
-        add_child(b);
-        add_link(a, "out", b, "in");
-        add_link(coordinator, "in", a, "in");
+        add_child(&a);
+        add_child(&b);
+        add_link(&a, "out", &b, "in");
+        add_link(coordinator, "in", &a, "in");
     }
 
     virtual ~S2GraphManager()
     { }
+
+private:
+    pdevs::Simulator < MyTime, A > a;
+    pdevs::Simulator < MyTime, B > b;
 };
 
 class RootGraphManager : public pdevs::GraphManager < MyTime >
 {
 public:
     RootGraphManager(common::Coordinator < MyTime >* coordinator) :
-        pdevs::GraphManager < MyTime >(coordinator)
+        pdevs::GraphManager < MyTime >(coordinator),
+        S1("S1", Parameters()),
+        S2("S2", Parameters())
     {
-        Coordinator < MyTime, S1GraphManager >* S1 =
-            new Coordinator < MyTime, S1GraphManager >("S1", Parameters());
-        Coordinator < MyTime, S2GraphManager >* S2 =
-            new Coordinator < MyTime, S2GraphManager >("S2", Parameters());
-
-        add_child(S1);
-        add_child(S2);
-        add_link(S1, "out", S2, "in");
+        add_child(&S1);
+        add_child(&S2);
+        add_link(&S1, "out", &S2, "in");
     }
 
     virtual ~RootGraphManager()
     { }
+
+private:
+    Coordinator < MyTime, S1GraphManager > S1;
+    Coordinator < MyTime, S2GraphManager > S2;
 };
 
 class OnlyOneGraphManager : public pdevs::GraphManager < MyTime >
 {
 public:
     OnlyOneGraphManager(common::Coordinator < MyTime >* coordinator) :
-        pdevs::GraphManager < MyTime >(coordinator)
+        pdevs::GraphManager < MyTime >(coordinator), a("a")
     {
-        pdevs::Simulator < MyTime, A >* a =
-            new pdevs::Simulator < MyTime, A >("a");
-
-        add_child(a);
+        add_child(&a);
     }
 
     virtual ~OnlyOneGraphManager()
     { }
+
+private:
+    pdevs::Simulator < MyTime, A > a;
 };
 
 class FlatGraphManager : public pdevs::GraphManager < MyTime >
 {
 public:
     FlatGraphManager(common::Coordinator < MyTime >* coordinator) :
-        pdevs::GraphManager < MyTime >(coordinator)
+        pdevs::GraphManager < MyTime >(coordinator),
+        a1("a1"), b1("b1"), a2("a2"), b2("b2")
     {
-        pdevs::Simulator < MyTime, A >* a1 =
-            new pdevs::Simulator < MyTime, A >("a1");
-        pdevs::Simulator < MyTime, B >* b1 =
-            new pdevs::Simulator < MyTime, B >("b1");
-        pdevs::Simulator < MyTime, A >* a2 =
-            new pdevs::Simulator < MyTime, A >("a2");
-        pdevs::Simulator < MyTime, B >* b2 =
-            new pdevs::Simulator < MyTime, B >("b2");
-
-        add_child(a1);
-        add_child(b1);
-        add_child(a2);
-        add_child(b2);
-        add_link(a1, "out", b1, "in");
-        add_link(b1, "out", a2, "in");
-        add_link(a2, "out", b2, "in");
+        add_child(&a1);
+        add_child(&b1);
+        add_child(&a2);
+        add_child(&b2);
+        add_link(&a1, "out", &b1, "in");
+        add_link(&b1, "out", &a2, "in");
+        add_link(&a2, "out", &b2, "in");
     }
 
     virtual ~FlatGraphManager()
     { }
+
+private:
+    pdevs::Simulator < MyTime, A > a1;
+    pdevs::Simulator < MyTime, B > b1;
+    pdevs::Simulator < MyTime, A > a2;
+    pdevs::Simulator < MyTime, B > b2;
 };
 
 } } // namespace paradevs pdevs
@@ -394,7 +391,8 @@ TEST_CASE("pdevs/flat", "run")
     }
 
     for (unsigned int t = 0; t <= 10; ++t) {
-        REQUIRE(paradevs::common::Trace < paradevs::pdevs::MyTime >::trace().elements().
+        REQUIRE(paradevs::common::Trace <
+                    paradevs::pdevs::MyTime >::trace().elements().
                 filter_model_name("b1").filter_time(t).
                 filter_type(paradevs::common::LAMBDA).size() == 1);
         REQUIRE(paradevs::common::Trace <