Skip to content

Commit

Permalink
Replace std::unique_ptr with xr_unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeZoneMods committed Nov 3, 2018
1 parent bb5e0eb commit 1980ecb
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/Common/Common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<ClInclude Include="..\xrCommon\xr_list.h" />
<ClInclude Include="..\xrCommon\xr_map.h" />
<ClInclude Include="..\xrCommon\xr_set.h" />
<ClInclude Include="..\xrCommon\xr_smart_pointers.h" />
<ClInclude Include="..\xrCommon\xr_stack.h" />
<ClInclude Include="..\xrCommon\xr_string.h" />
<ClInclude Include="..\xrCommon\xr_unordered_map.h" />
Expand Down
3 changes: 3 additions & 0 deletions src/Common/Common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
<ClInclude Include="..\xrCommon\xr_array.h">
<Filter>xrCommon</Filter>
</ClInclude>
<ClInclude Include="..\xrCommon\xr_smart_pointers.h">
<Filter>xrCommon</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="NvMender2003">
Expand Down
1 change: 1 addition & 0 deletions src/editors/ECore/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ typedef TMsgDlgBtn TMsgDlgButtons[mbHelp];
#include "xrCore/xr_token.h"
#include "xrCommon/xr_vector.h"
#include "xrCommon/xr_string.h"
#include "xrCommon/xr_smart_pointers.h"
#include "xrCore/Animation/Bone.hpp"
#include "xrCore/Animation/Motion.hpp"

Expand Down
21 changes: 21 additions & 0 deletions src/xrCommon/xr_smart_pointers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <memory>

template <typename T>
using xr_unique_ptr = std::unique_ptr<T>;

template <typename T>
using xr_shared_ptr = std::shared_ptr<T>;

template <class T, class... Args>
inline xr_unique_ptr<T> xr_make_unique(Args&&... args)
{
return std::make_unique<T>(args...);
}

template <class T, class... Args>
inline xr_shared_ptr<T> xr_make_shared(Args&&... args)
{
return std::make_shared<T>(args...);
}
2 changes: 1 addition & 1 deletion src/xrCore/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "vfw.h"
#endif

std::unique_ptr<EFS_Utils> xr_EFS;
xr_unique_ptr<EFS_Utils> xr_EFS;
//----------------------------------------------------
EFS_Utils::EFS_Utils() {}
EFS_Utils::~EFS_Utils() {}
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class XRCORE_API EFS_Utils
static xr_string ExtractFileExt(LPCSTR src);
static xr_string ExcludeBasePath(LPCSTR full_path, LPCSTR excl_path);
};
extern XRCORE_API std::unique_ptr<EFS_Utils> xr_EFS;
extern XRCORE_API xr_unique_ptr<EFS_Utils> xr_EFS;
#define EFS (*xr_EFS)

#endif /*_INCDEF_FileSystem_H_*/
2 changes: 1 addition & 1 deletion src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

const u32 BIG_FILE_READER_WINDOW_SIZE = 1024 * 1024;

std::unique_ptr<CLocatorAPI> xr_FS;
xr_unique_ptr<CLocatorAPI> xr_FS;

#ifdef _EDITOR
static constexpr pcstr FSLTX = "fs.ltx"
Expand Down
3 changes: 2 additions & 1 deletion src/xrCore/LocatorAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "LocatorAPI_defs.h"
//#include "xrCore/Threading/Lock.hpp"
#include "xrCommon/xr_map.h"
#include "xrCommon/xr_smart_pointers.h"
#include "xrCommon/predicates.h"
#include "Common/Noncopyable.hpp"

Expand Down Expand Up @@ -255,5 +256,5 @@ class XRCORE_API CLocatorAPI : Noncopyable
void unlock_rescan();
};

extern XRCORE_API std::unique_ptr<CLocatorAPI> xr_FS;
extern XRCORE_API xr_unique_ptr<CLocatorAPI> xr_FS;
#define FS (*xr_FS)
8 changes: 4 additions & 4 deletions src/xrCore/ModuleLookup.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <memory>
#include "xrCommon/xr_smart_pointers.h"

