Skip to content

Commit

Permalink
Port/strings Typedef (#574)
Browse files Browse the repository at this point in the history
* Create StringType in String Module

* Remove StringType From File dep

* Add Back RC::File::String* for Compatibility

* Seperate Stream Type into I/O and Keep Original Name

* Use StreamIType in File

* Use fmt for ToString

* Include String as Deps
  • Loading branch information
Yangff authored Jul 27, 2024
1 parent e4a1d60 commit 7f5b638
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 44 deletions.
49 changes: 7 additions & 42 deletions deps/first/File/include/File/Macros.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#pragma once

// Set this to 1 to use ANSI (char*) instead of wide strings (wchar_t*)
#ifndef RC_IS_ANSI
#define RC_IS_ANSI 0
#endif

#if RC_IS_ANSI == 1
#define STR(str) u##str
#else
#define STR(str) L##str
#endif
#include <String/StringType.hpp>

#define THROW_INTERNAL_FILE_ERROR(msg) \
RC::File::Internal::StaticStorage::internal_error = true; \
Expand All @@ -24,38 +15,12 @@ construct a Targets object and supply your own devices.") \
}
//*/

#include <string>

namespace RC::File
{
#if RC_IS_ANSI == 1
using StringType = std::string;
using StringViewType = std::string_view;
using CharType = char;
using StreamType = std::ifstream;
using ToString = std::tostring;

constexpr auto ToString = [](auto&& numeric_value) constexpr -> decltype(auto) {
return std::to_string(std::forward<decltype(numeric_value)>(numeric_value));
};
#else
using StringType = std::wstring;
using StringViewType = std::wstring_view;
using CharType = wchar_t;
using StreamType = std::wifstream;

constexpr auto ToString = [](auto&& numeric_value) constexpr -> decltype(auto) {
return std::to_wstring(std::forward<decltype(numeric_value)>(numeric_value));
};
#endif
using StringType = RC::StringType;
using StringViewType = RC::StringViewType;
using CharType = RC::CharType;
using StreamIType = RC::StreamIType;
using StreamOType = RC::StreamOType;
using StreamType = StreamIType;
} // namespace RC::File

namespace RC
{
using StringType = File::StringType;
using StringViewType = File::StringViewType;
using CharType = File::CharType;
using StreamType = File::StreamType;

constexpr auto ToString = File::ToString;
} // namespace RC
4 changes: 2 additions & 2 deletions deps/first/File/src/FileType/WinFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,15 @@ namespace RC::File

auto WinFile::read_all() const -> StringType
{
StreamType stream{get_file_path(), std::ios::in | std::ios::binary};
StreamIType stream{get_file_path(), std::ios::in | std::ios::binary};
if (!stream)
{
THROW_INTERNAL_FILE_ERROR(fmt::format("[WinFile::read_all] Tried to read entire file but returned error {}", errno))
}
else
{
// Strip the BOM if it exists
File::StreamType::off_type start{};
File::StreamIType::off_type start{};
File::CharType bom[3]{};
stream.read(bom, 3);
if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF)
Expand Down
2 changes: 2 additions & 0 deletions deps/first/File/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ target(projectName)
set_languages("cxx20")
set_exceptions("cxx")
add_rules("ue4ss.dependency")

add_deps("String")

add_includedirs("include", { public = true })
add_headerfiles("include/**.hpp")
Expand Down
5 changes: 5 additions & 0 deletions deps/first/JSON/src/Number.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <JSON/Number.hpp>

#include <fmt/core.h>
#include <fmt/xchar.h>

namespace RC::JSON
{
Number::Number(uint32_t value)
Expand Down Expand Up @@ -47,6 +50,8 @@ namespace RC::JSON
(void)should_format;
(void)indent_level;

#define ToString(numeric_value) fmt::format(STR("{}"), numeric_value)

switch (m_stored_type)
{
case Type::UInt32:
Expand Down
27 changes: 27 additions & 0 deletions deps/first/String/include/String/StringType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <string>

// We will use this once we solve the circular dependency issue
//#include <Unreal/Core/HAL/Platform.hpp>

// This is a debug flag to force the use of u16string for testing purposes
// char16_t and wchar_t are two different types, so we need to force the use of one of them
// to ensure we have covered all the cases.
// #define FORCE_U16

namespace RC {

#ifdef FORCE_U16
using CharType = char16_t;
#define STR(str) u ## str
#else
using CharType = wchar_t;
#define STR(str) L ## str
#endif

using StringType = std::basic_string<CharType>;
using StringViewType = std::basic_string_view<CharType>;
using StreamIType = std::basic_ifstream<CharType>;
using StreamOType = std::basic_ofstream<CharType>;
} // namespace RC
10 changes: 10 additions & 0 deletions deps/first/String/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local projectName = "String"

target(projectName)
set_kind("headeronly")
set_languages("cxx20")
set_exceptions("cxx")
add_rules("ue4ss.dependency")

add_includedirs("include", { public = true })
add_headerfiles("include/**.hpp")
1 change: 1 addition & 0 deletions deps/first/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ includes("Profiler")
includes("ScopedTimer")
includes("SinglePassSigScanner")
includes("Unreal")
includes("String")

if is_config("patternsleuth", "local") then
-- The patternsleuth target is managed by the cargo.build rule.
Expand Down

0 comments on commit 7f5b638

Please sign in to comment.