Replace std::auto_ptr with std::unique_ptr

std::auto_ptr has awkward copy semantics and is deprecated in C++11.
scancodes-fix
Nicolas Hake 2013-03-19 17:28:19 +01:00
parent 698be41e90
commit 459fce0758
15 changed files with 43 additions and 21 deletions

View File

@ -96,6 +96,8 @@ endforeach()
# out because it does not understand -std=gnu++0x
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS ${OC_REQUIRED_FLAGS})
include(RequireCXXSourceCompiles)
REQUIRE_CXX_SOURCE_COMPILES("#include <memory>\nint main() { std::unique_ptr<int> a; std::shared_ptr<int> b; }" HAVE_C11_SMART_PTRS)
CHECK_CXX_SOURCE_COMPILES("void f(struct D&&); int main() { return 0; }" HAVE_RVALUE_REF)
CHECK_CXX_SOURCE_COMPILES("int main() { void *d = nullptr; }" HAVE_NULLPTR)
CHECK_CXX_SOURCE_COMPILES("int main() { static_assert(true, \"\"); }" HAVE_STATIC_ASSERT)

View File

@ -0,0 +1,20 @@
# OpenClonk, http://www.openclonk.org
#
# Copyright (c) 2013 Nicolas Hake
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# See isc_license.txt for full license and disclaimer.
#
# "Clonk" is a registered trademark of Matthes Bender.
# See clonk_trademark_license.txt for full license.
include(CheckCXXSourceCompiles)
macro(REQUIRE_CXX_SOURCE_COMPILES _code _var)
CHECK_CXX_SOURCE_COMPILES("${_code}" ${_var})
if(NOT ${_var})
unset(${_var} CACHE)
MESSAGE(FATAL_ERROR "${_var} is required for this project to build properly. Aborting.")
endif()
endmacro()

View File

@ -46,7 +46,7 @@ bool C4Extra::InitGroup()
// register extra root into game group set
for(C4Reloc::iterator iter = Reloc.begin(); iter != Reloc.end(); ++iter)
{
std::auto_ptr<C4Group> pGroup(new C4Group);
std::unique_ptr<C4Group> pGroup(new C4Group);
if(pGroup->Open( ((*iter).strBuf + DirSep + C4CFN_Extra).getData()))
ExtraGroups.push_back(pGroup.release());
}

View File