namespace XRay
{
Expand All @@ -23,15 +23,15 @@ class XRCORE_API ModuleHandle
void* GetProcAddress(pcstr procName) const;
};

using Module = std::unique_ptr<ModuleHandle>;
using Module = xr_unique_ptr<ModuleHandle>;

inline auto LoadModule(bool dontUnload = false)
{
return std::make_unique<ModuleHandle>(dontUnload);
return xr_make_unique<ModuleHandle>(dontUnload);
}

inline auto LoadModule(pcstr moduleName, bool dontUnload = false)
{
return std::make_unique<ModuleHandle>(moduleName, dontUnload);
return xr_make_unique<ModuleHandle>(moduleName, dontUnload);
}
}
4 changes: 2 additions & 2 deletions src/xrCore/Threading/ThreadPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <mutex>
#include <condition_variable>
#include <functional>
#include <memory>
#include "xrCommon/xr_smart_pointers.h"

class XRCORE_API Thread
{
Expand All @@ -42,7 +42,7 @@ class XRCORE_API Thread
class ThreadPool
{
public:
xr_vector<std::unique_ptr<Thread>> threads;
xr_vector<xr_unique_ptr<Thread>> threads;

void initialize()
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/cpuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ unsigned int query_processor_info(processor_info* pinfo)
DWORD byteOffset = 0;
GetLogicalProcessorInformation(nullptr, &returnedLength);

auto buffer = std::make_unique<u8[]>(returnedLength);
auto buffer = xr_make_unique<u8[]>(returnedLength);
auto ptr = reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION>(buffer.get());
GetLogicalProcessorInformation(ptr, &returnedLength);

Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/xrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ void xrCore::Initialize(pcstr _ApplicationName, pcstr commandLine, LogCallback c

rtc_initialize();

xr_FS = std::make_unique<CLocatorAPI>();
xr_FS = xr_make_unique<CLocatorAPI>();

xr_EFS = std::make_unique<EFS_Utils>();
xr_EFS = xr_make_unique<EFS_Utils>();
//. R_ASSERT (co_res==S_OK);
}
if (init_fs)
Expand Down
6 changes: 3 additions & 3 deletions src/xrGame/ai_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ void CAI_Space::init()
{
AISpaceBase::Initialize();

m_ef_storage = std::make_unique<CEF_Storage>();
m_cover_manager = std::make_unique<CCoverManager>();
m_moving_objects = std::make_unique<::moving_objects>();
m_ef_storage = xr_make_unique<CEF_Storage>();
m_cover_manager = xr_make_unique<CCoverManager>();
m_moving_objects = xr_make_unique<::moving_objects>();

VERIFY(!GEnv.ScriptEngine);
GEnv.ScriptEngine = new CScriptEngine();
Expand Down
12 changes: 6 additions & 6 deletions src/xrGame/ai_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "xrAICore/AISpaceBase.hpp"
#include "xrCommon/xr_array.h"
#include "xrCommon/xr_smart_pointers.h"

#include <memory>
#include <mutex>

class CGameGraph;
Expand Down Expand Up @@ -45,7 +45,7 @@ class CAI_Space : public AISpaceBase

class CEventCallbackStorage
{
xr_vector<std::unique_ptr<CEventCallback>> m_callbacks;
xr_vector<xr_unique_ptr<CEventCallback>> m_callbacks;
std::mutex m_lock;

public:
Expand Down Expand Up @@ -84,10 +84,10 @@ class CAI_Space : public AISpaceBase
bool m_inited = false;
CNotifier m_events_notifier;

std::unique_ptr<CEF_Storage> m_ef_storage;
std::unique_ptr<CCoverManager> m_cover_manager;
std::unique_ptr<moving_objects> m_moving_objects;
std::unique_ptr<doors::manager> m_doors_manager;
xr_unique_ptr<CEF_Storage> m_ef_storage;
xr_unique_ptr<CCoverManager> m_cover_manager;
xr_unique_ptr<moving_objects> m_moving_objects;
xr_unique_ptr<doors::manager> m_doors_manager;

CALifeSimulator* m_alife_simulator = nullptr;

Expand Down

0 comments on commit 1980ecb

Please sign in to comment.