From 9dfd3fc9813e25d9a8b5fd009d555e94845e1dc2 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 15 Sep 2014 02:03:10 +0200 Subject: [PATCH] phase out some use of auto_ptr TODO: the toolfactory needs a redesign anyway, this was just placeholder code added in a very early state of the Lumiera project. We have way better memory managing facilities at hand now --- src/lib/test/run.hpp | 17 +++-- src/lib/test/suite.cpp | 79 ++++++++++++------------ src/proc/engine/engine-service-mock.cpp | 1 - src/proc/engine/engine-service.cpp | 1 - src/proc/mobject/builder/toolfactory.cpp | 4 +- src/proc/mobject/builder/toolfactory.hpp | 4 +- src/proc/play/play-controller.cpp | 1 - src/proc/play/play-process.cpp | 1 - src/proc/play/render-configurator.cpp | 1 - 9 files changed, 60 insertions(+), 49 deletions(-) diff --git a/src/lib/test/run.hpp b/src/lib/test/run.hpp index 013581e41..571f71a15 100644 --- a/src/lib/test/run.hpp +++ b/src/lib/test/run.hpp @@ -42,13 +42,14 @@ #include "lib/test/suite.hpp" #include "lib/util.hpp" +#include #include namespace test { using std::string; - using std::auto_ptr; + using std::shared_ptr; typedef std::vector & Arg; @@ -72,7 +73,7 @@ namespace test { { public: virtual ~Launcher() {} - virtual auto_ptr operator() () = 0; + virtual shared_ptr makeInstance() =0; }; @@ -91,8 +92,16 @@ namespace test { class Launch : public Launcher { public: - Launch (string testID, string groups) { Suite::enrol (this,testID,groups); }; - virtual auto_ptr operator() () { return auto_ptr (new TEST ); }; + Launch (string testID, string groups) + { + Suite::enrol (this,testID,groups); + } + + virtual shared_ptr + makeInstance () override + { + return shared_ptr (new TEST ); + } }; } // namespace test diff --git a/src/lib/test/suite.cpp b/src/lib/test/suite.cpp index 8028eb2f9..63201fbea 100644 --- a/src/lib/test/suite.cpp +++ b/src/lib/test/suite.cpp @@ -38,8 +38,6 @@ #include #include #include -#include -#include namespace test { @@ -49,7 +47,6 @@ namespace test { using std::cerr; using std::endl; using std::vector; - using std::auto_ptr; using std::shared_ptr; using boost::algorithm::trim; @@ -63,39 +60,45 @@ namespace test { - /** helper to collect and manage the test cases. - * Every testcase class should create a Launch instance - * which causes a call to Suite::enrol(), so we can add a - * pointer to this Launcher into a map indexed by the - * provided testIDs and groupIDs. - * This enables us to build a Suite instance for any - * requested group and then instantiate and invoke - * individual testcases accordingly. - */ - class Registry - { - auto_ptr groups; - public: - Registry() : groups(new GroupMap ) {}; - PTestMap& getGroup (string grpID) { return (*groups)[grpID]; }; - void add2group (Launcher* test, string testID, string groupID); - }; - - void - Registry::add2group (Launcher* test, string testID, string groupID) - { - REQUIRE( test ); - REQUIRE( !isnil(testID) ); - REQUIRE( !isnil(groupID) ); - - PTestMap& group = getGroup(groupID); - if (!group) - group.reset( new TestMap ); - (*group)[testID] = test; + namespace { + /** + * helper to collect and manage the test cases. + * Every testcase class should create a Launch instance, + * which causes a call to Suite::enrol(), so we can add a pointer + * to this Launcher into a map indexed by the provided testIDs and groupIDs. + * This enables us to build a Suite instance for any requested group + * and then instantiate and invoke individual testcases accordingly. + */ + class Registry + { + GroupMap groups_; + + public: + Registry() { }; + + PTestMap& + getGroup (string grpID) + { + return groups_[grpID]; + }; + + void + add2group (Launcher* test, string testID, string groupID) + { + REQUIRE( test ); + REQUIRE( !isnil(testID) ); + REQUIRE( !isnil(groupID) ); + + PTestMap& group = getGroup(groupID); + if (!group) + group.reset( new TestMap ); + (*group)[testID] = test; + } + }; + + Registry testcases; } - Registry testcases; - @@ -216,9 +219,9 @@ namespace test { // Special contract: in case the cmdline holds no actual arguments // beyond the test name, then it's cleared entirely. - if (1 == cmdline.size()) cmdline.clear(); // TODO this invalidates also testID -- really need to redesign the API ////TICKET #289 + if (1 == cmdline.size()) cmdline.clear(); // TODO this invalidates also testID -- really need to redesign the API ////TICKET #289 - exitCode_ |= invokeTestCase (*(*test)(), cmdline); // TODO confusing statement, improve definition of test collection datatype Ticket #289 + exitCode_ |= invokeTestCase (*test->makeInstance(), cmdline); // TODO confusing statement, improve definition of test collection datatype Ticket #289 return true; } else @@ -232,7 +235,7 @@ namespace test { std::cout << "\n ----------"<< i->first<< "----------\n"; Launcher* test = (i->second); IS_VALID (test, i->first); - exitCode_ |= invokeTestCase (*(*test)(), cmdline); // actually no cmdline arguments + exitCode_ |= invokeTestCase (*test->makeInstance(), cmdline); // actually no cmdline arguments } return true; } @@ -259,7 +262,7 @@ namespace test { IS_VALID (test, i->first); try { - (*test)()->run(noCmdline); // run it to insert test generated output + test->makeInstance()->run(noCmdline); // run it to insert test generated output } catch (...) { diff --git a/src/proc/engine/engine-service-mock.cpp b/src/proc/engine/engine-service-mock.cpp index 9bbf09c93..899e21af9 100644 --- a/src/proc/engine/engine-service-mock.cpp +++ b/src/proc/engine/engine-service-mock.cpp @@ -36,7 +36,6 @@ namespace engine{ // using std::string; // using lumiera::Subsys; -// using std::auto_ptr; // using boost::scoped_ptr; // using std::bind; diff --git a/src/proc/engine/engine-service.cpp b/src/proc/engine/engine-service.cpp index 485efd3af..45e7a24e6 100644 --- a/src/proc/engine/engine-service.cpp +++ b/src/proc/engine/engine-service.cpp @@ -36,7 +36,6 @@ namespace engine{ // using std::string; // using lumiera::Subsys; -// using std::auto_ptr; // using boost::scoped_ptr; using std::function; using std::bind; diff --git a/src/proc/mobject/builder/toolfactory.cpp b/src/proc/mobject/builder/toolfactory.cpp index 1a679c864..b116ea62f 100644 --- a/src/proc/mobject/builder/toolfactory.cpp +++ b/src/proc/mobject/builder/toolfactory.cpp @@ -24,7 +24,8 @@ #include "proc/mobject/builder/toolfactory.hpp" #include "lib/util.hpp" -//#include +#include +#include namespace proc { namespace mobject { @@ -82,6 +83,7 @@ namespace builder { } + //////////////////////////////////////////TODO: a better idea than using auto_ptr? auto_ptr ToolFactory::getProduct () { diff --git a/src/proc/mobject/builder/toolfactory.hpp b/src/proc/mobject/builder/toolfactory.hpp index 83ca8303b..b30b90907 100644 --- a/src/proc/mobject/builder/toolfactory.hpp +++ b/src/proc/mobject/builder/toolfactory.hpp @@ -64,7 +64,9 @@ namespace builder { NodeCreatorTool & configureFabrication (); /** receive the finished product of the build process; effectively - * releases any other builder tool object */ + * releases any other builder tool object + * //////////////////////////////////////////TODO a better idea than using auto_ptr? + */ std::auto_ptr getProduct (); }; diff --git a/src/proc/play/play-controller.cpp b/src/proc/play/play-controller.cpp index 6335e471d..09cc8c4a7 100644 --- a/src/proc/play/play-controller.cpp +++ b/src/proc/play/play-controller.cpp @@ -209,7 +209,6 @@ namespace play{ // using std::string; // using lumiera::Subsys; -// using std::auto_ptr; // using boost::scoped_ptr; // using std::bind; diff --git a/src/proc/play/play-process.cpp b/src/proc/play/play-process.cpp index e7491f153..c412e8a8f 100644 --- a/src/proc/play/play-process.cpp +++ b/src/proc/play/play-process.cpp @@ -38,7 +38,6 @@ namespace play { // using std::string; // using lumiera::Subsys; -// using std::auto_ptr; // using boost::scoped_ptr; // using std::bind; using lib::transform; diff --git a/src/proc/play/render-configurator.cpp b/src/proc/play/render-configurator.cpp index 95b820c65..e0be1facd 100644 --- a/src/proc/play/render-configurator.cpp +++ b/src/proc/play/render-configurator.cpp @@ -41,7 +41,6 @@ namespace play { namespace error = lumiera::error; // using std::string; // using lumiera::Subsys; -// using std::auto_ptr; // using boost::scoped_ptr; using std::shared_ptr; using std::bind;