Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove more use of std::auto_ptr #608

Merged
merged 6 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class Row
std::vector< Field > mData;
};

//typedef mem::auto_ptr< Row > pRow;
//typedef std::unique_ptr< Row > pRow;

/*!
* \class ResultSet
Expand Down Expand Up @@ -303,7 +303,7 @@ class ResultSet
Row mCurrentRow;
};

typedef mem::auto_ptr< ResultSet > pResultSet;
typedef std::unique_ptr< ResultSet > pResultSet;

/*!
* \class DatabaseConnection
Expand Down
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/io/include/io/DbgStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct DbgStream : public OutputStream
}
protected:
//! The bound stream
mem::auto_ptr<OutputStream> mStream;
std::unique_ptr<OutputStream> mStream;
//! On or off??
bool mOn = false;
};
Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/io/include/io/ProxyStreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct CODA_OSS_API ProxyInputStream : public InputStream
return mProxy->read(buffer, len);
}

mem::auto_ptr<InputStream> mProxy;
std::unique_ptr<InputStream> mProxy;
bool mOwnPtr;
};

Expand Down Expand Up @@ -117,7 +117,7 @@ struct CODA_OSS_API ProxyOutputStream : public OutputStream
}

protected:
mem::auto_ptr<OutputStream> mProxy;
std::unique_ptr<OutputStream> mProxy;
bool mOwnPtr = false;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ using path = std::filesystem::path;
#else
using path = coda_oss::filesystem::path;
#endif
mem::auto_ptr<logging::Logger> setupLogger(
std::unique_ptr<logging::Logger> setupLogger(
const path& program,
const std::string& logLevel = "warning",
const path& logFile = "console",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct CODA_OSS_API StreamHandler : public Handler
// used for the bulk of the logging for speed
void emitRecord(const LogRecord* record) override;

mem::auto_ptr<io::OutputStream> mStream;
std::unique_ptr<io::OutputStream> mStream;

private:
bool mClosed;
Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/logging/source/Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "logging/Setup.h"

mem::auto_ptr<logging::Logger>
std::unique_ptr<logging::Logger>
logging::setupLogger(const path& program_,
const std::string& logLevel,
const path& logFile_,
Expand Down Expand Up @@ -89,5 +89,5 @@ logging::setupLogger(const path& program_,
logHandler->setFormatter(formatter.release());
log->addHandler(logHandler.release(), true);

return mem::auto_ptr<logging::Logger>(log.release());
return std::unique_ptr<logging::Logger>(log.release());
}
18 changes: 17 additions & 1 deletion externals/coda-oss/modules/c++/mem/include/mem/AutoPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#pragma once

#include <memory>
#include <type_traits>

#include "coda_oss/memory.h"
#include "mem/SharedPtr.h"

namespace mem
{
Expand Down Expand Up @@ -81,6 +81,18 @@ class AutoPtr final
*this = std::move(p);
}

template<typename U>
AutoPtr& operator=(std::auto_ptr<U> p) noexcept
{
ptr_.reset(p.release());
return *this;
}
template <typename U>
AutoPtr(std::auto_ptr<U> p) noexcept
{
*this = p;
}


T* get() const noexcept
{
Expand All @@ -106,6 +118,10 @@ class AutoPtr final
{
return get();
}

operator std::unique_ptr<T>& () { return ptr_; }
operator const std::unique_ptr<T>& () const { return ptr_; }

};

} // namespace mem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ namespace mem
/*!
* \class ScopedCloneablePtr
* \brief This class provides RAII for object allocations via new. It is a
* light wrapper around std::auto_ptr and has the same semantics
* light wrapper around std::unique_ptr and has the same semantics
* except that the copy constructor and assignment operator are deep
* copies (by using T's clone() method) rather than transferring
* ownership.
*
* This is useful for cases where you have a class which has a member
* variable that's dynamically allocated and you want to provide a
* valid copy constructor / assignment operator. With raw pointers or
* std::auto_ptr's, you'll have to write the copy constructor /
* std::unique_ptr's, you'll have to write the copy constructor /
* assignment operator for this class - this is tedious and
* error-prone since you need to include all the members in the class.
* Using ScopedCloneablePtr's instead, the compiler-generated copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ namespace mem
/*!
* \class ScopedCopyablePtr
* \brief This class provides RAII for object allocations via new. It is a
* light wrapper around std::auto_ptr and has the same semantics
* light wrapper around std::unique_ptr and has the same semantics
* except that the copy constructor and assignment operator are deep
* copies (that is, they use T's copy constructor) rather than
* transferring ownership.
*
* This is useful for cases where you have a class which has a member
* variable that's dynamically allocated and you want to provide a
* valid copy constructor / assignment operator. With raw pointers or
* std::auto_ptr's, you'll have to write the copy constructor /
* std::unique_ptr's, you'll have to write the copy constructor /
* assignment operator for this class - this is tedious and
* error-prone since you need to include all the members in the class.
* Using ScopedCopyablePtr's instead, the compiler-generated copy
Expand Down
16 changes: 2 additions & 14 deletions externals/coda-oss/modules/c++/mem/include/mem/ScopedPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ namespace mem
/*!
* \class ScopedPtr
* \brief This class provides RAII for object allocations via new. It is a
* light wrapper around std::auto_ptr and has the same semantics
* light wrapper around std::unique_ptr and has the same semantics
* except that the copy constructor and assignment operator are deep
* copies (by using T's clone() method) rather than transferring
* ownership.
*
* This is useful for cases where you have a class which has a member
* variable that's dynamically allocated and you want to provide a
* valid copy constructor / assignment operator. With raw pointers or
* std::auto_ptr's, you'll have to write the copy constructor /
* std::unique_ptr's, you'll have to write the copy constructor /
* assignment operator for this class - this is tedious and
* error-prone since you need to include all the members in the class.
* Using ScopedCloneablePtr's instead, the compiler-generated copy
Expand Down Expand Up @@ -77,12 +77,6 @@ class ScopedPtr
{
reset(std::move(ptr));
}
#if CODA_OSS_autoptr_is_std // std::auto_ptr removed in C++17
explicit ScopedPtr(mem::auto_ptr<T> ptr)
{
reset(ptr);
}
#endif

ScopedPtr(const ScopedPtr& rhs)
{
Expand Down Expand Up @@ -161,12 +155,6 @@ class ScopedPtr
{
mPtr = std::move(ptr);
}
#if CODA_OSS_autoptr_is_std // std::auto_ptr removed in C++17
void reset(mem::auto_ptr<T> ptr)
{
reset(std::unique_ptr<T>(ptr.release()));
}
#endif
};
}

Expand Down
23 changes: 0 additions & 23 deletions externals/coda-oss/modules/c++/mem/include/mem/SharedPtrCpp11.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,6 @@

namespace mem
{
// This won't work everywhere since C++11's std::unique_ptr<> often requires
// "&&" and std::move. But for member data and the like it can reduce some
// boiler-plate code; note that it's often possible to just use std::unique_ptr
// directly. This is mostly needed to support existing interfaces.
#if CODA_OSS_cpp17 // std::auto_ptr removed in C++17
#if defined(CODA_OSS_no_autoptr) && (!CODA_OSS_no_autoptr)
#error "std::auto_ptr was removed in C++17."
#endif
#define CODA_OSS_autoptr_is_std 0 // mem::auto_ptr != std::auto_ptr
#else // C++11 or C++14 still have std::auto_ptr, but it's depricated
#ifdef CODA_OSS_no_autoptr // don't use std::auto_ptr even if it's available
#define CODA_OSS_autoptr_is_std 0 // mem::auto_ptr != std::auto_ptr
#else
#define CODA_OSS_autoptr_is_std 1 // mem::auto_ptr == std::auto_ptr
#endif
#endif
template <typename T> using auto_ptr =
#if CODA_OSS_autoptr_is_std
std::auto_ptr<T>;
#else
std::unique_ptr<T>;
#endif

// Pretty much give-up on mem::SharedPtr as it's too hard to get something that will
// compile with all the different compilers; let somebody else worry about that
// via std::shared_ptr. The only code change is use_count() instead of getCount(),
Expand Down
16 changes: 0 additions & 16 deletions externals/coda-oss/modules/c++/mem/include/mem/VectorOfPointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ struct VectorOfPointers
mValues.resize(mValues.size() + 1);
mValues.back() = value.release();
}
#if CODA_OSS_autoptr_is_std // std::auto_ptr removed in C++17
template <typename OtherT>
void push_back(mem::auto_ptr<OtherT> value)
{
std::unique_ptr<OtherT> scopedValue(value.release());
push_back(std::move(scopedValue));
}
#endif

typedef typename std::vector<T*>::iterator iterator;
typedef typename std::vector<T*>::const_iterator const_iterator;
Expand Down Expand Up @@ -199,14 +191,6 @@ template <typename T>
mValues.resize(mValues.size() + 1);
mValues.back().reset(value.release());
}
#if CODA_OSS_autoptr_is_std // std::auto_ptr removed in C++17
template <typename OtherT>
void push_back(mem::auto_ptr<OtherT> value)
{
std::unique_ptr<OtherT> scopedValue(value.release());
push_back(std::move(scopedValue));
}
#endif

template <typename OtherT>
void push_back(std::shared_ptr<OtherT> value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class AbstractCPUAffinityInitializer
* \returns a new thread initializer. In general, this should return
* a different affinity initializer each time it is called.
*/
mem::auto_ptr<AbstractCPUAffinityThreadInitializer> newThreadInitializer()
std::unique_ptr<AbstractCPUAffinityThreadInitializer> newThreadInitializer()
{
return mem::auto_ptr<AbstractCPUAffinityThreadInitializer>(
return std::unique_ptr<AbstractCPUAffinityThreadInitializer>(
newThreadInitializerImpl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class AbstractTiedThreadPool : public AbstractThreadPool<Request_T>
mAffinityInit = affinityInit;
}

virtual mem::auto_ptr<CPUAffinityThreadInitializer>
virtual std::unique_ptr<CPUAffinityThreadInitializer>
getCPUAffinityThreadInitializer()
{
mem::auto_ptr<CPUAffinityThreadInitializer> threadInit(nullptr);
std::unique_ptr<CPUAffinityThreadInitializer> threadInit(nullptr);

// If we were passed a schematic
// for initializing thread affinity...
Expand All @@ -74,11 +74,11 @@ class AbstractTiedThreadPool : public AbstractThreadPool<Request_T>
#if CODA_OSS_cpp17
std::unique_ptr<CPUAffinityThreadInitializer>&& init) = 0;
#else
mem::auto_ptr<CPUAffinityThreadInitializer> init) = 0;
std::unique_ptr<CPUAffinityThreadInitializer> init) = 0;
virtual mt::TiedWorkerThread<Request_T>*
newTiedWorker(mt::RequestQueue<Request_T>* q,
std::unique_ptr<CPUAffinityThreadInitializer>&& init) {
mem::auto_ptr<CPUAffinityThreadInitializer> init_(init.release());
std::unique_ptr<CPUAffinityThreadInitializer> init_(init.release());
return newTiedWorker(q, init_);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace mt
{
struct AbstractNextCPUProviderLinux
{
virtual mem::auto_ptr<const sys::ScopedCPUMaskUnix> nextCPU() = 0;
virtual std::unique_ptr<const sys::ScopedCPUMaskUnix> nextCPU() = 0;
};

/*!
Expand Down Expand Up @@ -69,9 +69,9 @@ class CPUAffinityInitializerLinux : public AbstractCPUAffinityInitializer
* \returns a new CPUAffinityInitializerLinux for the next available
* CPU that can be bound to.
*/
mem::auto_ptr<CPUAffinityThreadInitializerLinux> newThreadInitializer()
std::unique_ptr<CPUAffinityThreadInitializerLinux> newThreadInitializer()
{
return mem::auto_ptr<CPUAffinityThreadInitializerLinux>(
return std::unique_ptr<CPUAffinityThreadInitializerLinux>(
newThreadInitializerImpl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class CPUAffinityInitializerWin32 : public AbstractCPUAffinityInitializer
* \todo Not yet implemented
* \returns NULL
*/
mem::auto_ptr<CPUAffinityThreadInitializerWin32> newThreadInitializer()
std::unique_ptr<CPUAffinityThreadInitializerWin32> newThreadInitializer()
{
return mem::auto_ptr<CPUAffinityThreadInitializerWin32>(
return std::unique_ptr<CPUAffinityThreadInitializerWin32>(
newThreadInitializerImpl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ class CPUAffinityThreadInitializerLinux :
*/
CPUAffinityThreadInitializerLinux(
std::unique_ptr<const sys::ScopedCPUMaskUnix>&& cpu);
#if CODA_OSS_autoptr_is_std // std::auto_ptr removed in C++17
CPUAffinityThreadInitializerLinux(
mem::auto_ptr<const sys::ScopedCPUMaskUnix> cpu);
#endif

/*!
* Attempt to bind to the affinity mask given during construction
Expand Down
12 changes: 1 addition & 11 deletions externals/coda-oss/modules/c++/mt/include/mt/ThreadGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ struct CODA_OSS_API ThreadGroup
* \param runnable auto_ptr to sys::Runnable
*/
void createThread(std::unique_ptr<sys::Runnable>&& runnable);
#if CODA_OSS_autoptr_is_std
void createThread(mem::auto_ptr<sys::Runnable> runnable);
#endif

/*!
* Waits for all threads to complete.
Expand Down Expand Up @@ -138,7 +135,7 @@ struct CODA_OSS_API ThreadGroup
* the internal CPUAffinityInitializer. If no initializer
* was created, will return NULL.
*/
mem::auto_ptr<CPUAffinityThreadInitializer> getNextInitializer();
std::unique_ptr<CPUAffinityThreadInitializer> getNextInitializer();

/*!
* \class ThreadGroupRunnable
Expand All @@ -164,13 +161,6 @@ struct CODA_OSS_API ThreadGroup
mt::ThreadGroup& parentThreadGroup,
std::unique_ptr<CPUAffinityThreadInitializer>&& threadInit =
std::unique_ptr<CPUAffinityThreadInitializer>(nullptr));
#if CODA_OSS_autoptr_is_std
ThreadGroupRunnable(
mem::auto_ptr<sys::Runnable> runnable,
mt::ThreadGroup& parentThreadGroup,
mem::auto_ptr<CPUAffinityThreadInitializer> threadInit =
mem::auto_ptr<CPUAffinityThreadInitializer>(nullptr));
#endif

ThreadGroupRunnable(const ThreadGroupRunnable&) = delete;
ThreadGroupRunnable& operator=(const ThreadGroupRunnable&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class TiedWorkerThread : public mt::WorkerThread<Request_T>
#if !CODA_OSS_cpp17
TiedWorkerThread(
mt::RequestQueue<Request_T>* requestQueue,
mem::auto_ptr<CPUAffinityThreadInitializer> cpuAffinityInit =
mem::auto_ptr<CPUAffinityThreadInitializer>(nullptr)) :
std::unique_ptr<CPUAffinityThreadInitializer> cpuAffinityInit =
std::unique_ptr<CPUAffinityThreadInitializer>(nullptr)) :
TiedWorkerThread(requestQueue, std::unique_ptr<CPUAffinityThreadInitializer>(cpuAffinityInit.release()))
{
}
Expand Down
Loading