clean up xlnt_config.hpp and fix visual studio warnings

This commit is contained in:
Thomas Fussell 2016-06-12 01:07:07 +08:00
parent 8a22245e25
commit 8361bcad74
4 changed files with 41 additions and 22 deletions

View File

@ -68,7 +68,7 @@ SET(PUGIXML ../third-party/pugixml/src/pugixml.hpp ../third-party/pugixml/src/pu
if(SHARED)
add_library(xlnt.shared SHARED ${HEADERS} ${SOURCES} ${MINIZ} ${PUGIXML})
add_definitions(-DXLNT_SHARED)
target_compile_definitions(xlnt.shared PRIVATE XLNT_SHARED=1)
if(MSVC)
target_compile_definitions(xlnt.shared PRIVATE XLNT_EXPORT=1)
set_target_properties(xlnt.shared PROPERTIES COMPILE_FLAGS "/wd\"4251\" /wd\"4275\"")
@ -102,9 +102,7 @@ endif()
if(STATIC)
add_library(xlnt.static STATIC ${HEADERS} ${SOURCES} ${MINIZ} ${PUGIXML})
if(MSVC)
target_compile_definitions(xlnt.static PRIVATE XLNT_API=)
endif()
target_compile_definitions(xlnt.static PRIVATE XLNT_STATIC=1)
install(TARGETS xlnt.static
LIBRARY DESTINATION ${LIB_DEST_DIR}
ARCHIVE DESTINATION ${LIB_DEST_DIR}

View File

@ -54,10 +54,9 @@ enum class limit_style
/// </summary>
const limit_style LimitStyle = limit_style::openpyxl;
// If no API is defined, assume default
#ifndef XLNT_API
#ifdef _MSC_VER
#ifdef _DLL
#if defined(_DLL) && defined(_MSC_VER)
#ifdef XLNT_EXPORT
#define XLNT_API __declspec(dllexport)
#else
#define XLNT_API __declspec(dllimport)

View File

@ -27,6 +27,19 @@
#include <xlnt/serialization/xml_document.hpp>
#include <xlnt/serialization/xml_node.hpp>
namespace {
std::size_t string_to_size_t(const std::string &s)
{
#if ULLONG_MAX == SIZE_MAX
return std::stoull(s);
#else
return std::stoul(s);
#endif
} // namespace
}
namespace xlnt {
xml_document shared_strings_serializer::write_shared_strings(const std::vector<text> &strings)
@ -102,7 +115,7 @@ bool shared_strings_serializer::read_shared_strings(const xml_document &xml, std
if (root_node.has_attribute("uniqueCount"))
{
unique_count = std::stoull(root_node.get_attribute("uniqueCount"));
unique_count = string_to_size_t(root_node.get_attribute("uniqueCount"));
}
for (const auto &string_item_node : root_node.get_children())
@ -136,7 +149,7 @@ bool shared_strings_serializer::read_shared_strings(const xml_document &xml, std
if (run_properties_node.has_child("sz"))
{
run.set_size(std::stoull(run_properties_node.get_child("sz").get_attribute("val")));
run.set_size(string_to_size_t(run_properties_node.get_child("sz").get_attribute("val")));
}
if (run_properties_node.has_child("rFont"))
@ -151,7 +164,7 @@ bool shared_strings_serializer::read_shared_strings(const xml_document &xml, std
if (run_properties_node.has_child("family"))
{
run.set_family(std::stoull(run_properties_node.get_child("family").get_attribute("val")));
run.set_family(string_to_size_t(run_properties_node.get_child("family").get_attribute("val")));
}
if (run_properties_node.has_child("scheme"))

View File

@ -75,6 +75,15 @@ bool is_true(const std::string &bool_string)
return bool_string == "1" || bool_string == "true";
}
std::size_t string_to_size_t(const std::string &s)
{
#if ULLONG_MAX == SIZE_MAX
return std::stoull(s);
#else
return std::stoul(s);
#endif
}
// Enumerations from string
xlnt::protection::type protection_type_from_string(const std::string &type_string)
@ -316,7 +325,7 @@ void read_number_formats(const xlnt::xml_node &number_formats_node, std::vector<
xlnt::number_format nf;
nf.set_format_string(format_string);
nf.set_id(std::stoull(num_fmt_node.get_attribute("numFmtId")));
nf.set_id(string_to_size_t(num_fmt_node.get_attribute("numFmtId")));
number_formats.push_back(nf);
}
@ -330,15 +339,15 @@ xlnt::color read_color(const xlnt::xml_node &color_node)
}
else if (color_node.has_attribute("theme"))
{
return xlnt::color(xlnt::color::type::theme, std::stoull(color_node.get_attribute("theme")));
return xlnt::color(xlnt::color::type::theme, string_to_size_t(color_node.get_attribute("theme")));
}
else if (color_node.has_attribute("indexed"))
{
return xlnt::color(xlnt::color::type::indexed, std::stoull(color_node.get_attribute("indexed")));
return xlnt::color(xlnt::color::type::indexed, string_to_size_t(color_node.get_attribute("indexed")));
}
else if (color_node.has_attribute("auto"))
{
return xlnt::color(xlnt::color::type::auto_, std::stoull(color_node.get_attribute("auto")));
return xlnt::color(xlnt::color::type::auto_, string_to_size_t(color_node.get_attribute("auto")));
}
throw std::runtime_error("bad color");
@ -348,7 +357,7 @@ xlnt::font read_font(const xlnt::xml_node &font_node)
{
xlnt::font new_font;
new_font.set_size(std::stoull(font_node.get_child("sz").get_attribute("val")));
new_font.set_size(string_to_size_t(font_node.get_child("sz").get_attribute("val")));
new_font.set_name(font_node.get_child("name").get_attribute("val"));
if (font_node.has_child("color"))
@ -358,7 +367,7 @@ xlnt::font read_font(const xlnt::xml_node &font_node)
if (font_node.has_child("family"))
{
new_font.set_family(std::stoull(font_node.get_child("family").get_attribute("val")));
new_font.set_family(string_to_size_t(font_node.get_child("family").get_attribute("val")));
}
if (font_node.has_child("scheme"))
@ -574,22 +583,22 @@ bool read_base_format(const xlnt::xml_node &format_node, const xlnt::detail::sty
}
// Border
auto border_index = format_node.has_attribute("borderId") ? std::stoull(format_node.get_attribute("borderId")) : 0;
auto border_index = format_node.has_attribute("borderId") ? string_to_size_t(format_node.get_attribute("borderId")) : 0;
f.set_border(stylesheet.borders.at(border_index));
f.border_applied(is_true(format_node.get_attribute("applyBorder")));
// Fill
auto fill_index = format_node.has_attribute("fillId") ? std::stoull(format_node.get_attribute("fillId")) : 0;
auto fill_index = format_node.has_attribute("fillId") ? string_to_size_t(format_node.get_attribute("fillId")) : 0;
f.set_fill(stylesheet.fills.at(fill_index));
f.fill_applied(is_true(format_node.get_attribute("applyFill")));
// Font
auto font_index = format_node.has_attribute("fontId") ? std::stoull(format_node.get_attribute("fontId")) : 0;
auto font_index = format_node.has_attribute("fontId") ? string_to_size_t(format_node.get_attribute("fontId")) : 0;
f.set_font(stylesheet.fonts.at(font_index));
f.font_applied(is_true(format_node.get_attribute("applyFont")));
// Number Format
auto number_format_id = std::stoull(format_node.get_attribute("numFmtId"));
auto number_format_id = string_to_size_t(format_node.get_attribute("numFmtId"));
bool builtin_format = true;
@ -639,7 +648,7 @@ void read_formats(const xlnt::xml_node &formats_node, const xlnt::detail::styles
// TODO do all formats have xfId?
if(format_node.has_attribute("xfId"))
{
auto style_index = std::stoull(format_node.get_attribute("xfId"));
auto style_index = string_to_size_t(format_node.get_attribute("xfId"));
auto style_name = stylesheet.style_name_map.at(style_index);
format_styles.push_back(style_name);
}
@ -660,7 +669,7 @@ xlnt::style read_style(const xlnt::xml_node &style_node, const xlnt::xml_node &s
s.set_name(style_node.get_attribute("name"));
s.set_hidden(style_node.has_attribute("hidden") && is_true(style_node.get_attribute("hidden")));
s.set_builtin_id(std::stoull(style_node.get_attribute("builtinId")));
s.set_builtin_id(string_to_size_t(style_node.get_attribute("builtinId")));
return s;
}