forked from 0ad/0ad
Refactors smart pointers creation, reduces code duplication and improves exception safety.
This was SVN commit r24915.
This commit is contained in:
parent
425f19b8ac
commit
7a71011149
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -148,7 +148,7 @@ namespace
|
||||
for (xmlNodeList::iterator skeletonNode = skeletonNodes.begin();
|
||||
skeletonNode != skeletonNodes.end(); ++skeletonNode)
|
||||
{
|
||||
std::unique_ptr<Skeleton> skeleton (new Skeleton());
|
||||
std::unique_ptr<Skeleton> skeleton = std::make_unique<Skeleton>();
|
||||
|
||||
std::string title (FUXmlParser::ReadNodeProperty(*skeletonNode, "title"));
|
||||
|
||||
|
@ -280,7 +280,7 @@ CModelDef* CModelDef::Load(const VfsPath& filename, const VfsPath& name)
|
||||
throw PSERROR_File_InvalidVersion();
|
||||
}
|
||||
|
||||
std::unique_ptr<CModelDef> mdef (new CModelDef());
|
||||
std::unique_ptr<CModelDef> mdef = std::make_unique<CModelDef>();
|
||||
mdef->m_Name = name;
|
||||
|
||||
// now unpack everything
|
||||
|
@ -91,7 +91,7 @@ typename CShaderParams<value_t>::SItems* CShaderParams<value_t>::GetInterned(con
|
||||
typedef ItemNameCmp<value_t> Cmp;
|
||||
ENSURE(std::adjacent_find(items.items.begin(), items.items.end(), std::binary_negate<Cmp>(Cmp())) == items.items.end());
|
||||
|
||||
shared_ptr<SItems> ptr(new SItems(items));
|
||||
shared_ptr<SItems> ptr = std::make_shared<SItems>(items);
|
||||
s_InternedItems.insert(std::make_pair(items, ptr));
|
||||
return ptr.get();
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ CTextureConverter::SettingsFile* CTextureConverter::LoadSettings(const VfsPath&
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::unique_ptr<SettingsFile> settings(new SettingsFile());
|
||||
std::unique_ptr<SettingsFile> settings = std::make_unique<SettingsFile>();
|
||||
|
||||
XERO_ITER_EL(root, child)
|
||||
{
|
||||
@ -385,7 +385,7 @@ bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath
|
||||
|
||||
#if CONFIG2_NVTT
|
||||
|
||||
shared_ptr<ConversionRequest> request(new ConversionRequest);
|
||||
shared_ptr<ConversionRequest> request = std::make_shared<ConversionRequest>();
|
||||
request->dest = dest;
|
||||
request->texture = texture;
|
||||
|
||||
@ -572,7 +572,7 @@ void CTextureConverter::RunThread(CTextureConverter* textureConverter)
|
||||
}
|
||||
|
||||
// Set up the result object
|
||||
shared_ptr<ConversionResult> result(new ConversionResult());
|
||||
shared_ptr<ConversionResult> result = std::make_shared<ConversionResult>();
|
||||
result->dest = request->dest;
|
||||
result->texture = request->texture;
|
||||
|
||||
|
@ -66,7 +66,7 @@ const CStr CGUI::EventNameMouseRightDoubleClick = "MouseRightDoubleClick";
|
||||
const CStr CGUI::EventNameMouseRightRelease = "MouseRightRelease";
|
||||
|
||||
CGUI::CGUI(const shared_ptr<ScriptContext>& context)
|
||||
: m_BaseObject(new CGUIDummyObject(*this)),
|
||||
: m_BaseObject(std::make_unique<CGUIDummyObject>(*this)),
|
||||
m_FocusedObject(nullptr),
|
||||
m_InternalNameNumber(0),
|
||||
m_MouseButtons(0)
|
||||
|
@ -507,7 +507,7 @@ void L10n::LoadListOfAvailableLocales()
|
||||
std::string filename = utf8_from_wstring(path.string()).substr(strlen("l10n/"));
|
||||
size_t lengthToFirstDot = filename.find('.');
|
||||
std::string localeCode = filename.substr(0, lengthToFirstDot);
|
||||
std::unique_ptr<icu::Locale> locale(new icu::Locale(icu::Locale::createCanonical(localeCode.c_str())));
|
||||
std::unique_ptr<icu::Locale> locale = std::make_unique<icu::Locale>(icu::Locale::createCanonical(localeCode.c_str()));
|
||||
auto it = std::find_if(availableLocales.begin(), availableLocales.end(), [&locale](const std::unique_ptr<icu::Locale>& l) {
|
||||
return *locale == *l;
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -472,7 +472,7 @@ public:
|
||||
{
|
||||
const OsPath name = relativePathname.Filename();
|
||||
CFileInfo fileInfo(name, cdfh->USize(), cdfh->MTime());
|
||||
shared_ptr<ArchiveFile_Zip> archiveFile(new ArchiveFile_Zip(m_file, cdfh->HeaderOffset(), cdfh->CSize(), cdfh->Checksum(), cdfh->Method()));
|
||||
shared_ptr<ArchiveFile_Zip> archiveFile = std::make_shared<ArchiveFile_Zip>(m_file, cdfh->HeaderOffset(), cdfh->CSize(), cdfh->Checksum(), cdfh->Method());
|
||||
cb(relativePathname, fileInfo, archiveFile, cbData);
|
||||
}
|
||||
|
||||
@ -548,7 +548,7 @@ private:
|
||||
// for this:
|
||||
// 1) Header file format and size differ from what we expect
|
||||
// 2) File has been truncated
|
||||
// 3) The magic id occurs inside a zip comment
|
||||
// 3) The magic id occurs inside a zip comment
|
||||
ecdr = nullptr;
|
||||
}
|
||||
else
|
||||
|
@ -105,7 +105,7 @@ static CStrInternInternals* GetString(const char* str, size_t len)
|
||||
if (it != g_Strings.end())
|
||||
return it->second.get();
|
||||
|
||||
shared_ptr<CStrInternInternals> internals(new CStrInternInternals(str, len));
|
||||
shared_ptr<CStrInternInternals> internals = std::make_shared<CStrInternInternals>(str, len);
|
||||
g_Strings.insert(std::make_pair(internals->data, internals));
|
||||
return internals.get();
|
||||
}
|
||||
|
@ -629,7 +629,7 @@ void CUserReporter::SubmitReport(const std::string& type, int version, const std
|
||||
return;
|
||||
|
||||
// Actual submit
|
||||
shared_ptr<CUserReport> report(new CUserReport);
|
||||
shared_ptr<CUserReport> report = std::make_shared<CUserReport>();
|
||||
report->m_Time = time(NULL);
|
||||
report->m_Type = type;
|
||||
report->m_Version = version;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -98,7 +98,7 @@ bool RelaxNGValidator::LoadGrammar(const std::string& grammar)
|
||||
std::map<std::string, shared_ptr<RelaxNGSchema> >::iterator it = g_SchemaCache.find(grammar);
|
||||
if (it == g_SchemaCache.end())
|
||||
{
|
||||
schema = shared_ptr<RelaxNGSchema>(new RelaxNGSchema(grammar));
|
||||
schema = std::make_shared<RelaxNGSchema>(grammar);
|
||||
g_SchemaCache[grammar] = schema;
|
||||
}
|
||||
else
|
||||
|
@ -285,7 +285,7 @@ void OverlayRenderer::PrepareForRendering()
|
||||
SOverlayTexturedLine* line = m->texlines[i];
|
||||
if (!line->m_RenderData)
|
||||
{
|
||||
line->m_RenderData = shared_ptr<CTexturedLineRData>(new CTexturedLineRData());
|
||||
line->m_RenderData = std::make_shared<CTexturedLineRData>();
|
||||
line->m_RenderData->Update(*line);
|
||||
// We assume the overlay line will get replaced by the caller
|
||||
// if terrain changes, so we don't need to detect that here and
|
||||
|
@ -78,7 +78,7 @@ void GCSliceCallbackHook(JSContext* UNUSED(cx), JS::GCProgress progress, const J
|
||||
|
||||
shared_ptr<ScriptContext> ScriptContext::CreateContext(int contextSize, int heapGrowthBytesGCTrigger)
|
||||
{
|
||||
return shared_ptr<ScriptContext>(new ScriptContext(contextSize, heapGrowthBytesGCTrigger));
|
||||
return std::make_shared<ScriptContext>(contextSize, heapGrowthBytesGCTrigger);
|
||||
}
|
||||
|
||||
ScriptContext::ScriptContext(int contextSize, int heapGrowthBytesGCTrigger):
|
||||
|
@ -365,7 +365,7 @@ void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs)
|
||||
}
|
||||
|
||||
ScriptInterface::ScriptInterface(const char* nativeScopeName, const char* debugName, const shared_ptr<ScriptContext>& context) :
|
||||
m(new ScriptInterface_impl(nativeScopeName, context))
|
||||
m(std::make_unique<ScriptInterface_impl>(nativeScopeName, context))
|
||||
{
|
||||
// Profiler stats table isn't thread-safe, so only enable this on the main thread
|
||||
if (Threading::IsMainThread())
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -430,7 +430,7 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
|
||||
// Load the map into the secondary simulation
|
||||
|
||||
LDR_BeginRegistering();
|
||||
std::unique_ptr<CMapReader> mapReader(new CMapReader);
|
||||
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
|
||||
|
||||
std::string mapType;
|
||||
scriptInterface.GetProperty(m_InitAttributes, "mapType", mapType);
|
||||
|
@ -472,7 +472,7 @@ public:
|
||||
|
||||
bool AddPlayer(const std::wstring& aiName, player_id_t player, u8 difficulty, const std::wstring& behavior)
|
||||
{
|
||||
shared_ptr<CAIPlayer> ai(new CAIPlayer(*this, aiName, player, difficulty, behavior, m_ScriptInterface));
|
||||
shared_ptr<CAIPlayer> ai = std::make_shared<CAIPlayer>(*this, aiName, player, difficulty, behavior, m_ScriptInterface);
|
||||
if (!ai->Initialise())
|
||||
return false;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -57,9 +57,9 @@ void CCmpPathfinder::Init(const CParamNode& UNUSED(paramNode))
|
||||
|
||||
m_AtlasOverlay = NULL;
|
||||
|
||||
m_VertexPathfinder = std::unique_ptr<VertexPathfinder>(new VertexPathfinder(m_MapSize, m_TerrainOnlyGrid));
|
||||
m_LongPathfinder = std::unique_ptr<LongPathfinder>(new LongPathfinder());
|
||||
m_PathfinderHier = std::unique_ptr<HierarchicalPathfinder>(new HierarchicalPathfinder());
|
||||
m_VertexPathfinder = std::make_unique<VertexPathfinder>(m_MapSize, m_TerrainOnlyGrid);
|
||||
m_LongPathfinder = std::make_unique<LongPathfinder>();
|
||||
m_PathfinderHier = std::make_unique<HierarchicalPathfinder>();
|
||||
|
||||
// Register Relax NG validator
|
||||
CXeromyces::AddValidator(g_VFS, "pathfinder", "simulation/data/pathfinder.rng");
|
||||
|
@ -196,7 +196,7 @@ private:
|
||||
CVector2D origin;
|
||||
cmpPosition->GetInterpolatedPosition2D(frameOffset, origin.X, origin.Y, rotY);
|
||||
|
||||
rangeOverlay.line = std::unique_ptr<SOverlayTexturedLine>(new SOverlayTexturedLine);
|
||||
rangeOverlay.line = std::make_unique<SOverlayTexturedLine>();
|
||||
rangeOverlay.line->m_SimContext = &GetSimContext();
|
||||
rangeOverlay.line->m_Color = m_Color;
|
||||
rangeOverlay.line->CreateOverlayTexture(&rangeOverlay.descriptor);
|
||||
|
@ -144,7 +144,7 @@ public:
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
std::unique_ptr<CMapReader> mapReader(new CMapReader());
|
||||
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
|
||||
|
||||
LDR_BeginRegistering();
|
||||
mapReader->LoadMap(L"maps/skirmishes/Median Oasis (2).pmp",
|
||||
@ -255,7 +255,7 @@ public:
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
std::unique_ptr<CMapReader> mapReader(new CMapReader());
|
||||
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
|
||||
|
||||
LDR_BeginRegistering();
|
||||
mapReader->LoadMap(L"maps/scenarios/Peloponnese.pmp",
|
||||
@ -312,7 +312,7 @@ public:
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
std::unique_ptr<CMapReader> mapReader(new CMapReader());
|
||||
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
|
||||
|
||||
LDR_BeginRegistering();
|
||||
mapReader->LoadMap(L"maps/scenarios/Peloponnese.pmp",
|
||||
|
@ -254,7 +254,7 @@ void CComponentManager::Script_RegisterComponentType_Common(ScriptInterface::Cmp
|
||||
ctWrapper.dealloc,
|
||||
cname,
|
||||
schema,
|
||||
std::unique_ptr<JS::PersistentRootedValue>(new JS::PersistentRootedValue(rq.cx, ctor))
|
||||
std::make_unique<JS::PersistentRootedValue>(rq.cx, ctor)
|
||||
};
|
||||
componentManager->m_ComponentTypesById[cid] = std::move(ct);
|
||||
|
||||
|
@ -889,7 +889,7 @@ public:
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
std::unique_ptr<CMapReader> mapReader(new CMapReader());
|
||||
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
|
||||
|
||||
LDR_BeginRegistering();
|
||||
mapReader->LoadMap(L"maps/skirmishes/Greek Acropolis (2).pmp",
|
||||
|
@ -310,7 +310,7 @@ Status OpenOggStream(const OsPath& pathname, OggStreamPtr& stream)
|
||||
PFile file(new File);
|
||||
RETURN_STATUS_IF_ERR(file->Open(pathname, L'r'));
|
||||
|
||||
shared_ptr<OggStreamImpl<VorbisFileAdapter> > tmp(new OggStreamImpl<VorbisFileAdapter>(VorbisFileAdapter(file)));
|
||||
shared_ptr<OggStreamImpl<VorbisFileAdapter>> tmp = std::make_shared<OggStreamImpl<VorbisFileAdapter>>(VorbisFileAdapter(file));
|
||||
RETURN_STATUS_IF_ERR(tmp->Open());
|
||||
stream = tmp;
|
||||
return INFO::OK;
|
||||
@ -322,7 +322,7 @@ Status OpenOggNonstream(const PIVFS& vfs, const VfsPath& pathname, OggStreamPtr&
|
||||
size_t size;
|
||||
RETURN_STATUS_IF_ERR(vfs->LoadFile(pathname, contents, size));
|
||||
|
||||
shared_ptr<OggStreamImpl<VorbisBufferAdapter> > tmp(new OggStreamImpl<VorbisBufferAdapter>(VorbisBufferAdapter(contents, size)));
|
||||
shared_ptr<OggStreamImpl<VorbisBufferAdapter>> tmp = std::make_shared<OggStreamImpl<VorbisBufferAdapter>>(VorbisBufferAdapter(contents, size));
|
||||
RETURN_STATUS_IF_ERR(tmp->Open());
|
||||
stream = tmp;
|
||||
return INFO::OK;
|
||||
|
Loading…
Reference in New Issue
Block a user