Disabled unused variable and fallthrough warnings from std. Changed Store to be a template with tag that is used with a using declaration.

This commit is contained in:
2022-11-28 17:51:31 +11:00
parent e7c5ae0beb
commit b79cec3f8f
3 changed files with 30 additions and 20 deletions

View File

@@ -1,6 +1,9 @@
#ifndef ESX_READER_HPP #ifndef ESX_READER_HPP
#define ESX_READER_HPP #define ESX_READER_HPP
#pragma warning( push )
#pragma warning( disable : 5264 )
#pragma warning( disable : 5262 )
#include <memory> #include <memory>
#include <variant> #include <variant>
#include <array> #include <array>
@@ -9,6 +12,7 @@
#include <vector> #include <vector>
#include <type_traits> #include <type_traits>
#include <fstream> #include <fstream>
#pragma warning( pop )
#include "utility.hpp" #include "utility.hpp"
@@ -58,10 +62,10 @@ enum class RecordType {
// Aggregate types // Aggregate types
// //
struct FourCC : utility::Store<FourCC, uint32_t> { }; using FourCC = utility::Store<struct FourCCTag , uint32_t>;
struct FormID : utility::Store<FormID, uint32_t> { }; using FormID = utility::Store<struct FormIDTag , uint32_t>;
struct Timestamp : utility::Store<Timestamp, uint16_t> { }; using Timestamp = utility::Store<struct TimestampTag, uint16_t>;
struct VCInfo : utility::Store<VCInfo, uint16_t> { }; using VCInfo = utility::Store<struct VCInfoTag , uint16_t>;
struct Flag { struct Flag {
RecordType type; RecordType type;
@@ -85,14 +89,14 @@ struct GroupHeader {
int16_t y, x; int16_t y, x;
}; };
struct TopType : utility::Store<TopType, FourCC> { }; using TopType = utility::Store<struct TopTypeTag , FourCC >;
struct ParentWorld : utility::Store<ParentWorld, FormID> { }; using ParentWorld = utility::Store<struct ParentWorldTag , FormID >;
struct BlockNumber : utility::Store<BlockNumber, int32_t> { }; using BlockNumber = utility::Store<struct BlockNumberTag , int32_t>;
struct SubBlockNumber : utility::Store<SubBlockNumber, int32_t> { }; using SubBlockNumber = utility::Store<struct SubBlockNumberTag, int32_t>;
struct BlockCoord : utility::Store<BlockCoord, Coord> { }; using BlockCoord = utility::Store<struct BlockCoordTag , Coord >;
struct SubBlockCoord : utility::Store<SubBlockCoord, Coord> { }; using SubBlockCoord = utility::Store<struct SubBlockCoordTag , Coord >;
struct ParentCell : utility::Store<ParentCell, FormID> { }; using ParentCell = utility::Store<struct ParentCellTag , FormID >;
struct ParentDialogue : utility::Store<ParentDialogue, FormID> { }; using ParentDialogue = utility::Store<struct ParentDialogueTag, FormID >;
union GroupLabel { union GroupLabel {
TopType top_type; TopType top_type;
@@ -115,8 +119,8 @@ struct GroupHeader {
}; };
struct RecordHeader { struct RecordHeader {
struct Flags : utility::Store<Flags, uint32_t> { }; using Flags = utility::Store<struct FlagsTag , uint32_t>;
struct Version : utility::Store<Version, uint16_t> { }; using Version = utility::Store<struct VersionTag, uint16_t>;
FourCC type; FourCC type;
uint32_t size; uint32_t size;

View File

@@ -1,8 +1,12 @@
#include "esx_reader.hpp" #include "esx_reader.hpp"
#pragma warning( push )
#pragma warning( disable : 5264 )
#pragma warning( disable : 5262 )
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <filesystem> #include <filesystem>
#pragma warning( pop )
static constexpr auto esx_name = "Skyrim.esm"; static constexpr auto esx_name = "Skyrim.esm";

View File

@@ -1,9 +1,13 @@
#ifndef UTILITY_HPP #ifndef UTILITY_HPP
#define UTILITY_HPP #define UTILITY_HPP
#pragma warning( push )
#pragma warning( disable : 5264 )
#pragma warning( disable : 5262 )
#include <array> #include <array>
#include <optional> #include <optional>
#include <bit> #include <bit>
#pragma warning( pop )
namespace utility { namespace utility {
@@ -15,12 +19,10 @@ T::size_type index_of(const T &container, typename T::const_iterator &iter)
return static_cast<T::size_type>(distance); return static_cast<T::size_type>(distance);
} }
// This is a base class for a generic store for some value that can be represented by // Along the lines of https://github.com/joboccara/NamedType
// type Type but should not be type checked as type Type, but rather some more constrained class. // Usage: using StoreType = Store<struct StoreTypeTag, type>;
// CRTP is the derived class, and is used as a tag to prevent having Store as a base class to template <typename Tag, typename Type>
// multiple derived types. struct Store final {
template <typename CRTP, typename Type>
struct Store {
static_assert(std::is_trivial_v<Type>); static_assert(std::is_trivial_v<Type>);
Type value; Type value;
friend constexpr auto operator<=>(const Store &, const Store &) = default; friend constexpr auto operator<=>(const Store &, const Store &) = default;