Skip to content

Commit

Permalink
chore: improve const-correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirdEyeSqueegee committed Sep 28, 2023
1 parent 6cc521a commit 6f4d837
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 122 deletions.
10 changes: 5 additions & 5 deletions CommonLibSF/include/REL/ID.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace REL
return *this;
}

[[nodiscard]] void* data() noexcept { return _view; }
[[nodiscard]] void* data() const noexcept { return _view; }

bool open(stl::zwstring a_name, std::size_t a_size);

Expand Down Expand Up @@ -111,7 +111,7 @@ namespace REL
using reference = stream_type&;
using const_reference = const stream_type&;

istream_t(stl::zwstring a_filename, std::ios_base::openmode a_mode) :
istream_t(const stl::zwstring a_filename, const std::ios_base::openmode a_mode) :
_stream(a_filename.data(), a_mode)
{
stl_assert(_stream.is_open(),
Expand All @@ -120,7 +120,7 @@ namespace REL
_stream.exceptions(std::ios::badbit | std::ios::failbit | std::ios::eofbit);
}

void ignore(std::streamsize a_count)
void ignore(const std::streamsize a_count)
{
_stream.ignore(a_count);
}
Expand Down Expand Up @@ -244,11 +244,11 @@ namespace REL
public:
constexpr ID() noexcept = default;

explicit constexpr ID(std::uint64_t a_id) noexcept :
explicit constexpr ID(const std::uint64_t a_id) noexcept :
_id(a_id)
{}

constexpr ID& operator=(std::uint64_t a_id) noexcept
constexpr ID& operator=(const std::uint64_t a_id) noexcept
{
_id = a_id;
return *this;
Expand Down
8 changes: 4 additions & 4 deletions CommonLibSF/include/REL/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace REL

Segment() noexcept = default;

Segment(std::uintptr_t a_proxyBase, std::uintptr_t a_address, std::uintptr_t a_size) noexcept :
Segment(const std::uintptr_t a_proxyBase, const std::uintptr_t a_address, const std::uintptr_t a_size) noexcept :
_proxyBase(a_proxyBase), _address(a_address), _size(a_size)
{}

Expand Down Expand Up @@ -64,11 +64,11 @@ namespace REL
return std::bit_cast<T*>(base());
}

[[nodiscard]] constexpr auto segment(Segment::Name a_segment) noexcept { return _segments[a_segment]; }
[[nodiscard]] constexpr auto segment(const Segment::Name a_segment) const noexcept { return _segments[a_segment]; }

[[nodiscard]] constexpr auto version() noexcept { return _version; }
[[nodiscard]] constexpr auto version() const noexcept { return _version; }

[[nodiscard]] static Module& get(const std::uintptr_t a_address) noexcept;
[[nodiscard]] static Module& get(std::uintptr_t a_address) noexcept;

[[nodiscard]] static Module& get(std::string_view a_filePath = {}) noexcept;

Expand Down
18 changes: 9 additions & 9 deletions CommonLibSF/include/REL/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ namespace REL
{
namespace characters
{
[[nodiscard]] constexpr bool hexadecimal(char a_ch) noexcept
[[nodiscard]] constexpr bool hexadecimal(const char a_ch) noexcept
{
return ('0' <= a_ch && a_ch <= '9') || ('A' <= a_ch && a_ch <= 'F') ||
('a' <= a_ch && a_ch <= 'f');
}

[[nodiscard]] constexpr bool space(char a_ch) noexcept
[[nodiscard]] constexpr bool space(const char a_ch) noexcept
{
return a_ch == ' ';
}

[[nodiscard]] constexpr bool wildcard(char a_ch) noexcept
[[nodiscard]] constexpr bool wildcard(const char a_ch) noexcept
{
return a_ch == '?';
}
Expand All @@ -30,8 +30,8 @@ namespace REL
namespace detail
{
[[nodiscard]] consteval std::byte hexacharacters_to_hexadecimal(
char a_hi,
char a_lo) noexcept
const char a_hi,
const char a_lo) noexcept
{
constexpr auto lut = []() noexcept {
std::array<
Expand All @@ -42,7 +42,7 @@ namespace REL
const auto iterate =
[&](std::uint8_t a_iFirst,
unsigned char a_cFirst,
unsigned char a_cLast) noexcept {
const unsigned char a_cLast) noexcept {
for (; a_cFirst <= a_cLast; ++a_cFirst, ++a_iFirst) {
a[a_cFirst] = a_iFirst;
}
Expand All @@ -65,7 +65,7 @@ namespace REL
class Hexadecimal
{
public:
[[nodiscard]] static constexpr bool match(std::byte a_byte) noexcept
[[nodiscard]] static constexpr bool match(const std::byte a_byte) noexcept
{
constexpr auto expected = detail::hexacharacters_to_hexadecimal(
HI,
Expand Down Expand Up @@ -134,8 +134,8 @@ namespace REL
}

void match_or_fail(
std::uintptr_t a_address,
std::source_location a_loc = std::source_location::current())
const std::uintptr_t a_address,
const std::source_location& a_loc = std::source_location::current())
const noexcept
{
if (!this->match(a_address)) {
Expand Down
12 changes: 6 additions & 6 deletions CommonLibSF/include/REL/Relocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace REL
}
}

inline void safe_write(std::uintptr_t a_dst, const void* a_src, std::size_t a_count)
inline void safe_write(const std::uintptr_t a_dst, const void* a_src, const std::size_t a_count)
{
std::uint32_t old{ 0 };
auto success = WinAPI::VirtualProtect(reinterpret_cast<void*>(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old));
Expand All @@ -164,18 +164,18 @@ namespace REL
}

template <std::integral T>
void safe_write(std::uintptr_t a_dst, const T& a_data)
void safe_write(const std::uintptr_t a_dst, const T& a_data)
{
safe_write(a_dst, std::addressof(a_data), sizeof(T));
}

template <class T>
void safe_write(std::uintptr_t a_dst, std::span<T> a_data)
void safe_write(const std::uintptr_t a_dst, std::span<T> a_data)
{
safe_write(a_dst, a_data.data(), a_data.size_bytes());
}

inline void safe_fill(std::uintptr_t a_dst, std::uint8_t a_value, std::size_t a_count)
inline void safe_fill(const std::uintptr_t a_dst, const std::uint8_t a_value, const std::size_t a_count)
{
std::uint32_t old{ 0 };
auto success = WinAPI::VirtualProtect(reinterpret_cast<void*>(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old));
Expand Down Expand Up @@ -251,7 +251,7 @@ namespace REL
return invoke(get(), std::forward<Args>(a_args)...);
}

std::uintptr_t write_vfunc(std::size_t a_idx, std::uintptr_t a_newFunc)
std::uintptr_t write_vfunc(const std::size_t a_idx, const std::uintptr_t a_newFunc)
requires(std::same_as<value_type, std::uintptr_t>)
{
const auto addr = address() + (sizeof(void*) * a_idx);
Expand All @@ -261,7 +261,7 @@ namespace REL
}

template <class F>
std::uintptr_t write_vfunc(std::size_t a_idx, F a_newFunc)
std::uintptr_t write_vfunc(const std::size_t a_idx, F a_newFunc)
requires(std::same_as<value_type, std::uintptr_t>)
{
return write_vfunc(a_idx, stl::unrestricted_cast<std::uintptr_t>(a_newFunc));
Expand Down
16 changes: 8 additions & 8 deletions CommonLibSF/include/REL/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace REL

constexpr Version() noexcept = default;

explicit constexpr Version(std::array<value_type, 4> a_version) noexcept :
explicit constexpr Version(const std::array<value_type, 4> a_version) noexcept :
_impl(a_version) {}

constexpr Version(value_type a_v1, value_type a_v2 = 0, value_type a_v3 = 0, value_type a_v4 = 0) noexcept :
constexpr Version(const value_type a_v1, const value_type a_v2 = 0, const value_type a_v3 = 0, const value_type a_v4 = 0) noexcept :
_impl{ a_v1, a_v2, a_v3, a_v4 } {}

explicit constexpr Version(std::string_view a_version);

[[nodiscard]] constexpr reference operator[](std::size_t a_idx) noexcept { return _impl[a_idx]; }
[[nodiscard]] constexpr reference operator[](const std::size_t a_idx) noexcept { return _impl[a_idx]; }

[[nodiscard]] constexpr const_reference operator[](std::size_t a_idx) const noexcept { return _impl[a_idx]; }
[[nodiscard]] constexpr const_reference operator[](const std::size_t a_idx) const noexcept { return _impl[a_idx]; }

[[nodiscard]] constexpr decltype(auto) begin() const noexcept { return _impl.begin(); }

Expand Down Expand Up @@ -55,7 +55,7 @@ namespace REL
[[nodiscard]] constexpr value_type patch() const noexcept { return _impl[2]; }
[[nodiscard]] constexpr value_type build() const noexcept { return _impl[3]; }

[[nodiscard]] std::string string(std::string_view a_separator = "-"sv) const
[[nodiscard]] std::string string(const std::string_view a_separator = "-"sv) const
{
std::string result;
for (auto&& ver : _impl) {
Expand All @@ -66,7 +66,7 @@ namespace REL
return result;
}

[[nodiscard]] std::wstring wstring(std::wstring_view a_separator = L"-"sv) const
[[nodiscard]] std::wstring wstring(const std::wstring_view a_separator = L"-"sv) const
{
std::wstring result;
for (auto&& ver : _impl) {
Expand All @@ -77,7 +77,7 @@ namespace REL
return result;
}

[[nodiscard]] static constexpr Version unpack(std::uint32_t a_packedVersion) noexcept
[[nodiscard]] static constexpr Version unpack(const std::uint32_t a_packedVersion) noexcept
{
return REL::Version{
static_cast<value_type>((a_packedVersion >> 24) & 0x0FF),
Expand Down Expand Up @@ -139,7 +139,7 @@ namespace REL
return REL::Version(result);
}

[[nodiscard]] constexpr REL::Version operator""_v(const char* str, std::size_t len)
[[nodiscard]] constexpr REL::Version operator""_v(const char* str, const std::size_t len)
{
return Version(std::string_view(str, len));
}
Expand Down
2 changes: 1 addition & 1 deletion CommonLibSF/include/SFSE/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace SFSE
{
void Init(const LoadInterface* a_intfc, bool a_log = true) noexcept;
void RegisterForAPIInitEvent(std::function<void()> a_fn);
void RegisterForAPIInitEvent(const std::function<void()>& a_fn);

PluginHandle GetPluginHandle() noexcept;

Expand Down
2 changes: 1 addition & 1 deletion CommonLibSF/include/SFSE/IAT.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace SFSE
std::uintptr_t PatchIAT(std::uintptr_t a_newFunc, std::string_view a_dll, std::string_view a_function);

template <class F>
inline std::uintptr_t PatchIAT(F a_newFunc, std::string_view a_dll, std::string_view a_function)
inline std::uintptr_t PatchIAT(F a_newFunc, const std::string_view a_dll, const std::string_view a_function)
{
return PatchIAT(stl::unrestricted_cast<std::uintptr_t>(a_newFunc), a_dll, a_function);
}
Expand Down
16 changes: 8 additions & 8 deletions CommonLibSF/include/SFSE/Impl/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ namespace SFSE
inline constexpr auto ssizeof_v = ssizeof<T>::value;

template <class T, class U>
[[nodiscard]] auto adjust_pointer(U* a_ptr, std::ptrdiff_t a_adjust) noexcept
[[nodiscard]] auto adjust_pointer(U* a_ptr, const std::ptrdiff_t a_adjust) noexcept
{
auto addr = a_ptr ? reinterpret_cast<std::uintptr_t>(a_ptr) + a_adjust : 0;
if constexpr (std::is_const_v<U> && std::is_volatile_v<U>) {
Expand All @@ -580,7 +580,7 @@ namespace SFSE
}

template <class T>
void memzero(volatile T* a_ptr, std::size_t a_size = sizeof(T))
void memzero(volatile T* a_ptr, const std::size_t a_size = sizeof(T))
{
const auto begin = reinterpret_cast<volatile char*>(a_ptr);
constexpr char val{ 0 };
Expand All @@ -606,9 +606,9 @@ namespace SFSE
}
}

[[nodiscard]] inline auto utf8_to_utf16(std::string_view a_in) noexcept -> std::optional<std::wstring>
[[nodiscard]] inline auto utf8_to_utf16(const std::string_view a_in) noexcept -> std::optional<std::wstring>
{
const auto cvt = [&](wchar_t* a_dst, std::size_t a_length) {
const auto cvt = [&](wchar_t* a_dst, const std::size_t a_length) {
return WinAPI::MultiByteToWideChar(
WinAPI::CP_UTF8, 0, a_in.data(), static_cast<int>(a_in.length()), a_dst, static_cast<int>(a_length));
};
Expand All @@ -626,9 +626,9 @@ namespace SFSE
return out;
}

[[nodiscard]] inline auto utf16_to_utf8(std::wstring_view a_in) noexcept -> std::optional<std::string>
[[nodiscard]] inline auto utf16_to_utf8(const std::wstring_view a_in) noexcept -> std::optional<std::string>
{
const auto cvt = [&](char* a_dst, std::size_t a_length) {
const auto cvt = [&](char* a_dst, const std::size_t a_length) {
return WinAPI::WideCharToMultiByte(
WinAPI::CP_UTF8, 0, a_in.data(), static_cast<int>(a_in.length()), a_dst, static_cast<int>(a_length), nullptr, nullptr);
};
Expand All @@ -646,7 +646,7 @@ namespace SFSE
return out;
}

inline bool report_and_error(std::string_view a_msg, bool a_fail = true, std::source_location a_loc = std::source_location::current())
inline bool report_and_error(std::string_view a_msg, const bool a_fail = true, const std::source_location& a_loc = std::source_location::current())
{
const auto body = [&]() -> std::wstring {
const std::filesystem::path p = a_loc.file_name();
Expand Down Expand Up @@ -689,7 +689,7 @@ namespace SFSE
return true;
}

[[noreturn]] inline void report_and_fail(std::string_view a_msg, std::source_location a_loc = std::source_location::current())
[[noreturn]] inline void report_and_fail(const std::string_view a_msg, const std::source_location& a_loc = std::source_location::current())
{
report_and_error(a_msg, true, a_loc);
std::unreachable();
Expand Down
20 changes: 10 additions & 10 deletions CommonLibSF/include/SFSE/Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,27 @@ namespace SFSE
kVersion = 1
};

constexpr void PluginVersion(std::uint32_t a_version) noexcept { pluginVersion = a_version; }
constexpr void PluginVersion(const std::uint32_t a_version) noexcept { pluginVersion = a_version; }

constexpr void PluginVersion(REL::Version a_version) noexcept { pluginVersion = a_version.pack(); }
constexpr void PluginVersion(const REL::Version a_version) noexcept { pluginVersion = a_version.pack(); }

[[nodiscard]] constexpr std::uint32_t GetPluginVersion() const noexcept { return pluginVersion; }

constexpr void PluginName(std::string_view a_plugin) noexcept { SetCharBuffer(a_plugin, std::span{ pluginName }); }
constexpr void PluginName(const std::string_view a_plugin) noexcept { SetCharBuffer(a_plugin, std::span{ pluginName }); }

[[nodiscard]] constexpr std::string_view GetPluginName() const noexcept { return std::string_view{ pluginName }; }

constexpr void AuthorName(std::string_view a_name) noexcept { SetCharBuffer(a_name, std::span{ author }); }
constexpr void AuthorName(const std::string_view a_name) noexcept { SetCharBuffer(a_name, std::span{ author }); }

[[nodiscard]] constexpr std::string_view GetAuthorName() const noexcept { return std::string_view{ author }; }

constexpr void UsesSigScanning(bool a_value) noexcept { addressIndependence = SetOrClearBit(addressIndependence, 1 << 0, a_value); }
constexpr void UsesSigScanning(const bool a_value) noexcept { addressIndependence = SetOrClearBit(addressIndependence, 1 << 0, a_value); }

constexpr void UsesAddressLibrary(bool a_value) noexcept { addressIndependence = SetOrClearBit(addressIndependence, 1 << 1, a_value); }
constexpr void UsesAddressLibrary(const bool a_value) noexcept { addressIndependence = SetOrClearBit(addressIndependence, 1 << 1, a_value); }

constexpr void HasNoStructUse(bool a_value) noexcept { structureCompatibility = SetOrClearBit(structureCompatibility, 1 << 0, a_value); }
constexpr void HasNoStructUse(const bool a_value) noexcept { structureCompatibility = SetOrClearBit(structureCompatibility, 1 << 0, a_value); }

constexpr void IsLayoutDependent(bool a_value) noexcept { structureCompatibility = SetOrClearBit(structureCompatibility, 1 << 1, a_value); }
constexpr void IsLayoutDependent(const bool a_value) noexcept { structureCompatibility = SetOrClearBit(structureCompatibility, 1 << 1, a_value); }

constexpr void CompatibleVersions(std::initializer_list<REL::Version> a_versions) noexcept
{
Expand All @@ -158,7 +158,7 @@ namespace SFSE
std::ranges::transform(a_versions, std::begin(compatibleVersions), [](const REL::Version& a_version) noexcept { return a_version.pack(); });
}

constexpr void MinimumRequiredXSEVersion(REL::Version a_version) noexcept { xseMinimum = a_version.pack(); }
constexpr void MinimumRequiredXSEVersion(const REL::Version a_version) noexcept { xseMinimum = a_version.pack(); }

[[nodiscard]] static const PluginVersionData* GetSingleton() noexcept;

Expand All @@ -181,7 +181,7 @@ namespace SFSE
std::ranges::copy(a_src, a_dst.begin());
}

[[nodiscard]] static constexpr std::uint32_t SetOrClearBit(std::uint32_t a_data, std::uint32_t a_bit, bool a_set) noexcept
[[nodiscard]] static constexpr std::uint32_t SetOrClearBit(std::uint32_t a_data, const std::uint32_t a_bit, const bool a_set) noexcept
{
if (a_set)
a_data |= a_bit;
Expand Down
Loading

0 comments on commit 6f4d837

Please sign in to comment.