summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorLéo Lam <leolino.lam@gmail.com>2018-04-06 12:17:09 +0200
committerGitHub <noreply@github.com>2018-04-06 12:17:09 +0200
commita957bd1ecc7af636eab2cb449b14801abb06b0bd (patch)
tree1c4ac1a8d0963ec75cfb8f5601b270f78f51369f /Source/Core/Common
parentc2fa6f5bee75a283d6195c4d53111145e1a98549 (diff)
parent4e547772da89bc541352ae7376c369eb8ceb7f44 (diff)
Merge pull request #6421 from leoetlino/fs-interface
IOS: Refactor the filesystem code
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/Common.vcxproj1
-rw-r--r--Source/Core/Common/Common.vcxproj.filters1
-rw-r--r--Source/Core/Common/Logging/Log.h2
-rw-r--r--Source/Core/Common/Logging/LogManager.cpp2
-rw-r--r--Source/Core/Common/Result.h30
-rw-r--r--Source/Core/Common/Swap.h12
6 files changed, 46 insertions, 2 deletions
diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj
index a518b531f1..5b64898b7b 100644
--- a/Source/Core/Common/Common.vcxproj
+++ b/Source/Core/Common/Common.vcxproj
@@ -138,6 +138,7 @@
<ClInclude Include="PcapFile.h" />
<ClInclude Include="Profiler.h" />
<ClInclude Include="QoSSession.h" />
+ <ClInclude Include="Result.h" />
<ClInclude Include="ScopeGuard.h" />
<ClInclude Include="SDCardUtil.h" />
<ClInclude Include="Semaphore.h" />
diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters
index 50ea0f619d..58b75ff30f 100644
--- a/Source/Core/Common/Common.vcxproj.filters
+++ b/Source/Core/Common/Common.vcxproj.filters
@@ -59,6 +59,7 @@
<ClInclude Include="PcapFile.h" />
<ClInclude Include="Profiler.h" />
<ClInclude Include="QoSSession.h" />
+ <ClInclude Include="Result.h" />
<ClInclude Include="ScopeGuard.h" />
<ClInclude Include="SDCardUtil.h" />
<ClInclude Include="SettingsHandler.h" />
diff --git a/Source/Core/Common/Logging/Log.h b/Source/Core/Common/Logging/Log.h
index 6c50789b9d..c2dd70937e 100644
--- a/Source/Core/Common/Logging/Log.h
+++ b/Source/Core/Common/Logging/Log.h
@@ -31,7 +31,7 @@ enum LOG_TYPE
IOS,
IOS_DI,
IOS_ES,
- IOS_FILEIO,
+ IOS_FS,
IOS_NET,
IOS_SD,
IOS_SSL,
diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp
index fcf606ad0b..7d910b3a8b 100644
--- a/Source/Core/Common/Logging/LogManager.cpp
+++ b/Source/Core/Common/Logging/LogManager.cpp
@@ -99,7 +99,7 @@ LogManager::LogManager()
m_log[LogTypes::IOS] = {"IOS", "IOS"};
m_log[LogTypes::IOS_DI] = {"IOS_DI", "IOS - Drive Interface"};
m_log[LogTypes::IOS_ES] = {"IOS_ES", "IOS - ETicket Services"};
- m_log[LogTypes::IOS_FILEIO] = {"IOS_FILEIO", "IOS - FileIO"};
+ m_log[LogTypes::IOS_FS] = {"IOS_FS", "IOS - Filesystem Services"};
m_log[LogTypes::IOS_SD] = {"IOS_SD", "IOS - SDIO"};
m_log[LogTypes::IOS_SSL] = {"IOS_SSL", "IOS - SSL"};
m_log[LogTypes::IOS_STM] = {"IOS_STM", "IOS - State Transition Manager"};
diff --git a/Source/Core/Common/Result.h b/Source/Core/Common/Result.h
new file mode 100644
index 0000000000..2c4f47b3d7
--- /dev/null
+++ b/Source/Core/Common/Result.h
@@ -0,0 +1,30 @@
+// Copyright 2018 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <variant>
+
+namespace Common
+{
+template <typename ResultCode, typename T>
+class Result final
+{
+public:
+ Result(ResultCode code) : m_variant{code} {}
+ Result(const T& t) : m_variant{t} {}
+ Result(T&& t) : m_variant{std::move(t)} {}
+ explicit operator bool() const { return Succeeded(); }
+ bool Succeeded() const { return std::holds_alternative<T>(m_variant); }
+ // Must only be called when Succeeded() returns false.
+ ResultCode Error() const { return std::get<ResultCode>(m_variant); }
+ // Must only be called when Succeeded() returns true.
+ const T& operator*() const { return std::get<T>(m_variant); }
+ const T* operator->() const { return &std::get<T>(m_variant); }
+ T& operator*() { return std::get<T>(m_variant); }
+ T* operator->() { return &std::get<T>(m_variant); }
+private:
+ std::variant<ResultCode, T> m_variant;
+};
+} // namespace Common
diff --git a/Source/Core/Common/Swap.h b/Source/Core/Common/Swap.h
index c5b143dbcb..207faac93c 100644
--- a/Source/Core/Common/Swap.h
+++ b/Source/Core/Common/Swap.h
@@ -166,4 +166,16 @@ inline T FromBigEndian(T data)
swap<sizeof(data)>(reinterpret_cast<u8*>(&data));
return data;
}
+
+template <typename value_type>
+struct BigEndianValue
+{
+ static_assert(std::is_arithmetic<value_type>(), "value_type must be an arithmetic type");
+ BigEndianValue() = default;
+ explicit BigEndianValue(value_type val) { *this = val; }
+ operator value_type() const { return FromBigEndian(raw); }
+ void operator=(value_type v) { raw = FromBigEndian(v); }
+private:
+ value_type raw;
+};
} // Namespace Common