From 6968befaaca09ab84052a3f1637a56c7704cfe06 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Tue, 15 Oct 2024 11:21:03 -0400 Subject: [PATCH] Prefer dynamic_pointer_cast --- cpp/include/Ice/MetricsAdminI.h | 2 +- cpp/src/Ice/EndpointFactory.cpp | 2 +- cpp/src/Ice/IPEndpointI.cpp | 2 +- cpp/src/Ice/InputStream.cpp | 2 +- cpp/src/Ice/Instance.cpp | 2 +- cpp/src/Ice/InstrumentationI.cpp | 10 +++++----- cpp/src/Ice/LoggerAdminI.cpp | 4 ++-- cpp/src/Ice/OutgoingAsync.cpp | 2 +- cpp/src/Ice/Reference.cpp | 2 +- cpp/src/Ice/SSL/SSLEndpointI.cpp | 2 +- cpp/src/Ice/WSEndpoint.cpp | 2 +- cpp/src/IceBT/EndpointI.cpp | 2 +- cpp/test/Ice/background/EndpointI.cpp | 2 +- cpp/test/Ice/metrics/InstrumentationI.h | 4 ++-- cpp/test/Ice/optional/AllTests.cpp | 14 +++++++------- 15 files changed, 27 insertions(+), 27 deletions(-) diff --git a/cpp/include/Ice/MetricsAdminI.h b/cpp/include/Ice/MetricsAdminI.h index a063c6ac934..697e455a8ba 100644 --- a/cpp/include/Ice/MetricsAdminI.h +++ b/cpp/include/Ice/MetricsAdminI.h @@ -165,7 +165,7 @@ namespace IceInternal m = p->second.first; } - MetricsMapT* map = dynamic_cast*>(m.get()); + auto map = std::dynamic_pointer_cast>(m); assert(map); return map->getMatching(helper); } diff --git a/cpp/src/Ice/EndpointFactory.cpp b/cpp/src/Ice/EndpointFactory.cpp index d390ce56516..7ea4c4f110c 100644 --- a/cpp/src/Ice/EndpointFactory.cpp +++ b/cpp/src/Ice/EndpointFactory.cpp @@ -121,7 +121,7 @@ IceInternal::UnderlyingEndpointFactory::initialize() EndpointFactoryPtr factory = _instance->getEndpointFactory(_type); if (factory) { - EndpointFactoryWithUnderlying* f = dynamic_cast(factory.get()); + auto f = dynamic_pointer_cast(factory); if (f) { _factory = f->cloneWithUnderlying(_instance, _underlying); diff --git a/cpp/src/Ice/IPEndpointI.cpp b/cpp/src/Ice/IPEndpointI.cpp index 9027ca54edf..c18b9ebba55 100644 --- a/cpp/src/Ice/IPEndpointI.cpp +++ b/cpp/src/Ice/IPEndpointI.cpp @@ -151,7 +151,7 @@ IceInternal::IPEndpointI::withPublishedHost(string host) const bool IceInternal::IPEndpointI::equivalent(const EndpointIPtr& endpoint) const { - const IPEndpointI* ipEndpointI = dynamic_cast(endpoint.get()); + auto ipEndpointI = dynamic_pointer_cast(endpoint); if (!ipEndpointI) { return false; diff --git a/cpp/src/Ice/InputStream.cpp b/cpp/src/Ice/InputStream.cpp index f0078579c24..6581bbaa28d 100644 --- a/cpp/src/Ice/InputStream.cpp +++ b/cpp/src/Ice/InputStream.cpp @@ -41,7 +41,7 @@ IceInternal::Ex::throwUOE(const char* file, int line, const string& expectedType // If the object is an unknown sliced object, we didn't find a // value factory, in this case raise a MarshalException instead. // - UnknownSlicedValue* usv = dynamic_cast(v.get()); + UnknownSlicedValuePtr usv = dynamic_pointer_cast(v); if (usv) { throw MarshalException{ diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 498fd432a66..ddea5a1b463 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -1337,7 +1337,7 @@ IceInternal::Instance::finishSetup(int& argc, const char* argv[], const Ice::Com // Load plug-ins. // assert(!_serverThreadPool); - PluginManagerI* pluginManagerImpl = dynamic_cast(_pluginManager.get()); + auto pluginManagerImpl = dynamic_pointer_cast(_pluginManager); assert(pluginManagerImpl); pluginManagerImpl->loadPlugins(argc, argv); diff --git a/cpp/src/Ice/InstrumentationI.cpp b/cpp/src/Ice/InstrumentationI.cpp index 328666f5b26..9903a63e3c1 100644 --- a/cpp/src/Ice/InstrumentationI.cpp +++ b/cpp/src/Ice/InstrumentationI.cpp @@ -58,11 +58,11 @@ namespace ThreadState newState; }; - IPConnectionInfo* getIPConnectionInfo(const ConnectionInfoPtr& info) + IPConnectionInfoPtr getIPConnectionInfo(const ConnectionInfoPtr& info) { for (ConnectionInfoPtr p = info; p; p = p->underlying) { - IPConnectionInfo* ipInfo = dynamic_cast(p.get()); + IPConnectionInfoPtr ipInfo = dynamic_pointer_cast(p); if (ipInfo) { return ipInfo; @@ -101,7 +101,7 @@ namespace if (_id.empty()) { ostringstream os; - IPConnectionInfo* info = getIPConnectionInfo(_connectionInfo); + IPConnectionInfoPtr info = getIPConnectionInfo(_connectionInfo); if (info) { os << info->localAddress << ':' << info->localPort; @@ -850,7 +850,7 @@ CommunicatorObserverI::getConnectionObserver( try { ConnectionObserverPtr delegate; - ConnectionObserverI* o = dynamic_cast(observer.get()); + auto o = dynamic_pointer_cast(observer); if (_delegate) { delegate = _delegate->getConnectionObserver(con, endpt, state, o ? o->getDelegate() : observer); @@ -878,7 +878,7 @@ CommunicatorObserverI::getThreadObserver( try { ThreadObserverPtr delegate; - ThreadObserverI* o = dynamic_cast(observer.get()); + auto o = dynamic_pointer_cast(observer); if (_delegate) { delegate = _delegate->getThreadObserver(parent, id, state, o ? o->getDelegate() : observer); diff --git a/cpp/src/Ice/LoggerAdminI.cpp b/cpp/src/Ice/LoggerAdminI.cpp index 130ca46966e..2a4b9b4808f 100644 --- a/cpp/src/Ice/LoggerAdminI.cpp +++ b/cpp/src/Ice/LoggerAdminI.cpp @@ -565,9 +565,9 @@ namespace // // There is currently no way to have a null local logger // - assert(localLogger != 0); + assert(localLogger); - LoggerAdminLoggerI* wrapper = dynamic_cast(localLogger.get()); + auto wrapper = dynamic_pointer_cast(localLogger); if (wrapper) { // use the underlying local logger diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index 2aebebc240b..c77b51dec56 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -616,7 +616,7 @@ ProxyOutgoingAsyncBase::checkRetryAfterException(std::exception_ptr ex) // If it's a fixed proxy, retrying isn't useful as the proxy is tied to // the connection and the request will fail with the exception. - if (dynamic_cast(ref.get())) + if (dynamic_pointer_cast(ref)) { rethrow_exception(ex); } diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 3848c228f85..4dbcc357604 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -1616,7 +1616,7 @@ IceInternal::RoutableReference::filterEndpoints(const vector& allE remove_if( endpoints.begin(), endpoints.end(), - [](const EndpointIPtr& p) { return dynamic_cast(p.get()) != 0; }), + [](const EndpointIPtr& p) { return dynamic_pointer_cast(p) != nullptr; }), endpoints.end()); // Filter out endpoints according to the mode of the reference. diff --git a/cpp/src/Ice/SSL/SSLEndpointI.cpp b/cpp/src/Ice/SSL/SSLEndpointI.cpp index 7b97f083108..9c2ea665458 100644 --- a/cpp/src/Ice/SSL/SSLEndpointI.cpp +++ b/cpp/src/Ice/SSL/SSLEndpointI.cpp @@ -268,7 +268,7 @@ Ice::SSL::EndpointI::withPublishedHost(string host) const bool Ice::SSL::EndpointI::equivalent(const IceInternal::EndpointIPtr& endpoint) const { - const EndpointI* endpointI = dynamic_cast(endpoint.get()); + auto endpointI = dynamic_pointer_cast(endpoint); if (!endpointI) { return false; diff --git a/cpp/src/Ice/WSEndpoint.cpp b/cpp/src/Ice/WSEndpoint.cpp index 06419750b79..68b50fb61a6 100644 --- a/cpp/src/Ice/WSEndpoint.cpp +++ b/cpp/src/Ice/WSEndpoint.cpp @@ -289,7 +289,7 @@ IceInternal::WSEndpoint::withPublishedHost(string host) const bool IceInternal::WSEndpoint::equivalent(const EndpointIPtr& endpoint) const { - const WSEndpoint* wsEndpointI = dynamic_cast(endpoint.get()); + auto wsEndpointI = dynamic_pointer_cast(endpoint); if (!wsEndpointI) { return false; diff --git a/cpp/src/IceBT/EndpointI.cpp b/cpp/src/IceBT/EndpointI.cpp index 2567e235db8..9c1bb65ae06 100644 --- a/cpp/src/IceBT/EndpointI.cpp +++ b/cpp/src/IceBT/EndpointI.cpp @@ -212,7 +212,7 @@ IceBT::EndpointI::withPublishedHost(string) const bool IceBT::EndpointI::equivalent(const IceInternal::EndpointIPtr& endpoint) const { - const EndpointI* btEndpointI = dynamic_cast(endpoint.get()); + auto btEndpointI = dynamic_pointer_cast(endpoint); if (!btEndpointI) { return false; diff --git a/cpp/test/Ice/background/EndpointI.cpp b/cpp/test/Ice/background/EndpointI.cpp index aca9aa6e9ab..e93638987b0 100644 --- a/cpp/test/Ice/background/EndpointI.cpp +++ b/cpp/test/Ice/background/EndpointI.cpp @@ -214,7 +214,7 @@ EndpointI::withPublishedHost(string host) const bool EndpointI::equivalent(const IceInternal::EndpointIPtr& endpoint) const { - const EndpointI* testEndpointI = dynamic_cast(endpoint.get()); + auto testEndpointI = dynamic_pointer_cast(endpoint); if (!testEndpointI) { return false; diff --git a/cpp/test/Ice/metrics/InstrumentationI.h b/cpp/test/Ice/metrics/InstrumentationI.h index d73f2f81e30..74112d42da0 100644 --- a/cpp/test/Ice/metrics/InstrumentationI.h +++ b/cpp/test/Ice/metrics/InstrumentationI.h @@ -271,7 +271,7 @@ class CommunicatorObserverI final : public Ice::Instrumentation::CommunicatorObs const Ice::Instrumentation::ConnectionObserverPtr& old) final { std::lock_guard lock(_mutex); - test(!old || dynamic_cast(old.get())); + test(!old || std::dynamic_pointer_cast(old)); if (!connectionObserver) { connectionObserver = std::make_shared(); @@ -287,7 +287,7 @@ class CommunicatorObserverI final : public Ice::Instrumentation::CommunicatorObs const Ice::Instrumentation::ThreadObserverPtr& old) final { std::lock_guard lock(_mutex); - test(!old || dynamic_cast(old.get())); + test(!old || std::dynamic_pointer_cast(old)); if (!threadObserver) { threadObserver = std::make_shared(); diff --git a/cpp/test/Ice/optional/AllTests.cpp b/cpp/test/Ice/optional/AllTests.cpp index d61d5bcc8a7..a2f34ea18ac 100644 --- a/cpp/test/Ice/optional/AllTests.cpp +++ b/cpp/test/Ice/optional/AllTests.cpp @@ -608,7 +608,7 @@ allTests(Test::TestHelper* helper, bool) Ice::ValuePtr obj; in.read(obj); in.endEncapsulation(); - test(obj && dynamic_cast(obj.get())); + test(obj && dynamic_pointer_cast(obj)); } { @@ -623,7 +623,7 @@ allTests(Test::TestHelper* helper, bool) Ice::ValuePtr obj; in.read(obj); in.endEncapsulation(); - test(obj && dynamic_cast(obj.get())); + test(obj && dynamic_pointer_cast(obj)); factory->setEnabled(false); } @@ -693,7 +693,7 @@ allTests(Test::TestHelper* helper, bool) Ice::ValuePtr obj; in.read(obj); in.endEncapsulation(); - test(obj && dynamic_cast(obj.get())); + test(obj && dynamic_pointer_cast(obj)); factory->setEnabled(false); } @@ -759,7 +759,7 @@ allTests(Test::TestHelper* helper, bool) in.endEncapsulation(); factory->setEnabled(false); - rf = dynamic_cast(obj.get())->getF(); + rf = dynamic_pointer_cast(obj)->getF(); test(rf->fse.m == 56 && !rf->fsf); } cout << "ok" << endl; @@ -795,7 +795,7 @@ allTests(Test::TestHelper* helper, bool) Ice::ValuePtr obj; in.read(obj); in.endEncapsulation(); - test(dynamic_cast(obj.get())); + test(dynamic_pointer_cast(obj)); factory->setEnabled(false); } @@ -813,8 +813,8 @@ allTests(Test::TestHelper* helper, bool) Ice::ValuePtr obj; in.read(obj); in.endEncapsulation(); - test(obj && dynamic_cast(obj.get())); - dynamic_cast(obj.get())->check(); + test(obj && dynamic_pointer_cast(obj)); + dynamic_pointer_cast(obj)->check(); factory->setEnabled(false); } }