Skip to content

Commit

Permalink
Eliminate deprecated std::auto_ptr
Browse files Browse the repository at this point in the history
Replace with std::unique_ptr, and add std::move() where necessary (one
location). Remove redundant initialization to 0 (nullptr) where it
causes ambiguity.
  • Loading branch information
marktsuchida committed Mar 8, 2022
1 parent fe06007 commit 4cd47bb
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion DeviceAdapters/QCam/QICamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ int QICamera::Initialize()
}

// init the driver
m_driverAccess = auto_ptr<QIDriver::Access>(new QIDriver::Access);
m_driverAccess = unique_ptr<QIDriver::Access>(new QIDriver::Access);
if (!*m_driverAccess) {
REPORT_QERR(m_driverAccess->Status());
return DEVICE_NATIVE_MODULE_FAILED;
Expand Down
2 changes: 1 addition & 1 deletion DeviceAdapters/QCam/QICamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class QICamera : public CCameraBase<QICamera>
#endif
int SendSettingsToCamera(QCam_Settings* settings);

std::auto_ptr<QIDriver::Access> m_driverAccess;
std::unique_ptr<QIDriver::Access> m_driverAccess;

bool m_isInitialized; // Has the camera been initialized (setup)?
QCam_Handle m_camera; // handle to the camera. Used by all QCam_* functions
Expand Down
2 changes: 1 addition & 1 deletion DeviceAdapters/SerialManager/SerialManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void SerialPortLister::ListPorts(std::vector<std::string> &availablePorts)
#ifdef WIN32

availablePorts.clear();
std::auto_ptr<B100000> allDeviceNames (new B100000());
std::unique_ptr<B100000> allDeviceNames (new B100000());

// on Windows the serial ports are devices that begin with "COM"
int ret = QueryDosDevice( 0, allDeviceNames->buffer, MaxBuf);
Expand Down
2 changes: 1 addition & 1 deletion DeviceAdapters/SutterLambda/SutterLambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ bool ShutterOnTenDashTwo::Busy()
{

{
std::auto_ptr<MMThreadGuard> pg ( new MMThreadGuard(*(::gplocks_[port_])));
std::unique_ptr<MMThreadGuard> pg ( new MMThreadGuard(*(::gplocks_[port_])));
if(::g_Busy[port_])
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions DeviceAdapters/TwainCamera/TwainDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ class TwImpl

twCap.Cap = cap;
twCap.ConType = TWON_ONEVALUE;
std::auto_ptr<TW_ONEVALUE> handle( new TW_ONEVALUE);
std::unique_ptr<TW_ONEVALUE> handle( new TW_ONEVALUE);

twCap.hContainer = handle.get();
//twCap.hContainer = (void *) malloc(sizeof(TW_ONEVALUE));
Expand Down Expand Up @@ -1260,7 +1260,7 @@ class TwImpl

// cap.Cap = Cap;
// cap.ConType = TWON_ONEVALUE;
// std::auto_ptr<TW_ONEVALUEFIX32> pcontainer (new TW_ONEVALUEFIX32);
// std::unique_ptr<TW_ONEVALUEFIX32> pcontainer (new TW_ONEVALUEFIX32);
// cap.hContainer = pcontainer.get();

// pcontainer->ItemType = TWTY_FIX32;
Expand Down
22 changes: 11 additions & 11 deletions DeviceAdapters/UserDefinedSerial/ResponseDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include <vector>


std::auto_ptr<ResponseDetector>
std::unique_ptr<ResponseDetector>
ResponseDetector::NewByName(const std::string& name)
{
std::auto_ptr<ResponseDetector> newDetector;
std::unique_ptr<ResponseDetector> newDetector;

newDetector = IgnoringResponseDetector::NewByName(name);
if (newDetector.get())
Expand All @@ -49,14 +49,14 @@ ResponseDetector::NewByName(const std::string& name)
if (newDetector.get())
return newDetector;

return std::auto_ptr<ResponseDetector>();
return std::unique_ptr<ResponseDetector>();
}


std::auto_ptr<ResponseDetector>
std::unique_ptr<ResponseDetector>
IgnoringResponseDetector::NewByName(const std::string& name)
{
std::auto_ptr<ResponseDetector> ret;
std::unique_ptr<ResponseDetector> ret;
if (name == g_PropValue_ResponseIgnore)
ret.reset(new IgnoringResponseDetector());
return ret;
Expand Down Expand Up @@ -86,10 +86,10 @@ IgnoringResponseDetector::RecvAlternative(MM::Core*, MM::Device*,
}


std::auto_ptr<ResponseDetector>
std::unique_ptr<ResponseDetector>
TerminatorResponseDetector::NewByName(const std::string& name)
{
std::auto_ptr<ResponseDetector> ret;
std::unique_ptr<ResponseDetector> ret;
if (name == g_PropValue_ResponseCRLFTerminated)
ret.reset(new TerminatorResponseDetector("\r\n", "CRLF"));
else if (name == g_PropValue_ResponseCRTerminated)
Expand Down Expand Up @@ -240,10 +240,10 @@ BinaryResponseDetector::Recv(MM::Core* core, MM::Device* device,
}


std::auto_ptr<ResponseDetector>
std::unique_ptr<ResponseDetector>
FixedLengthResponseDetector::NewByName(const std::string& name)
{
std::auto_ptr<ResponseDetector> ret;
std::unique_ptr<ResponseDetector> ret;
const std::string prefix(g_PropValuePrefix_ResponseFixedByteCount);
if (name.substr(0, prefix.size()) == prefix)
{
Expand Down Expand Up @@ -322,10 +322,10 @@ FixedLengthResponseDetector::RecvAlternative(MM::Core* core,
}


std::auto_ptr<ResponseDetector>
std::unique_ptr<ResponseDetector>
VariableLengthResponseDetector::NewByName(const std::string& name)
{
std::auto_ptr<ResponseDetector> ret;
std::unique_ptr<ResponseDetector> ret;
if (name == g_PropValue_ResponseVariableByteCount)
ret.reset(new VariableLengthResponseDetector());
return ret;
Expand Down
10 changes: 5 additions & 5 deletions DeviceAdapters/UserDefinedSerial/ResponseDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ResponseDetector : boost::noncopyable
* NewByName() functions to create the appropriate instance. If name is not
* a known name, returns null.
*/
static std::auto_ptr<ResponseDetector> NewByName(const std::string& name);
static std::unique_ptr<ResponseDetector> NewByName(const std::string& name);

virtual ~ResponseDetector() {}

Expand Down Expand Up @@ -78,7 +78,7 @@ class ResponseDetector : boost::noncopyable
class IgnoringResponseDetector : public ResponseDetector
{
public:
static std::auto_ptr<ResponseDetector> NewByName(const std::string& name);
static std::unique_ptr<ResponseDetector> NewByName(const std::string& name);

virtual std::string GetMethodName() const;
virtual int RecvExpected(MM::Core* core, MM::Device* device,
Expand All @@ -101,7 +101,7 @@ class TerminatorResponseDetector : public ResponseDetector
std::string terminatorName_;

public:
static std::auto_ptr<ResponseDetector> NewByName(const std::string& name);
static std::unique_ptr<ResponseDetector> NewByName(const std::string& name);

virtual std::string GetMethodName() const;
virtual int RecvExpected(MM::Core* core, MM::Device* device,
Expand Down Expand Up @@ -138,7 +138,7 @@ class FixedLengthResponseDetector : public BinaryResponseDetector
size_t byteCount_;

public:
static std::auto_ptr<ResponseDetector> NewByName(const std::string& name);
static std::unique_ptr<ResponseDetector> NewByName(const std::string& name);

virtual std::string GetMethodName() const;
virtual int RecvExpected(MM::Core* core, MM::Device* device,
Expand All @@ -160,7 +160,7 @@ class FixedLengthResponseDetector : public BinaryResponseDetector
class VariableLengthResponseDetector : public BinaryResponseDetector
{
public:
static std::auto_ptr<ResponseDetector> NewByName(const std::string& name);
static std::unique_ptr<ResponseDetector> NewByName(const std::string& name);

virtual std::string GetMethodName() const;
virtual int RecvExpected(MM::Core* core, MM::Device* device,
Expand Down
2 changes: 1 addition & 1 deletion DeviceAdapters/UserDefinedSerial/UserDefinedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class UserDefSerialBase : public TBasicDevice<UConcreteDevice>

bool binaryMode_;
std::string asciiTerminator_;
std::auto_ptr<ResponseDetector> responseDetector_;
std::unique_ptr<ResponseDetector> responseDetector_;

std::vector<char> initializeCommand_;
std::vector<char> initializeResponse_;
Expand Down
4 changes: 2 additions & 2 deletions DeviceAdapters/UserDefinedSerial/UserDefinedSerialImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ OnResponseDetectionMethod(MM::PropertyBase* pProp, MM::ActionType eAct)
{
std::string s;
pProp->Get(s);
std::auto_ptr<ResponseDetector> newDetector =
std::unique_ptr<ResponseDetector> newDetector =
ResponseDetector::NewByName(s);
if (!newDetector.get())
return DEVICE_INVALID_PROPERTY_VALUE;
responseDetector_ = newDetector;
responseDetector_ = std::move(newDetector);
}
return DEVICE_OK;
}
Expand Down
9 changes: 3 additions & 6 deletions MMCore/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@

CMMError::CMMError(const std::string& msg, Code code) :
message_(msg),
code_(code),
underlying_(0)
code_(code)
{}


CMMError::CMMError(const char* msg, Code code) :
message_(msg ? msg : "(null message)"),
code_(code),
underlying_(0)
code_(code)
{}


Expand Down Expand Up @@ -70,8 +68,7 @@ CMMError::CMMError(const char* msg, const CMMError& underlyingError) :

CMMError::CMMError(const CMMError& other) :
message_(other.message_),
code_(other.code_),
underlying_(0)
code_(other.code_)
{
if (other.getUnderlyingError())
underlying_.reset(new CMMError(*(other.getUnderlyingError())));
Expand Down
4 changes: 2 additions & 2 deletions MMCore/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ class CMMError : public std::exception
virtual const CMMError* getUnderlyingError() const;

private:
// Prohibit assignment.
// Prohibit assignment. (BUG: Assignment should behave like copy ctor.)
CMMError& operator=(const CMMError&);

std::string message_;
Code code_;
std::auto_ptr<CMMError> underlying_;
std::unique_ptr<CMMError> underlying_;
};

#endif //_ERROR_H_

0 comments on commit 4cd47bb

Please sign in to comment.