fix issues on MSVC

This commit is contained in:
falsycat 2022-05-27 06:08:31 -07:00
parent 0da55c9edf
commit 29430a8a6c
7 changed files with 17 additions and 18 deletions

View File

@ -17,9 +17,11 @@ set(NF7_CXX_FLAGS
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Wno-overloaded-virtual>
$<$<CXX_COMPILER_ID:MSVC>:
/W4 /WX>
/W4 /WX /Zc:__cplusplus /external:anglebrackets /external:W0>
)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_subdirectory(thirdparty EXCLUDE_FROM_ALL)
add_subdirectory(tool)

View File

@ -8,8 +8,6 @@ namespace nf7 {
template <typename T>
class GenericTypeInfo : public File::TypeInfo {
public:
static constexpr bool kHasFactory = std::is_constructible<T, Env&>::value;
GenericTypeInfo(const std::string& name, std::unordered_set<std::string>&& v) noexcept :
TypeInfo(name, AddFlags(std::move(v))) {
}
@ -21,7 +19,7 @@ class GenericTypeInfo : public File::TypeInfo {
throw DeserializeException(std::string(name())+" deserialization failed");
}
std::unique_ptr<File> Create(Env& env) const noexcept override {
if constexpr (kHasFactory) {
if constexpr (std::is_constructible<T, Env&>::value) {
return std::make_unique<T>(env);
} else {
return nullptr;
@ -31,7 +29,7 @@ class GenericTypeInfo : public File::TypeInfo {
private:
static std::unordered_set<std::string> AddFlags(
std::unordered_set<std::string>&& flags) noexcept {
if (kHasFactory) flags.insert("File_Factory");
if (std::is_constructible<T, Env&>::value) flags.insert("File_Factory");
return flags;
}
};

View File

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <iostream>
#include <yas/serialize.hpp>
#include <yas/types/std/string.hpp>

View File

@ -136,6 +136,7 @@ class Logger final : public File,
return "ERRR";
default:
assert(false);
return "X(";
}
}
static std::string GetLocationString(const std::source_location loc) noexcept {

View File

@ -46,7 +46,7 @@ class Env final : public nf7::Env {
// deserialize
try {
if (!std::filesystem::exists(kFileName)) {
std::ofstream of(kFileName);
std::ofstream of(kFileName, std::ios::binary);
if (!of) throw Exception("failed to open native file: "s+kFileName);
of.write(kDefaultRoot, sizeof(kDefaultRoot));
of.flush();

15
nf7.hh
View File

@ -28,29 +28,26 @@ class Env;
using Serializer = yas::binary_oarchive<yas::file_ostream, yas::binary>;
using Deserializer = yas::binary_iarchive<yas::file_istream, yas::binary>;
class Exception {
class Exception : public std::nested_exception {
public:
Exception() = delete;
Exception(std::string_view msg,
std::exception_ptr reason = std::current_exception(),
std::source_location loc = std::source_location::current()) noexcept :
msg_(msg), reason_(reason), srcloc_(loc) {
Exception(std::string_view msg, std::source_location loc = std::source_location::current()) noexcept :
nested_exception(), msg_(msg), srcloc_(loc) {
}
virtual ~Exception() = default;
Exception(const Exception&) = delete;
Exception(Exception&&) = delete;
Exception(const Exception&) = default;
Exception(Exception&&) = default;
Exception& operator=(const Exception&) = delete;
Exception& operator=(Exception&&) = delete;
virtual void UpdatePanic() const noexcept;
const std::string& msg() const noexcept { return msg_; }
const std::exception_ptr reason() const noexcept { return reason_; }
const std::source_location& srcloc() const noexcept { return srcloc_; }
std::exception_ptr reason() const noexcept { return nested_ptr(); }
private:
const std::string msg_;
const std::exception_ptr reason_;
const std::source_location srcloc_;
};
class DeserializeException : public Exception {

View File

@ -1,7 +1,7 @@
include(FetchContent)
if (KINGTAKER_STATIC)
if (NF7_STATIC)
set(BUILD_SHARED_LIBS OFF)
else()
set(BUILD_SHARED_LIBS ON)
@ -18,7 +18,7 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(glew)
if (KINGTAKER_STATIC)
if (NF7_STATIC)
add_library(glew ALIAS libglew_static)
else()
add_library(glew ALIAS libglew_shared)
@ -52,7 +52,7 @@ FetchContent_Declare(
)
FetchContent_Populate(imgui)
add_library(imgui)
add_library(imgui STATIC)
target_sources(imgui
PRIVATE
"${imgui_SOURCE_DIR}/imgui.cpp"