@ -417,7 +417,7 @@ int32_t C4Landscape::DigFreeShape(int *vtcs, int length, C4Object *by_object, bo
C4FindObjectLayer fo_layer(by_object ? by_object->Layer : NULL);
C4FindObject *fo_list[] = {&fo_inrect, &fo_collectible, &fo_insolid, &fo_layer};
C4FindObjectAndStatic fo_srch(4, fo_list);
std::auto_ptr<C4ValueArray> dig_objects(fo_srch.FindMany(::Objects, ::Objects.Sectors));
std::unique_ptr<C4ValueArray> dig_objects(fo_srch.FindMany(::Objects, ::Objects.Sectors));
if(by_object)
{

View File

@ -197,7 +197,7 @@ static bool FnLayerDraw(C4PropList * _this, C4String *mattex, C4PropList *mask_a
if (!layer || icol<0) return false;
C4Rect rcBounds;
if (!FnParRect(layer, rect, &rcBounds)) return false;
std::auto_ptr<C4MapScriptAlgo> algo(FnParAlgo(mask_algo));
std::unique_ptr<C4MapScriptAlgo> algo(FnParAlgo(mask_algo));
return layer->Fill(icol, rcBounds, algo.get());
}
@ -208,7 +208,7 @@ static bool FnLayerBlit(C4PropList * _this, C4PropList *mask_algo, C4ValueArray
if (!layer) return false;
C4Rect rcBounds;
if (!FnParRect(layer, rect, &rcBounds)) return false;
std::auto_ptr<C4MapScriptAlgo> algo(FnParAlgo(mask_algo));
std::unique_ptr<C4MapScriptAlgo> algo(FnParAlgo(mask_algo));
if (!algo.get()) return false;
return layer->Blit(rcBounds, algo.get());
}
@ -579,7 +579,7 @@ bool C4MapScriptHost::InitializeMap(C4Group &group, CSurface8 **pmap_surface)
if (!scen_proplist || !scen_proplist->GetFunc(PSF_InitializeMap)) return false;
}
// Create proplist as script context
std::auto_ptr<C4MapScriptMap> map(CreateMap());
std::unique_ptr<C4MapScriptMap> map(CreateMap());
// Drawing on existing map or create new?
if (*pmap_surface)
{

View File

@ -331,7 +331,7 @@ void CompileNewFunc(T *&pStruct, StdCompiler *pComp)
// a) Define a standard constructor for T
// b) Specialize this function to do whatever the correct
// behaviour is to construct the object from compiler data
std::auto_ptr<T> temp(new T); // exception-safety
std::unique_ptr<T> temp(new T); // exception-safety
// Compile
pComp->Value(*temp);
pStruct = temp.release();
@ -345,7 +345,7 @@ void CompileNewFunc(T *&pStruct, StdCompiler *pComp, const P& rPar)
// a) Define a standard constructor for T
// b) Specialize this function to do whatever the correct
// behaviour is to construct the object from compiler data
std::auto_ptr<T> temp(new T); // exception-safety
std::unique_ptr<T> temp(new T); // exception-safety
// Compile
//temp->CompileFunc(pComp, rPar);
pComp->Value(mkParAdapt(*temp, rPar));
@ -361,7 +361,7 @@ void CompileNewFuncCtx(T *&pStruct, StdCompiler *pComp, const ContextT& rCtx)
// b) Specialize this function to do whatever the correct
// behaviour is to construct the object from compiler data
// and context
std::auto_ptr<T> temp(new T(rCtx)); // exception-safety
std::unique_ptr<T> temp(new T(rCtx)); // exception-safety
// Compile
pComp->Value(*temp);
pStruct = temp.release();
@ -376,7 +376,7 @@ void CompileNewFuncCtx(T *&pStruct, StdCompiler *pComp, const ContextT& rCtx, co
// b) Specialize this function to do whatever the correct
// behaviour is to construct the object from compiler data
// and context
std::auto_ptr<T> temp(new T(rCtx)); // exception-safety
std::unique_ptr<T> temp(new T(rCtx)); // exception-safety
// Compile
//temp->CompileFunc(pComp, rPar);
pComp->Value(mkParAdapt(*temp, rPar));

View File

@ -1017,7 +1017,7 @@ StdMeshInstance::AttachedMesh* StdMeshInstance::AttachMesh(const StdMesh& mesh,
StdMeshInstance::AttachedMesh* StdMeshInstance::AttachMesh(StdMeshInstance& instance, AttachedMesh::Denumerator* denumerator, const StdStrBuf& parent_bone, const StdStrBuf& child_bone, const StdMeshMatrix& transformation, uint32_t flags, bool own_child)
{
std::auto_ptr<AttachedMesh::Denumerator> auto_denumerator(denumerator);
std::unique_ptr<AttachedMesh::Denumerator> auto_denumerator(denumerator);
// We don't allow an instance to be attached to multiple parent instances for now
if (instance.AttachParent) return NULL;

View File

@ -576,7 +576,7 @@ private:
inline void CompileNewFuncCtx(StdMeshInstance::SerializableValueProvider *&pStruct, StdCompiler *pComp, const StdMeshInstance::SerializableValueProvider::IDBase& rID)
{
std::auto_ptr<StdMeshInstance::SerializableValueProvider> temp(rID.newfunc());
std::unique_ptr<StdMeshInstance::SerializableValueProvider> temp(rID.newfunc());
pComp->Value(*temp);
pStruct = temp.release();
}

View File

@ -206,7 +206,7 @@ StdMesh *StdMeshLoader::LoadMeshBinary(const char *src, size_t length, const Std
// Generate mesh from data
Ogre::Mesh::ChunkMesh &cmesh = *static_cast<Ogre::Mesh::ChunkMesh*>(root.get());
std::auto_ptr<StdMesh> mesh(new StdMesh);
std::unique_ptr<StdMesh> mesh(new StdMesh);
mesh->BoundingBox = cmesh.bounds;
mesh->BoundingRadius = cmesh.radius;
@ -298,7 +298,7 @@ void StdMeshLoader::LoadSkeletonBinary(StdMesh *mesh, const char *src, size_t si
id = Ogre::Skeleton::Chunk::Peek(&stream)
)
{
std::auto_ptr<Ogre::Skeleton::Chunk> chunk(Ogre::Skeleton::Chunk::Read(&stream));
std::unique_ptr<Ogre::Skeleton::Chunk> chunk(Ogre::Skeleton::Chunk::Read(&stream));
switch (chunk->GetType())
{
case Ogre::Skeleton::CID_BlendMode:

View File

@ -55,7 +55,7 @@ namespace Ogre
}
// Create chunk
std::auto_ptr<Chunk> chunk;
std::unique_ptr<Chunk> chunk;
switch (id)
{
case CID_Header: chunk.reset(new ChunkFileHeader()); break;
@ -361,7 +361,7 @@ namespace Ogre
}
// Create chunk
std::auto_ptr<Chunk> chunk;
std::unique_ptr<Chunk> chunk;
switch (id)
{
case CID_Header: chunk.reset(new ChunkFileHeader()); break;

View File

@ -244,7 +244,7 @@ StdMesh *StdMeshLoader::LoadMeshXml(const char* xml_data, size_t size, const Std
{
StdMeshXML xml(filename ? filename : "<unknown>", xml_data);
std::auto_ptr<StdMesh> mesh(new StdMesh);
std::unique_ptr<StdMesh> mesh(new StdMesh);
TiXmlElement* mesh_elem = xml.RequireFirstChild(NULL, "mesh");

View File

@ -649,7 +649,7 @@ StdMeshMaterialTextureUnit::StdMeshMaterialTextureUnit():
void StdMeshMaterialTextureUnit::LoadTexture(StdMeshMaterialParserCtx& ctx, const char* texname)
{
std::auto_ptr<C4Surface> surface(ctx.TextureLoader.LoadTexture(texname)); // be exception-safe
std::unique_ptr<C4Surface> surface(ctx.TextureLoader.LoadTexture(texname)); // be exception-safe
if (!surface.get())
ctx.Error(StdCopyStrBuf("Could not load texture '") + texname + "'");

View File

@ -242,7 +242,7 @@ int C4Network2UPnPP::Callback_Static(Upnp_EventType EventType, void* Event, void
break;
case UPNP_CONTROL_ACTION_COMPLETE:
{
std::auto_ptr<ActionData> data(static_cast<ActionData*>(Cookie));
std::unique_ptr<ActionData> data(static_cast<ActionData*>(Cookie));
Upnp_Action_Complete* complete = static_cast<Upnp_Action_Complete*>(Event);
std::string action = ixmlNode_getNodeName(ixmlNode_getFirstChild(&complete->ActionRequest->n));
Application.InteractiveThread.PushEvent(Ev_UPNP_Response, new NotifyActionComplete(*data, action, complete->ErrCode));
@ -258,7 +258,7 @@ int C4Network2UPnPP::Callback_Static(Upnp_EventType EventType, void* Event, void
void C4Network2UPnPP::OnThreadEvent(C4InteractiveEventType eEvent, void *pEventData)
{
std::auto_ptr<Notify> notify(static_cast<Notify*>(pEventData));
std::unique_ptr<Notify> notify(static_cast<Notify*>(pEventData));
// TODO: Should call a virtual method instead of dynamic_casting
NotifySearchResult* notify_search_result = dynamic_cast<NotifySearchResult*>(notify.get());

View File

@ -325,7 +325,7 @@ void C4DefGraphics::Draw(C4Facet &cgo, DWORD iColor, C4Object *pObj, int32_t iPh
break;
case C4DefGraphics::TYPE_Mesh:
// TODO: Allow rendering of a mesh directly, without instance (to render pose; no animation)
std::auto_ptr<StdMeshInstance> dummy;
std::unique_ptr<StdMeshInstance> dummy;
StdMeshInstance* instance;
C4Value value;

View File

@ -251,7 +251,7 @@ void C4PropList::CompileFunc(StdCompiler *pComp, C4ValueNumbers * numbers)
void CompileNewFunc(C4PropList *&pStruct, StdCompiler *pComp, C4ValueNumbers * const & rPar)
{
std::auto_ptr<C4PropList> temp(C4PropList::New()); // exception-safety
std::unique_ptr<C4PropList> temp(C4PropList::New()); // exception-safety
pComp->Value(mkParAdapt(*temp, rPar));
pStruct = temp.release();
}