Fixed compiler warnings. Playing around with std::filesystem and std::fstream.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,6 +3,9 @@
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# Project specific
|
||||
*.esm
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="esx_reader.cpp" />
|
||||
<ClCompile Include="esx_reader_lut.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
<ClCompile Include="esx_reader_lut.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="esx_reader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="esx_reader.hpp">
|
||||
|
||||
4
Navmesher/esx_reader.cpp
Normal file
4
Navmesher/esx_reader.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "esx_reader.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string_view>
|
||||
#include <compare>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
@@ -62,11 +63,13 @@ using Node = std::variant<GroupNode, RecordNode>;
|
||||
// Aggregate types
|
||||
//
|
||||
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4514 )
|
||||
struct FourCC : utility::Store<uint32_t> {
|
||||
constexpr FourCC() noexcept = default;
|
||||
explicit constexpr FourCC(const char(&str)[5]) noexcept : Store{ utility::fourcc_lit_to_val(str) } { }
|
||||
};
|
||||
static_assert(std::is_trivial_v<FourCC>);
|
||||
#pragma warning( pop )
|
||||
|
||||
struct FormID : utility::Store<uint32_t> { };
|
||||
struct Timestamp : utility::Store<uint16_t> { };
|
||||
@@ -117,7 +120,6 @@ struct GroupHeader {
|
||||
VCInfo version_control_information;
|
||||
uint32_t unknown;
|
||||
};
|
||||
static_assert(sizeof(GroupHeader) == 24);
|
||||
|
||||
struct RecordHeader {
|
||||
struct Flags : utility::Store<uint32_t> { };
|
||||
@@ -132,7 +134,6 @@ struct RecordHeader {
|
||||
Version version;
|
||||
uint16_t unknown;
|
||||
};
|
||||
static_assert(sizeof(RecordHeader) == 24);
|
||||
|
||||
//
|
||||
// Classes
|
||||
|
||||
@@ -1,7 +1,33 @@
|
||||
#include <iostream>
|
||||
#include "esx_reader.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
static constexpr auto esm_name = "Skyrim.esm";
|
||||
|
||||
/* Propagated Exceptions:
|
||||
* - std::bad_alloc
|
||||
* - std::filesystem::filesystem_error
|
||||
* - std::ios_base::failure
|
||||
*/
|
||||
[[nodiscard]] static std::ifstream open_esm(void)
|
||||
{
|
||||
std::filesystem::path cwd = std::filesystem::current_path();
|
||||
auto esm_path = cwd / esm_name;
|
||||
auto esm_fs = std::ifstream(esm_path, std::ios::binary);
|
||||
if (esm_fs.fail())
|
||||
throw std::ios_base::failure("Could not open the esm file for reading.");
|
||||
return esm_fs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << esxr::flag_to_description({ esxr::RecordType::TES4, 0 }).value() << std::endl;
|
||||
auto esm_fs = open_esm();
|
||||
std::array<char, 4> fourcc{};
|
||||
esm_fs.read(fourcc.data(), static_cast<std::streamsize>(fourcc.size()));
|
||||
for (auto c : fourcc)
|
||||
std::cout << c;
|
||||
std::cout << '\n';
|
||||
return 0;
|
||||
}
|
||||
@@ -15,7 +15,7 @@ struct Store {
|
||||
friend constexpr auto operator<=>(const Store &, const Store &) noexcept = default;
|
||||
};
|
||||
|
||||
// Convert a fourcc literal (e.g. "LITR" to a uint32_t)
|
||||
// Convert a fourcc literal (e.g. "LITR") to a uint32_t
|
||||
constexpr uint32_t fourcc_lit_to_val(const char(&a)[5]) noexcept
|
||||
{
|
||||
char temp[4] = { a[0], a[1], a[2], a[3] };
|
||||
@@ -31,6 +31,7 @@ constexpr std::array<T, N> array_builtin_to_std(const T(&builtin)[N]) noexcept
|
||||
return array;
|
||||
}
|
||||
|
||||
// Convert a std::array of std::pairs to a std::pair of std::arrays
|
||||
template <typename First, typename Second, std::size_t N>
|
||||
constexpr std::pair<std::array<First, N>, std::array<Second, N>> map_to_soa(std::array<std::pair<First, Second>, N> map) noexcept
|
||||
{
|
||||
@@ -50,7 +51,7 @@ constexpr std::optional<Second> soa_first_to_second(const std::pair<std::array<F
|
||||
if (lhs == soa.first.cend())
|
||||
return {};
|
||||
auto index = std::distance(soa.first.cbegin(), lhs);
|
||||
return { soa.second[index] };
|
||||
return { soa.second[static_cast<size_t>(index)] };
|
||||
}
|
||||
|
||||
template <typename First, typename Second, std::size_t N>
|
||||
@@ -60,7 +61,7 @@ constexpr std::optional<First> soa_second_to_first(const std::pair<std::array<Fi
|
||||
if (lhs == soa.second.cend())
|
||||
return {};
|
||||
auto index = std::distance(soa.second.cbegin(), lhs);
|
||||
return { soa.first[index] };
|
||||
return { soa.first[static_cast<size_t>(index)] };
|
||||
}
|
||||
|
||||
// Used to inspect type sizes and values at compile time. Example:
|
||||
|
||||
Reference in New Issue
Block a user