Compile with C++11, migrate auto_ptr to unique_ptr

github/master
str4d 2017-04-02 09:57:03 +12:00
parent 6f60680ce7
commit a50d85ca9d
3 changed files with 19 additions and 17 deletions

View File

@ -1,3 +1,5 @@
CXXFLAGS=-Werror -std=c++11
SRCS=i2psam.cpp
OBJS=$(SRCS:.cpp=.o)
TARGET=libi2psam.a

View File

@ -317,16 +317,16 @@ std::string StreamSession::generateSessionID()
return result;
}
RequestResult<std::auto_ptr<I2pSocket> > StreamSession::accept(bool silent)
RequestResult<std::unique_ptr<I2pSocket> > StreamSession::accept(bool silent)
{
typedef RequestResult<std::auto_ptr<I2pSocket> > ResultType;
typedef RequestResult<std::unique_ptr<I2pSocket> > ResultType;
std::auto_ptr<I2pSocket> streamSocket(new I2pSocket(socket_));
std::unique_ptr<I2pSocket> streamSocket(new I2pSocket(socket_));
const Message::eStatus status = accept(*streamSocket, sessionID_, silent);
switch(status)
{
case Message::OK:
return RequestResult<std::auto_ptr<I2pSocket> >(streamSocket);
return ResultType(std::move(streamSocket));
case Message::EMPTY_ANSWER:
case Message::CLOSED_SOCKET:
case Message::INVALID_ID:
@ -339,16 +339,16 @@ RequestResult<std::auto_ptr<I2pSocket> > StreamSession::accept(bool silent)
return ResultType();
}
RequestResult<std::auto_ptr<I2pSocket> > StreamSession::connect(const std::string& destination, bool silent)
RequestResult<std::unique_ptr<I2pSocket> > StreamSession::connect(const std::string& destination, bool silent)
{
typedef RequestResult<std::auto_ptr<I2pSocket> > ResultType;
typedef RequestResult<std::unique_ptr<I2pSocket> > ResultType;
std::auto_ptr<I2pSocket> streamSocket(new I2pSocket(socket_));
std::unique_ptr<I2pSocket> streamSocket(new I2pSocket(socket_));
const Message::eStatus status = connect(*streamSocket, sessionID_, destination, silent);
switch(status)
{
case Message::OK:
return ResultType(streamSocket);
return ResultType(std::move(streamSocket));
case Message::EMPTY_ANSWER:
case Message::CLOSED_SOCKET:
case Message::INVALID_ID:
@ -365,7 +365,7 @@ RequestResult<void> StreamSession::forward(const std::string& host, uint16_t por
{
typedef RequestResult<void> ResultType;
std::auto_ptr<I2pSocket> newSocket(new I2pSocket(socket_));
std::unique_ptr<I2pSocket> newSocket(new I2pSocket(socket_));
const Message::eStatus status = forward(*newSocket, sessionID_, host, port, silent);
switch(status)
{
@ -390,7 +390,7 @@ RequestResult<const std::string> StreamSession::namingLookup(const std::string&
typedef RequestResult<const std::string> ResultType;
typedef Message::Answer<const std::string> AnswerType;
std::auto_ptr<I2pSocket> newSocket(new I2pSocket(socket_));
std::unique_ptr<I2pSocket> newSocket(new I2pSocket(socket_));
const AnswerType answer = namingLookup(*newSocket, name);
switch(answer.status)
{
@ -411,7 +411,7 @@ RequestResult<const FullDestination> StreamSession::destGenerate() const
typedef RequestResult<const FullDestination> ResultType;
typedef Message::Answer<const FullDestination> AnswerType;
std::auto_ptr<I2pSocket> newSocket(new I2pSocket(socket_));
std::unique_ptr<I2pSocket> newSocket(new I2pSocket(socket_));
const AnswerType answer = destGenerate(*newSocket);
switch(answer.status)
{

View File

@ -270,7 +270,7 @@ struct RequestResult
};
template<class T>
struct RequestResult<std::auto_ptr<T> >
struct RequestResult<std::unique_ptr<T> >
{
// a class-helper for resolving a problem with conversion from temporary RequestResult to non-const RequestResult&
struct RequestResultRef
@ -283,13 +283,13 @@ struct RequestResult<std::auto_ptr<T> >
};
bool isOk;
std::auto_ptr<T> value;
std::unique_ptr<T> value;
RequestResult()
: isOk(false) {}
explicit RequestResult(std::auto_ptr<T>& value)
: isOk(true), value(value) {}
explicit RequestResult(std::unique_ptr<T>&& value)
: isOk(true), value(std::move(value)) {}
// some C++ magic
@ -340,8 +340,8 @@ public:
static std::string generateSessionID();
RequestResult<std::auto_ptr<I2pSocket> > accept(bool silent);
RequestResult<std::auto_ptr<I2pSocket> > connect(const std::string& destination, bool silent);
RequestResult<std::unique_ptr<I2pSocket> > accept(bool silent);
RequestResult<std::unique_ptr<I2pSocket> > connect(const std::string& destination, bool silent);
RequestResult<void> forward(const std::string& host, uint16_t port, bool silent);
RequestResult<const std::string> namingLookup(const std::string& name) const;
RequestResult<const FullDestination> destGenerate() const;