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
This commit is contained in:
parent
d064623bab
commit
9dfd3fc981
9 changed files with 60 additions and 49 deletions
|
|
@ -42,13 +42,14 @@
|
|||
#include "lib/test/suite.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace test {
|
||||
|
||||
using std::string;
|
||||
using std::auto_ptr;
|
||||
using std::shared_ptr;
|
||||
|
||||
typedef std::vector<string> & Arg;
|
||||
|
||||
|
|
@ -72,7 +73,7 @@ namespace test {
|
|||
{
|
||||
public:
|
||||
virtual ~Launcher() {}
|
||||
virtual auto_ptr<Test> operator() () = 0;
|
||||
virtual shared_ptr<Test> 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<Test> operator() () { return auto_ptr<Test> (new TEST ); };
|
||||
Launch (string testID, string groups)
|
||||
{
|
||||
Suite::enrol (this,testID,groups);
|
||||
}
|
||||
|
||||
virtual shared_ptr<Test>
|
||||
makeInstance () override
|
||||
{
|
||||
return shared_ptr<Test> (new TEST );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
|
||||
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<GroupMap> 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 (...)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ namespace engine{
|
|||
|
||||
// using std::string;
|
||||
// using lumiera::Subsys;
|
||||
// using std::auto_ptr;
|
||||
// using boost::scoped_ptr;
|
||||
// using std::bind;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@
|
|||
#include "proc/mobject/builder/toolfactory.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
//#include <boost/ptr_container/ptr_vector.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace proc {
|
||||
namespace mobject {
|
||||
|
|
@ -82,6 +83,7 @@ namespace builder {
|
|||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////TODO: a better idea than using auto_ptr?
|
||||
auto_ptr<engine::RenderGraph>
|
||||
ToolFactory::getProduct ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<engine::RenderGraph> getProduct ();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -209,7 +209,6 @@ namespace play{
|
|||
|
||||
// using std::string;
|
||||
// using lumiera::Subsys;
|
||||
// using std::auto_ptr;
|
||||
// using boost::scoped_ptr;
|
||||
// using std::bind;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue