finally get rid of std::auto_ptr

This commit is contained in:
Günter Obiltschnig
2019-12-15 09:40:40 +01:00
parent 56fe4eaf97
commit 9c197e0ed1
19 changed files with 85 additions and 229 deletions

View File

@@ -28,16 +28,16 @@ namespace
Base()
{
}
virtual ~Base()
{
}
};
class A: public Base
{
};
class B: public Base
{
};
@@ -57,26 +57,21 @@ DynamicFactoryTest::~DynamicFactoryTest()
void DynamicFactoryTest::testDynamicFactory()
{
DynamicFactory<Base> dynFactory;
dynFactory.registerClass<A>("A");
dynFactory.registerClass<B>("B");
assertTrue (dynFactory.isClass("A"));
assertTrue (dynFactory.isClass("B"));
assertTrue (!dynFactory.isClass("C"));
#ifndef POCO_ENABLE_CPP11
std::auto_ptr<A> a(dynamic_cast<A*>(dynFactory.createInstance("A")));
std::auto_ptr<B> b(dynamic_cast<B*>(dynFactory.createInstance("B")));
#else
std::unique_ptr<A> a(dynamic_cast<A*>(dynFactory.createInstance("A")));
std::unique_ptr<B> b(dynamic_cast<B*>(dynFactory.createInstance("B")));
#endif // POCO_ENABLE_CPP11
assertNotNull(a.get());
assertNotNull(b.get());
try
{
dynFactory.registerClass<A>("A");
@@ -85,18 +80,14 @@ void DynamicFactoryTest::testDynamicFactory()
catch (Poco::ExistsException&)
{
}
dynFactory.unregisterClass("B");
assertTrue (dynFactory.isClass("A"));
assertTrue (!dynFactory.isClass("B"));
try
{
#ifndef POCO_ENABLE_CPP11
std::auto_ptr<B> b(dynamic_cast<B*>(dynFactory.createInstance("B")));
#else
std::unique_ptr<B> b(dynamic_cast<B*>(dynFactory.createInstance("B")));
#endif // POCO_ENABLE_CPP11
fail("unregistered - must throw");
}
catch (Poco::NotFoundException&)

View File

@@ -49,7 +49,7 @@ namespace
{
}
};
class CustomFormatter: public Formatter
{
void format(const Message& msg, std::string& text)
@@ -72,7 +72,7 @@ LoggingFactoryTest::~LoggingFactoryTest()
void LoggingFactoryTest::testBuiltins()
{
LoggingFactory& fact = LoggingFactory::defaultFactory();
AutoPtr<Channel> pConsoleChannel = fact.createChannel("ConsoleChannel");
#if defined(_WIN32) && !defined(_WIN32_WCE)
assertTrue (dynamic_cast<Poco::WindowsConsoleChannel*>(pConsoleChannel.get()) != 0);
@@ -82,10 +82,10 @@ void LoggingFactoryTest::testBuiltins()
AutoPtr<Channel> pFileChannel = fact.createChannel("FileChannel");
assertTrue (dynamic_cast<FileChannel*>(pFileChannel.get()) != 0);
AutoPtr<Channel> pSplitterChannel = fact.createChannel("SplitterChannel");
assertTrue (dynamic_cast<SplitterChannel*>(pSplitterChannel.get()) != 0);
try
{
AutoPtr<Channel> pUnknownChannel = fact.createChannel("UnknownChannel");
@@ -94,10 +94,10 @@ void LoggingFactoryTest::testBuiltins()
catch (Poco::NotFoundException&)
{
}
AutoPtr<Formatter> pPatternFormatter = fact.createFormatter("PatternFormatter");
assertTrue (dynamic_cast<PatternFormatter*>(pPatternFormatter.get()) != 0);
try
{
AutoPtr<Formatter> pUnknownFormatter = fact.createFormatter("UnknownFormatter");
@@ -111,11 +111,7 @@ void LoggingFactoryTest::testBuiltins()
void LoggingFactoryTest::testCustom()
{
#ifndef POCO_ENABLE_CPP11
std::auto_ptr<LoggingFactory> fact(new LoggingFactory);
#else
std::unique_ptr<LoggingFactory> fact(new LoggingFactory);
#endif // POCO_ENABLE_CPP11
fact->registerChannelClass("CustomChannel", new Instantiator<CustomChannel, Channel>);
fact->registerFormatterClass("CustomFormatter", new Instantiator<CustomFormatter, Formatter>);