Merge 4f780ead9f into 0e6e28d1a3
This commit is contained in:
commit
4d78c0bef2
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
build/
|
||||
cmake-build-*/
|
||||
/tags
|
||||
/bazel-*
|
||||
.idea
|
||||
|
||||
227
CMakeLists.txt
227
CMakeLists.txt
@ -3,16 +3,16 @@ cmake_minimum_required(VERSION 3.4)
|
||||
|
||||
# enable MSVC_RUNTIME_LIBRARY target property
|
||||
# see https://cmake.org/cmake/help/latest/policy/CMP0091.html
|
||||
if(POLICY CMP0091)
|
||||
cmake_policy(SET CMP0091 NEW)
|
||||
endif()
|
||||
if (POLICY CMP0091)
|
||||
cmake_policy(SET CMP0091 NEW)
|
||||
endif ()
|
||||
|
||||
project(YAML_CPP VERSION 0.7.0 LANGUAGES CXX)
|
||||
|
||||
set(YAML_CPP_MAIN_PROJECT OFF)
|
||||
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
|
||||
set(YAML_CPP_MAIN_PROJECT ON)
|
||||
endif()
|
||||
if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
|
||||
set(YAML_CPP_MAIN_PROJECT ON)
|
||||
endif ()
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(CMakeDependentOption)
|
||||
@ -20,29 +20,29 @@ include(CheckCXXCompilerFlag)
|
||||
include(GNUInstallDirs)
|
||||
include(CTest)
|
||||
|
||||
option(YAML_CPP_BUILD_CONTRIB "Enable yaml-cpp contrib in library" ON)
|
||||
option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON)
|
||||
option(YAML_CPP_BUILD_CONTRIB "Enable yaml-cpp contrib in library" OFF)
|
||||
option(YAML_CPP_BUILD_TOOLS "Enable parse tools" OFF)
|
||||
option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIBS})
|
||||
option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ${YAML_CPP_MAIN_PROJECT})
|
||||
option(YAML_CPP_FORMAT_SOURCE "Format source" ON)
|
||||
cmake_dependent_option(YAML_CPP_BUILD_TESTS
|
||||
"Enable yaml-cpp tests" OFF
|
||||
"BUILD_TESTING;YAML_CPP_MAIN_PROJECT" OFF)
|
||||
"Enable yaml-cpp tests" OFF
|
||||
"BUILD_TESTING;YAML_CPP_MAIN_PROJECT" OFF)
|
||||
cmake_dependent_option(YAML_MSVC_SHARED_RT
|
||||
"MSVC: Build yaml-cpp with shared runtime libs (/MD)" ON
|
||||
"CMAKE_SYSTEM_NAME MATCHES Windows" OFF)
|
||||
|
||||
"MSVC: Build yaml-cpp with shared runtime libs (/MD)" ON
|
||||
"CMAKE_SYSTEM_NAME MATCHES Windows" OFF)
|
||||
|
||||
if (YAML_CPP_FORMAT_SOURCE)
|
||||
find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if (YAML_BUILD_SHARED_LIBS)
|
||||
set(yaml-cpp-type SHARED)
|
||||
set(yaml-cpp-label-postfix "shared")
|
||||
else()
|
||||
set(yaml-cpp-type STATIC)
|
||||
set(yaml-cpp-label-postfix "static")
|
||||
endif()
|
||||
set(yaml-cpp-type SHARED)
|
||||
set(yaml-cpp-label-postfix "shared")
|
||||
else ()
|
||||
set(yaml-cpp-type STATIC)
|
||||
set(yaml-cpp-label-postfix "static")
|
||||
endif ()
|
||||
|
||||
set(build-shared $<BOOL:${YAML_BUILD_SHARED_LIBS}>)
|
||||
set(build-windows-dll $<AND:$<BOOL:${CMAKE_HOST_WIN32}>,${build-shared}>)
|
||||
@ -50,16 +50,16 @@ set(not-msvc $<NOT:$<CXX_COMPILER_ID:MSVC>>)
|
||||
set(msvc-shared_rt $<BOOL:${YAML_MSVC_SHARED_RT}>)
|
||||
|
||||
if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY
|
||||
MultiThreaded$<$<CONFIG:Debug>:Debug>$<${msvc-shared_rt}:DLL>)
|
||||
endif()
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY
|
||||
MultiThreaded$<$<CONFIG:Debug>:Debug>$<${msvc-shared_rt}:DLL>)
|
||||
endif ()
|
||||
|
||||
set(contrib-pattern "src/contrib/*.cpp")
|
||||
set(src-pattern "src/*.cpp")
|
||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||
list(INSERT contrib-pattern 0 CONFIGURE_DEPENDS)
|
||||
list(INSERT src-pattern 0 CONFIGURE_DEPENDS)
|
||||
endif()
|
||||
list(INSERT contrib-pattern 0 CONFIGURE_DEPENDS)
|
||||
list(INSERT src-pattern 0 CONFIGURE_DEPENDS)
|
||||
endif ()
|
||||
|
||||
file(GLOB yaml-cpp-contrib-sources ${contrib-pattern})
|
||||
file(GLOB yaml-cpp-sources ${src-pattern})
|
||||
@ -78,129 +78,124 @@ add_library(yaml-cpp ${yaml-cpp-type} "")
|
||||
add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp)
|
||||
|
||||
set_property(TARGET yaml-cpp
|
||||
PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY})
|
||||
PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY})
|
||||
set_property(TARGET yaml-cpp
|
||||
PROPERTY
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
PROPERTY
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if (NOT YAML_BUILD_SHARED_LIBS)
|
||||
set_property(TARGET yaml-cpp PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
set_property(TARGET yaml-cpp PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif ()
|
||||
|
||||
target_include_directories(yaml-cpp
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
||||
|
||||
if (NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
set_target_properties(yaml-cpp
|
||||
PROPERTIES
|
||||
CXX_STANDARD 11)
|
||||
endif()
|
||||
set_target_properties(yaml-cpp
|
||||
PROPERTIES
|
||||
CXX_STANDARD 11)
|
||||
endif ()
|
||||
|
||||
if(YAML_CPP_MAIN_PROJECT)
|
||||
target_compile_options(yaml-cpp
|
||||
PRIVATE
|
||||
$<${not-msvc}:-Wall -Wextra -Wshadow -Weffc++ -Wno-long-long>
|
||||
$<${not-msvc}:-pedantic -pedantic-errors>)
|
||||
endif()
|
||||
if (YAML_CPP_MAIN_PROJECT)
|
||||
target_compile_options(yaml-cpp
|
||||
PRIVATE
|
||||
$<${not-msvc}:-Wall -Wextra -Wshadow -Weffc++ -Wno-long-long>
|
||||
$<${not-msvc}:-pedantic -pedantic-errors>)
|
||||
endif ()
|
||||
|
||||
target_compile_options(yaml-cpp
|
||||
PRIVATE
|
||||
$<$<AND:${backport-msvc-runtime},${msvc-rt-mtd-static}>:-MTd>
|
||||
$<$<AND:${backport-msvc-runtime},${msvc-rt-mt-static}>:-MT>
|
||||
$<$<AND:${backport-msvc-runtime},${msvc-rt-mtd-dll}>:-MDd>
|
||||
$<$<AND:${backport-msvc-runtime},${msvc-rt-mt-dll}>:-MD>
|
||||
PRIVATE
|
||||
$<$<AND:${backport-msvc-runtime},${msvc-rt-mtd-static}>:-MTd>
|
||||
$<$<AND:${backport-msvc-runtime},${msvc-rt-mt-static}>:-MT>
|
||||
$<$<AND:${backport-msvc-runtime},${msvc-rt-mtd-dll}>:-MDd>
|
||||
$<$<AND:${backport-msvc-runtime},${msvc-rt-mt-dll}>:-MD>
|
||||
|
||||
# /wd4127 = disable warning C4127 "conditional expression is constant"
|
||||
# http://msdn.microsoft.com/en-us/library/6t66728h.aspx
|
||||
# /wd4355 = disable warning C4355 "'this' : used in base member initializer list
|
||||
# http://msdn.microsoft.com/en-us/library/3c594ae3.aspx
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/W3 /wd4127 /wd4355>)
|
||||
# /wd4127 = disable warning C4127 "conditional expression is constant"
|
||||
# http://msdn.microsoft.com/en-us/library/6t66728h.aspx
|
||||
# /wd4355 = disable warning C4355 "'this' : used in base member initializer list
|
||||
# http://msdn.microsoft.com/en-us/library/3c594ae3.aspx
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/W3 /wd4127 /wd4355>)
|
||||
|
||||
target_compile_definitions(yaml-cpp
|
||||
PUBLIC
|
||||
$<$<NOT:$<BOOL:${YAML_BUILD_SHARED_LIBS}>>:YAML_CPP_STATIC_DEFINE>
|
||||
PRIVATE
|
||||
$<${build-windows-dll}:${PROJECT_NAME}_DLL>
|
||||
$<$<NOT:$<BOOL:${YAML_CPP_BUILD_CONTRIB}>>:YAML_CPP_NO_CONTRIB>)
|
||||
PUBLIC
|
||||
$<$<NOT:$<BOOL:${YAML_BUILD_SHARED_LIBS}>>:YAML_CPP_STATIC_DEFINE>
|
||||
PRIVATE
|
||||
$<${build-windows-dll}:${PROJECT_NAME}_DLL>
|
||||
$<$<NOT:$<BOOL:${YAML_CPP_BUILD_CONTRIB}>>:YAML_CPP_NO_CONTRIB>)
|
||||
|
||||
target_sources(yaml-cpp
|
||||
PRIVATE
|
||||
$<$<BOOL:${YAML_CPP_BUILD_CONTRIB}>:${yaml-cpp-contrib-sources}>
|
||||
${yaml-cpp-sources})
|
||||
|
||||
if (NOT DEFINED CMAKE_DEBUG_POSTFIX)
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
endif()
|
||||
PRIVATE
|
||||
$<$<BOOL:${YAML_CPP_BUILD_CONTRIB}>:${yaml-cpp-contrib-sources}>
|
||||
${yaml-cpp-sources})
|
||||
|
||||
set_target_properties(yaml-cpp PROPERTIES
|
||||
VERSION "${PROJECT_VERSION}"
|
||||
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
|
||||
PROJECT_LABEL "yaml-cpp ${yaml-cpp-label-postfix}"
|
||||
DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
|
||||
VERSION "${PROJECT_VERSION}"
|
||||
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
|
||||
PROJECT_LABEL "yaml-cpp ${yaml-cpp-label-postfix}")
|
||||
|
||||
set(CONFIG_EXPORT_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/yaml-cpp")
|
||||
set(EXPORT_TARGETS yaml-cpp)
|
||||
configure_package_config_file(
|
||||
"${PROJECT_SOURCE_DIR}/yaml-cpp-config.cmake.in"
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake"
|
||||
INSTALL_DESTINATION "${CONFIG_EXPORT_DIR}"
|
||||
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR CONFIG_EXPORT_DIR YAML_BUILD_SHARED_LIBS)
|
||||
"${PROJECT_SOURCE_DIR}/yaml-cpp-config.cmake.in"
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake"
|
||||
INSTALL_DESTINATION "${CONFIG_EXPORT_DIR}"
|
||||
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR CONFIG_EXPORT_DIR YAML_BUILD_SHARED_LIBS)
|
||||
unset(EXPORT_TARGETS)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
|
||||
configure_file(yaml-cpp.pc.in yaml-cpp.pc @ONLY)
|
||||
|
||||
if (YAML_CPP_INSTALL)
|
||||
install(TARGETS yaml-cpp
|
||||
EXPORT yaml-cpp-targets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
install(EXPORT yaml-cpp-targets
|
||||
DESTINATION "${CONFIG_EXPORT_DIR}")
|
||||
install(FILES
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake"
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
|
||||
DESTINATION "${CONFIG_EXPORT_DIR}")
|
||||
install(FILES "${PROJECT_BINARY_DIR}/yaml-cpp.pc"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
endif()
|
||||
install(TARGETS yaml-cpp
|
||||
EXPORT yaml-cpp-targets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
install(EXPORT yaml-cpp-targets
|
||||
DESTINATION "${CONFIG_EXPORT_DIR}")
|
||||
install(FILES
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake"
|
||||
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
|
||||
DESTINATION "${CONFIG_EXPORT_DIR}")
|
||||
install(FILES "${PROJECT_BINARY_DIR}/yaml-cpp.pc"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
endif ()
|
||||
unset(CONFIG_EXPORT_DIR)
|
||||
|
||||
if(YAML_CPP_BUILD_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
if (YAML_CPP_BUILD_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif ()
|
||||
|
||||
if(YAML_CPP_BUILD_TOOLS)
|
||||
add_subdirectory(util)
|
||||
endif()
|
||||
if (YAML_CPP_BUILD_TOOLS)
|
||||
add_subdirectory(util)
|
||||
endif ()
|
||||
|
||||
if (YAML_CPP_FORMAT_SOURCE AND YAML_CPP_CLANG_FORMAT_EXE)
|
||||
add_custom_target(format
|
||||
COMMAND clang-format --style=file -i $<TARGET_PROPERTY:yaml-cpp,SOURCES>
|
||||
COMMAND_EXPAND_LISTS
|
||||
COMMENT "Running clang-format"
|
||||
VERBATIM)
|
||||
endif()
|
||||
add_custom_target(format
|
||||
COMMAND clang-format --style=file -i $<TARGET_PROPERTY:yaml-cpp,SOURCES>
|
||||
COMMAND_EXPAND_LISTS
|
||||
COMMENT "Running clang-format"
|
||||
VERBATIM)
|
||||
endif ()
|
||||
|
||||
# uninstall target
|
||||
if(NOT TARGET uninstall)
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
||||
IMMEDIATE @ONLY)
|
||||
if (NOT TARGET uninstall)
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
||||
IMMEDIATE @ONLY)
|
||||
|
||||
add_custom_target(uninstall
|
||||
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|
||||
endif()
|
||||
add_custom_target(uninstall
|
||||
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|
||||
endif ()
|
||||
|
||||
@ -205,7 +205,7 @@ void Emitter::EmitBeginSeq() {
|
||||
void Emitter::EmitEndSeq() {
|
||||
if (!good())
|
||||
return;
|
||||
FlowType::value originalType = m_pState->CurGroupFlowType();
|
||||
FlowType originalType = m_pState->CurGroupFlowType();
|
||||
|
||||
if (m_pState->CurGroupChildCount() == 0)
|
||||
m_pState->ForceFlow();
|
||||
@ -240,7 +240,7 @@ void Emitter::EmitBeginMap() {
|
||||
void Emitter::EmitEndMap() {
|
||||
if (!good())
|
||||
return;
|
||||
FlowType::value originalType = m_pState->CurGroupFlowType();
|
||||
FlowType originalType = m_pState->CurGroupFlowType();
|
||||
|
||||
if (m_pState->CurGroupChildCount() == 0)
|
||||
m_pState->ForceFlow();
|
||||
@ -703,7 +703,7 @@ void Emitter::StartedScalar() { m_pState->StartedScalar(); }
|
||||
// *******************************************************************************************
|
||||
// overloads of Write
|
||||
|
||||
StringEscaping::value GetStringEscapingStyle(const EMITTER_MANIP emitterManip) {
|
||||
StringEscaping GetStringEscapingStyle(const EMITTER_MANIP emitterManip) {
|
||||
switch (emitterManip) {
|
||||
case EscapeNonAscii:
|
||||
return StringEscaping::NonAscii;
|
||||
@ -719,9 +719,9 @@ Emitter& Emitter::Write(const std::string& str) {
|
||||
if (!good())
|
||||
return *this;
|
||||
|
||||
StringEscaping::value stringEscaping = GetStringEscapingStyle(m_pState->GetOutputCharset());
|
||||
StringEscaping stringEscaping = GetStringEscapingStyle(m_pState->GetOutputCharset());
|
||||
|
||||
const StringFormat::value strFormat =
|
||||
const StringFormat strFormat =
|
||||
Utils::ComputeStringFormat(str, m_pState->GetStringFormat(),
|
||||
m_pState->CurGroupFlowType(), stringEscaping == StringEscaping::NonAscii);
|
||||
|
||||
|
||||
@ -96,7 +96,7 @@ void EmitterState::StartedNode() {
|
||||
}
|
||||
|
||||
EmitterNodeType::value EmitterState::NextGroupType(
|
||||
GroupType::value type) const {
|
||||
GroupType type) const {
|
||||
if (type == GroupType::Seq) {
|
||||
if (GetFlowType(type) == Block)
|
||||
return EmitterNodeType::BlockSeq;
|
||||
@ -129,7 +129,7 @@ void EmitterState::StartedScalar() {
|
||||
ClearModifiedSettings();
|
||||
}
|
||||
|
||||
void EmitterState::StartedGroup(GroupType::value type) {
|
||||
void EmitterState::StartedGroup(GroupType type) {
|
||||
StartedNode();
|
||||
|
||||
const std::size_t lastGroupIndent =
|
||||
@ -156,7 +156,7 @@ void EmitterState::StartedGroup(GroupType::value type) {
|
||||
m_groups.push_back(std::move(pGroup));
|
||||
}
|
||||
|
||||
void EmitterState::EndedGroup(GroupType::value type) {
|
||||
void EmitterState::EndedGroup(GroupType type) {
|
||||
if (m_groups.empty()) {
|
||||
if (type == GroupType::Seq) {
|
||||
return SetError(ErrorMsg::UNEXPECTED_END_SEQ);
|
||||
@ -203,11 +203,11 @@ EmitterNodeType::value EmitterState::CurGroupNodeType() const {
|
||||
return m_groups.back()->NodeType();
|
||||
}
|
||||
|
||||
GroupType::value EmitterState::CurGroupType() const {
|
||||
GroupType EmitterState::CurGroupType() const {
|
||||
return m_groups.empty() ? GroupType::NoType : m_groups.back()->type;
|
||||
}
|
||||
|
||||
FlowType::value EmitterState::CurGroupFlowType() const {
|
||||
FlowType EmitterState::CurGroupFlowType() const {
|
||||
return m_groups.empty() ? FlowType::NoType : m_groups.back()->flowType;
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ void EmitterState::RestoreGlobalModifiedSettings() {
|
||||
}
|
||||
|
||||
bool EmitterState::SetOutputCharset(EMITTER_MANIP value,
|
||||
FmtScope::value scope) {
|
||||
FmtScope scope) {
|
||||
switch (value) {
|
||||
case EmitNonAscii:
|
||||
case EscapeNonAscii:
|
||||
@ -250,7 +250,7 @@ bool EmitterState::SetOutputCharset(EMITTER_MANIP value,
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FmtScope scope) {
|
||||
switch (value) {
|
||||
case Auto:
|
||||
case SingleQuoted:
|
||||
@ -263,7 +263,7 @@ bool EmitterState::SetStringFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FmtScope scope) {
|
||||
switch (value) {
|
||||
case OnOffBool:
|
||||
case TrueFalseBool:
|
||||
@ -276,7 +276,7 @@ bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
}
|
||||
|
||||
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value,
|
||||
FmtScope::value scope) {
|
||||
FmtScope scope) {
|
||||
switch (value) {
|
||||
case LongBool:
|
||||
case ShortBool:
|
||||
@ -288,7 +288,7 @@ bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value,
|
||||
}
|
||||
|
||||
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value,
|
||||
FmtScope::value scope) {
|
||||
FmtScope scope) {
|
||||
switch (value) {
|
||||
case UpperCase:
|
||||
case LowerCase:
|
||||
@ -300,7 +300,7 @@ bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value,
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetNullFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
bool EmitterState::SetNullFormat(EMITTER_MANIP value, FmtScope scope) {
|
||||
switch (value) {
|
||||
case LowerNull:
|
||||
case UpperNull:
|
||||
@ -313,7 +313,7 @@ bool EmitterState::SetNullFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope scope) {
|
||||
switch (value) {
|
||||
case Dec:
|
||||
case Hex:
|
||||
@ -325,7 +325,7 @@ bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetIndent(std::size_t value, FmtScope::value scope) {
|
||||
bool EmitterState::SetIndent(std::size_t value, FmtScope scope) {
|
||||
if (value <= 1)
|
||||
return false;
|
||||
|
||||
@ -334,7 +334,7 @@ bool EmitterState::SetIndent(std::size_t value, FmtScope::value scope) {
|
||||
}
|
||||
|
||||
bool EmitterState::SetPreCommentIndent(std::size_t value,
|
||||
FmtScope::value scope) {
|
||||
FmtScope scope) {
|
||||
if (value == 0)
|
||||
return false;
|
||||
|
||||
@ -343,7 +343,7 @@ bool EmitterState::SetPreCommentIndent(std::size_t value,
|
||||
}
|
||||
|
||||
bool EmitterState::SetPostCommentIndent(std::size_t value,
|
||||
FmtScope::value scope) {
|
||||
FmtScope scope) {
|
||||
if (value == 0)
|
||||
return false;
|
||||
|
||||
@ -351,8 +351,8 @@ bool EmitterState::SetPostCommentIndent(std::size_t value,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EmitterState::SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
|
||||
FmtScope::value scope) {
|
||||
bool EmitterState::SetFlowType(GroupType groupType, EMITTER_MANIP value,
|
||||
FmtScope scope) {
|
||||
switch (value) {
|
||||
case Block:
|
||||
case Flow:
|
||||
@ -363,7 +363,7 @@ bool EmitterState::SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
|
||||
}
|
||||
}
|
||||
|
||||
EMITTER_MANIP EmitterState::GetFlowType(GroupType::value groupType) const {
|
||||
EMITTER_MANIP EmitterState::GetFlowType(GroupType groupType) const {
|
||||
// force flow style if we're currently in a flow
|
||||
if (CurGroupFlowType() == FlowType::Flow)
|
||||
return Flow;
|
||||
@ -372,7 +372,7 @@ EMITTER_MANIP EmitterState::GetFlowType(GroupType::value groupType) const {
|
||||
return (groupType == GroupType::Seq ? m_seqFmt.get() : m_mapFmt.get());
|
||||
}
|
||||
|
||||
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope scope) {
|
||||
switch (value) {
|
||||
case Auto:
|
||||
case LongKey:
|
||||
@ -383,7 +383,7 @@ bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
||||
}
|
||||
}
|
||||
|
||||
bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) {
|
||||
bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope scope) {
|
||||
if (value > std::numeric_limits<float>::max_digits10)
|
||||
return false;
|
||||
_Set(m_floatPrecision, value, scope);
|
||||
@ -391,7 +391,7 @@ bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) {
|
||||
}
|
||||
|
||||
bool EmitterState::SetDoublePrecision(std::size_t value,
|
||||
FmtScope::value scope) {
|
||||
FmtScope scope) {
|
||||
if (value > std::numeric_limits<double>::max_digits10)
|
||||
return false;
|
||||
_Set(m_doublePrecision, value, scope);
|
||||
|
||||
@ -18,14 +18,16 @@
|
||||
#include <vector>
|
||||
|
||||
namespace YAML {
|
||||
struct FmtScope {
|
||||
enum value { Local, Global };
|
||||
enum class FmtScope {
|
||||
Local, Global
|
||||
};
|
||||
struct GroupType {
|
||||
enum value { NoType, Seq, Map };
|
||||
|
||||
enum class GroupType {
|
||||
NoType, Seq, Map
|
||||
};
|
||||
struct FlowType {
|
||||
enum value { NoType, Flow, Block };
|
||||
|
||||
enum class FlowType {
|
||||
NoType, Flow, Block
|
||||
};
|
||||
|
||||
class EmitterState {
|
||||
@ -51,14 +53,14 @@ class EmitterState {
|
||||
void StartedDoc();
|
||||
void EndedDoc();
|
||||
void StartedScalar();
|
||||
void StartedGroup(GroupType::value type);
|
||||
void EndedGroup(GroupType::value type);
|
||||
void StartedGroup(GroupType type);
|
||||
void EndedGroup(GroupType type);
|
||||
|
||||
EmitterNodeType::value NextGroupType(GroupType::value type) const;
|
||||
EmitterNodeType::value NextGroupType(GroupType type) const;
|
||||
EmitterNodeType::value CurGroupNodeType() const;
|
||||
|
||||
GroupType::value CurGroupType() const;
|
||||
FlowType::value CurGroupFlowType() const;
|
||||
GroupType CurGroupType() const;
|
||||
FlowType CurGroupFlowType() const;
|
||||
std::size_t CurGroupIndent() const;
|
||||
std::size_t CurGroupChildCount() const;
|
||||
bool CurGroupLongKey() const;
|
||||
@ -79,50 +81,50 @@ class EmitterState {
|
||||
// formatters
|
||||
void SetLocalValue(EMITTER_MANIP value);
|
||||
|
||||
bool SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetOutputCharset(EMITTER_MANIP value, FmtScope scope);
|
||||
EMITTER_MANIP GetOutputCharset() const { return m_charset.get(); }
|
||||
|
||||
bool SetStringFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetStringFormat(EMITTER_MANIP value, FmtScope scope);
|
||||
EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); }
|
||||
|
||||
bool SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetBoolFormat(EMITTER_MANIP value, FmtScope scope);
|
||||
EMITTER_MANIP GetBoolFormat() const { return m_boolFmt.get(); }
|
||||
|
||||
bool SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetBoolLengthFormat(EMITTER_MANIP value, FmtScope scope);
|
||||
EMITTER_MANIP GetBoolLengthFormat() const { return m_boolLengthFmt.get(); }
|
||||
|
||||
bool SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetBoolCaseFormat(EMITTER_MANIP value, FmtScope scope);
|
||||
EMITTER_MANIP GetBoolCaseFormat() const { return m_boolCaseFmt.get(); }
|
||||
|
||||
bool SetNullFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetNullFormat(EMITTER_MANIP value, FmtScope scope);
|
||||
EMITTER_MANIP GetNullFormat() const { return m_nullFmt.get(); }
|
||||
|
||||
bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetIntFormat(EMITTER_MANIP value, FmtScope scope);
|
||||
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
|
||||
|
||||
bool SetIndent(std::size_t value, FmtScope::value scope);
|
||||
bool SetIndent(std::size_t value, FmtScope scope);
|
||||
std::size_t GetIndent() const { return m_indent.get(); }
|
||||
|
||||
bool SetPreCommentIndent(std::size_t value, FmtScope::value scope);
|
||||
bool SetPreCommentIndent(std::size_t value, FmtScope scope);
|
||||
std::size_t GetPreCommentIndent() const { return m_preCommentIndent.get(); }
|
||||
bool SetPostCommentIndent(std::size_t value, FmtScope::value scope);
|
||||
bool SetPostCommentIndent(std::size_t value, FmtScope scope);
|
||||
std::size_t GetPostCommentIndent() const { return m_postCommentIndent.get(); }
|
||||
|
||||
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
|
||||
FmtScope::value scope);
|
||||
EMITTER_MANIP GetFlowType(GroupType::value groupType) const;
|
||||
bool SetFlowType(GroupType groupType, EMITTER_MANIP value,
|
||||
FmtScope scope);
|
||||
EMITTER_MANIP GetFlowType(GroupType groupType) const;
|
||||
|
||||
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope scope);
|
||||
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
|
||||
|
||||
bool SetFloatPrecision(std::size_t value, FmtScope::value scope);
|
||||
bool SetFloatPrecision(std::size_t value, FmtScope scope);
|
||||
std::size_t GetFloatPrecision() const { return m_floatPrecision.get(); }
|
||||
bool SetDoublePrecision(std::size_t value, FmtScope::value scope);
|
||||
bool SetDoublePrecision(std::size_t value, FmtScope scope);
|
||||
std::size_t GetDoublePrecision() const { return m_doublePrecision.get(); }
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void _Set(Setting<T>& fmt, T value, FmtScope::value scope);
|
||||
void _Set(Setting<T>& fmt, T value, FmtScope scope);
|
||||
|
||||
void StartedNode();
|
||||
|
||||
@ -151,7 +153,7 @@ class EmitterState {
|
||||
SettingChanges m_globalModifiedSettings;
|
||||
|
||||
struct Group {
|
||||
explicit Group(GroupType::value type_)
|
||||
explicit Group(GroupType type_)
|
||||
: type(type_),
|
||||
flowType{},
|
||||
indent(0),
|
||||
@ -159,8 +161,8 @@ class EmitterState {
|
||||
longKey(false),
|
||||
modifiedSettings{} {}
|
||||
|
||||
GroupType::value type;
|
||||
FlowType::value flowType;
|
||||
GroupType type;
|
||||
FlowType flowType;
|
||||
std::size_t indent;
|
||||
std::size_t childCount;
|
||||
bool longKey;
|
||||
@ -196,7 +198,7 @@ class EmitterState {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
|
||||
void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope scope) {
|
||||
switch (scope) {
|
||||
case FmtScope::Local:
|
||||
m_modifiedSettings.push(fmt.set(value));
|
||||
|
||||
@ -152,7 +152,7 @@ void WriteCodePoint(ostream_wrapper& out, int codePoint) {
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
|
||||
bool IsValidPlainScalar(const std::string& str, FlowType flowType,
|
||||
bool allowOnlyAscii) {
|
||||
// check against null
|
||||
if (IsNullString(str)) {
|
||||
@ -206,7 +206,7 @@ bool IsValidSingleQuotedScalar(const std::string& str, bool escapeNonAscii) {
|
||||
});
|
||||
}
|
||||
|
||||
bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType,
|
||||
bool IsValidLiteralScalar(const std::string& str, FlowType flowType,
|
||||
bool escapeNonAscii) {
|
||||
if (flowType == FlowType::Flow) {
|
||||
return false;
|
||||
@ -227,7 +227,7 @@ std::pair<uint16_t, uint16_t> EncodeUTF16SurrogatePair(int codePoint) {
|
||||
};
|
||||
}
|
||||
|
||||
void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint, StringEscaping::value stringEscapingStyle) {
|
||||
void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint, StringEscaping stringEscapingStyle) {
|
||||
static const char hexDigits[] = "0123456789abcdef";
|
||||
|
||||
out << "\\";
|
||||
@ -267,9 +267,9 @@ bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
StringFormat::value ComputeStringFormat(const std::string& str,
|
||||
StringFormat ComputeStringFormat(const std::string& str,
|
||||
EMITTER_MANIP strFormat,
|
||||
FlowType::value flowType,
|
||||
FlowType flowType,
|
||||
bool escapeNonAscii) {
|
||||
switch (strFormat) {
|
||||
case Auto:
|
||||
@ -317,7 +317,7 @@ bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str) {
|
||||
}
|
||||
|
||||
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
|
||||
StringEscaping::value stringEscaping) {
|
||||
StringEscaping stringEscaping) {
|
||||
out << "\"";
|
||||
int codePoint;
|
||||
for (std::string::const_iterator i = str.begin();
|
||||
@ -379,7 +379,7 @@ bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteChar(ostream_wrapper& out, char ch, StringEscaping::value stringEscapingStyle) {
|
||||
bool WriteChar(ostream_wrapper& out, char ch, StringEscaping stringEscapingStyle) {
|
||||
if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) {
|
||||
out << ch;
|
||||
} else if (ch == '\"') {
|
||||
|
||||
@ -20,27 +20,27 @@ class ostream_wrapper;
|
||||
namespace YAML {
|
||||
class Binary;
|
||||
|
||||
struct StringFormat {
|
||||
enum value { Plain, SingleQuoted, DoubleQuoted, Literal };
|
||||
enum class StringFormat {
|
||||
Plain, SingleQuoted, DoubleQuoted, Literal
|
||||
};
|
||||
|
||||
struct StringEscaping {
|
||||
enum value { None, NonAscii, JSON };
|
||||
enum class StringEscaping {
|
||||
None, NonAscii, JSON
|
||||
};
|
||||
|
||||
namespace Utils {
|
||||
StringFormat::value ComputeStringFormat(const std::string& str,
|
||||
StringFormat ComputeStringFormat(const std::string& str,
|
||||
EMITTER_MANIP strFormat,
|
||||
FlowType::value flowType,
|
||||
FlowType flowType,
|
||||
bool escapeNonAscii);
|
||||
|
||||
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str);
|
||||
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
|
||||
StringEscaping::value stringEscaping);
|
||||
StringEscaping stringEscaping);
|
||||
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
||||
std::size_t indent);
|
||||
bool WriteChar(ostream_wrapper& out, char ch,
|
||||
StringEscaping::value stringEscapingStyle);
|
||||
StringEscaping stringEscapingStyle);
|
||||
bool WriteComment(ostream_wrapper& out, const std::string& str,
|
||||
std::size_t postCommentIndent);
|
||||
bool WriteAlias(ostream_wrapper& out, const std::string& str);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user