From 0bda289b1769429fa17e12862626502498440529 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Tue, 11 Aug 2020 14:51:17 -0700 Subject: [PATCH] move xlsxreader identity statics to dfhack lib --- library/CMakeLists.txt | 3 +++ library/PluginStatics.cpp | 9 +++++++++ library/include/PluginStatics.h | 34 +++++++++++++++++++++++++++++++++ plugins/xlsxreader.cpp | 28 +-------------------------- 4 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 library/PluginStatics.cpp create mode 100644 library/include/PluginStatics.h diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 2de293e15..b551c03f9 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -40,6 +40,8 @@ set(MAIN_HEADERS include/Module.h include/Pragma.h include/MemAccess.h + include/PluginManager.h + include/PluginStatics.h include/Signal.hpp include/TileTypes.h include/Types.h @@ -72,6 +74,7 @@ set(MAIN_SOURCES MiscUtils.cpp Types.cpp PluginManager.cpp + PluginStatics.cpp TileTypes.cpp VersionInfoFactory.cpp RemoteClient.cpp diff --git a/library/PluginStatics.cpp b/library/PluginStatics.cpp new file mode 100644 index 000000000..d5abdb840 --- /dev/null +++ b/library/PluginStatics.cpp @@ -0,0 +1,9 @@ +#include "PluginStatics.h" + +namespace DFHack { + +// xlsxreader statics +DFHACK_EXPORT xlsx_file_handle_identity xlsx_file_handle::_identity; +DFHACK_EXPORT xlsx_sheet_handle_identity xlsx_sheet_handle::_identity; + +} diff --git a/library/include/PluginStatics.h b/library/include/PluginStatics.h new file mode 100644 index 000000000..b5ca4b468 --- /dev/null +++ b/library/include/PluginStatics.h @@ -0,0 +1,34 @@ +#pragma once + +#include "DataIdentity.h" + +namespace DFHack { + +// xlsxreader definitions +struct xlsx_file_handle_identity : public compound_identity { + xlsx_file_handle_identity() + :compound_identity(0, nullptr, nullptr, "xlsx_file_handle") {}; + DFHack::identity_type type() override { return IDTYPE_OPAQUE; } +}; + +struct xlsx_sheet_handle_identity : public compound_identity { + xlsx_sheet_handle_identity() + :compound_identity(0, nullptr, nullptr, "xlsx_sheet_handle") {}; + DFHack::identity_type type() override { return IDTYPE_OPAQUE; } +}; + +struct xlsx_file_handle { + typedef struct xlsxio_read_struct* xlsxioreader; + const xlsxioreader handle; + xlsx_file_handle(xlsxioreader handle): handle(handle) {} + static xlsx_file_handle_identity _identity; +}; + +struct xlsx_sheet_handle { + typedef struct xlsxio_read_sheet_struct* xlsxioreadersheet; + const xlsxioreadersheet handle; + xlsx_sheet_handle(xlsxioreadersheet handle): handle(handle) {} + static xlsx_sheet_handle_identity _identity; +}; + +} diff --git a/plugins/xlsxreader.cpp b/plugins/xlsxreader.cpp index d8e6264f7..6f76f5e97 100644 --- a/plugins/xlsxreader.cpp +++ b/plugins/xlsxreader.cpp @@ -8,38 +8,12 @@ #include "DataFuncs.h" #include "LuaTools.h" #include "PluginManager.h" +#include "PluginStatics.h" using namespace DFHack; DFHACK_PLUGIN("xlsxreader"); -struct xlsx_file_handle_identity : public compound_identity { - xlsx_file_handle_identity() - :compound_identity(0, nullptr, nullptr, "xlsx_file_handle") {}; - DFHack::identity_type type() override { return IDTYPE_OPAQUE; } -}; - -struct xlsx_sheet_handle_identity : public compound_identity { - xlsx_sheet_handle_identity() - :compound_identity(0, nullptr, nullptr, "xlsx_sheet_handle") {}; - DFHack::identity_type type() override { return IDTYPE_OPAQUE; } -}; - -struct xlsx_file_handle { - const xlsxioreader handle; - xlsx_file_handle(xlsxioreader handle): handle(handle) {} - static xlsx_file_handle_identity _identity; -}; - -struct xlsx_sheet_handle { - const xlsxioreadersheet handle; - xlsx_sheet_handle(xlsxioreadersheet handle): handle(handle) {} - static xlsx_sheet_handle_identity _identity; -}; - -xlsx_file_handle_identity xlsx_file_handle::_identity; -xlsx_sheet_handle_identity xlsx_sheet_handle::_identity; - // returns NULL on error xlsx_file_handle* open_xlsx_file(std::string filename) { return new xlsx_file_handle(xlsxioread_open(filename.c_str()));