mirror of
https://github.com/loot/yaml-cpp.git
synced 2026-07-27 14:13:42 -07:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5014a067f | ||
|
|
43438653c4 | ||
|
|
e377ae191d | ||
|
|
8fabe1f869 | ||
|
|
f5163e0bfe | ||
|
|
aae9bbb003 | ||
|
|
c7e490f9d6 |
+7
-36
@@ -118,15 +118,10 @@ include_directories(${YAML_CPP_SOURCE_DIR}/include)
|
||||
###
|
||||
### General compilation settings
|
||||
###
|
||||
|
||||
set(yaml_c_flags ${CMAKE_C_FLAGS})
|
||||
set(yaml_cxx_flags ${CMAKE_CXX_FLAGS})
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(LABEL_SUFFIX "shared")
|
||||
else()
|
||||
set(LABEL_SUFFIX "static")
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
if(APPLE_UNIVERSAL_BIN)
|
||||
set(CMAKE_OSX_ARCHITECTURES ppc;i386)
|
||||
@@ -179,7 +174,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
|
||||
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
|
||||
endif()
|
||||
#
|
||||
set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long -std=c++11 ${yaml_cxx_flags}")
|
||||
set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long -std=c++11")
|
||||
|
||||
### Make specific
|
||||
if(${CMAKE_BUILD_TOOL} MATCHES make OR ${CMAKE_BUILD_TOOL} MATCHES gmake)
|
||||
@@ -201,23 +196,20 @@ if(MSVC)
|
||||
# plus set lib suffix for later use and project label accordingly
|
||||
# see http://msdn.microsoft.com/en-us/library/aa278396(v=VS.60).aspx
|
||||
# http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.71).aspx
|
||||
set(LIB_RT_SUFFIX "md") # CMake defaults to /MD for MSVC
|
||||
set(LIB_RT_OPTION "/MD")
|
||||
#
|
||||
if(NOT MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML)
|
||||
if(MSVC_STHREADED_RT) # User wants to have old single-threaded static runtime libraries
|
||||
set(LIB_RT_SUFFIX "ml")
|
||||
set(LIB_RT_OPTION "/ML")
|
||||
if(NOT ${MSVC_VERSION} LESS 1400)
|
||||
message(FATAL_ERROR "Single-threaded static runtime libraries (/ML) only available until VS .NET 2003 (7.1).")
|
||||
endif()
|
||||
else()
|
||||
set(LIB_RT_SUFFIX "mt")
|
||||
set(LIB_RT_OPTION "/MT")
|
||||
endif()
|
||||
|
||||
# correct linker options
|
||||
foreach(flag_var yaml_c_flags yaml_cxx_flags)
|
||||
foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
||||
foreach(config_name "" DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
|
||||
set(var_name "${flag_var}")
|
||||
if(NOT "${config_name}" STREQUAL "")
|
||||
@@ -227,23 +219,15 @@ if(MSVC)
|
||||
endforeach()
|
||||
endforeach()
|
||||
endif()
|
||||
#
|
||||
set(LABEL_SUFFIX "${LABEL_SUFFIX} ${LIB_RT_SUFFIX}")
|
||||
|
||||
# b) Change prefix for static libraries
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # to distinguish static libraries from DLL import libs
|
||||
|
||||
# c) Correct suffixes for static libraries
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
### General stuff
|
||||
set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}")
|
||||
endif()
|
||||
|
||||
### Project stuff
|
||||
# /W3 = set warning level; see http://msdn.microsoft.com/en-us/library/thxezb7y.aspx
|
||||
# /wd4127 = disable warning C4127 "conditional expression is constant"; see 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
|
||||
set(yaml_cxx_flags "/W3 /wd4127 /wd4355 ${yaml_cxx_flags}")
|
||||
set(CMAKE_CXX_FLAGS "/W3 /wd4127 /wd4355 ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
|
||||
@@ -259,12 +243,12 @@ endif()
|
||||
set(INCLUDE_INSTALL_ROOT_DIR include)
|
||||
|
||||
set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_ROOT_DIR}/yaml-cpp)
|
||||
set(LIB_INSTALL_DIR "${_library_dir}${LIB_SUFFIX}")
|
||||
set(LIB_INSTALL_DIR "${_library_dir}")
|
||||
|
||||
set(_INSTALL_DESTINATIONS
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
|
||||
ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
|
||||
ARCHIVE DESTINATION "lib"
|
||||
)
|
||||
|
||||
|
||||
@@ -273,13 +257,12 @@ set(_INSTALL_DESTINATIONS
|
||||
###
|
||||
add_library(yaml-cpp ${library_sources})
|
||||
set_target_properties(yaml-cpp PROPERTIES
|
||||
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}"
|
||||
COMPILE_FLAGS "${yaml_cxx_flags}"
|
||||
)
|
||||
|
||||
set_target_properties(yaml-cpp PROPERTIES
|
||||
VERSION "${YAML_CPP_VERSION}"
|
||||
SOVERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}"
|
||||
PROJECT_LABEL "yaml-cpp ${LABEL_SUFFIX}"
|
||||
)
|
||||
|
||||
if(IPHONE)
|
||||
@@ -288,18 +271,6 @@ if(IPHONE)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
# correct library names
|
||||
set_target_properties(yaml-cpp PROPERTIES
|
||||
DEBUG_POSTFIX "${LIB_TARGET_SUFFIX}d"
|
||||
RELEASE_POSTFIX "${LIB_TARGET_SUFFIX}"
|
||||
MINSIZEREL_POSTFIX "${LIB_TARGET_SUFFIX}"
|
||||
RELWITHDEBINFO_POSTFIX "${LIB_TARGET_SUFFIX}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
install(TARGETS yaml-cpp ${_INSTALL_DESTINATIONS})
|
||||
install(
|
||||
DIRECTORY ${header_directory}
|
||||
|
||||
@@ -116,18 +116,48 @@ class node {
|
||||
value.add_dependency(*this);
|
||||
}
|
||||
|
||||
template <typename Key>
|
||||
inline node* GetValueFromMergeKey(const Key& key, node* currentValue,
|
||||
shared_memory_holder pMemory) const {
|
||||
node* mergeValue =
|
||||
static_cast<const node_ref&>(*m_pRef).get(std::string("<<"), pMemory);
|
||||
if (mergeValue) {
|
||||
if (mergeValue->type() == NodeType::Map) {
|
||||
return &mergeValue->get(key, pMemory);
|
||||
} else if (mergeValue->type() == NodeType::Sequence) {
|
||||
for (const_node_iterator it = mergeValue->begin();
|
||||
it != mergeValue->end(); ++it) {
|
||||
if (it->pNode && it->pNode->type() == NodeType::Map) {
|
||||
node* value = it->pNode->get(key, pMemory);
|
||||
if (value && value->type() != NodeType::Undefined) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
// indexing
|
||||
template <typename Key>
|
||||
node* get(const Key& key, shared_memory_holder pMemory) const {
|
||||
// NOTE: this returns a non-const node so that the top-level Node can wrap
|
||||
// it, and returns a pointer so that it can be NULL (if there is no such
|
||||
// key).
|
||||
return static_cast<const node_ref&>(*m_pRef).get(key, pMemory);
|
||||
node* value = static_cast<const node_ref&>(*m_pRef).get(key, pMemory);
|
||||
if (!value || value->type() == NodeType::Undefined) {
|
||||
return GetValueFromMergeKey(key, value, pMemory);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
template <typename Key>
|
||||
node& get(const Key& key, shared_memory_holder pMemory) {
|
||||
node& value = m_pRef->get(key, pMemory);
|
||||
value.add_dependency(*this);
|
||||
if (value.type() == NodeType::Undefined) {
|
||||
return *GetValueFromMergeKey(key, &value, pMemory);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
template <typename Key>
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ void NodeBuilder::OnSequenceStart(const Mark& mark,
|
||||
detail::node& node = Push(mark, anchor);
|
||||
node.set_tag(tag);
|
||||
node.set_type(NodeType::Sequence);
|
||||
node.set_style(style);
|
||||
//node.set_style(style);
|
||||
}
|
||||
|
||||
void NodeBuilder::OnSequenceEnd() { Pop(); }
|
||||
@@ -64,7 +64,7 @@ void NodeBuilder::OnMapStart(const Mark& mark, const std::string& tag,
|
||||
detail::node& node = Push(mark, anchor);
|
||||
node.set_type(NodeType::Map);
|
||||
node.set_tag(tag);
|
||||
node.set_style(style);
|
||||
//node.set_style(style);
|
||||
m_mapDepth++;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ add_executable(run-tests
|
||||
${test_headers}
|
||||
)
|
||||
set_target_properties(run-tests PROPERTIES
|
||||
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}"
|
||||
COMPILE_FLAGS "${yaml_test_flags}"
|
||||
)
|
||||
target_link_libraries(run-tests yaml-cpp gmock)
|
||||
|
||||
|
||||
@@ -624,6 +624,23 @@ TEST_F(EmitterTest, ComplexGlobalSettings) {
|
||||
ExpectEmit("- key 1: value 1\n key 2: [a, b, c]\n- [1, 2]:\n a: b");
|
||||
}
|
||||
|
||||
TEST_F(EmitterTest, GlobalSettingsNodeStyles) {
|
||||
Node node;
|
||||
|
||||
node = Load("foo:\n"
|
||||
" - 1\n"
|
||||
" - 2\n"
|
||||
" - 3\n"
|
||||
"bar: baz\n");
|
||||
|
||||
out.SetSeqFormat(YAML::Flow);
|
||||
out.SetMapFormat(YAML::Flow);
|
||||
|
||||
out << node;
|
||||
|
||||
ExpectEmit("{foo: [1, 2, 3], bar: baz}");
|
||||
}
|
||||
|
||||
TEST_F(EmitterTest, Null) {
|
||||
out << BeginSeq;
|
||||
out << Null;
|
||||
|
||||
@@ -185,6 +185,32 @@ TEST(LoadNodeTest, DereferenceIteratorError) {
|
||||
EXPECT_THROW(node.begin()->begin()->Type(), InvalidNode);
|
||||
}
|
||||
|
||||
TEST(NodeTest, MergeKeyScalarSupport) {
|
||||
Node node = Load("{<<: {a: 1}}");
|
||||
ASSERT_FALSE(!node["a"]);
|
||||
EXPECT_EQ(1, node["a"].as<int>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, MergeKeyExistingKey) {
|
||||
Node node = Load("{a: 1, <<: {a: 2}}");
|
||||
ASSERT_FALSE(!node["a"]);
|
||||
EXPECT_EQ(1, node["a"].as<int>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, MergeKeySequenceSupport) {
|
||||
Node node = Load("<<: [{a: 1}, {a: 2, b: 3}]");
|
||||
ASSERT_FALSE(!node["a"]);
|
||||
ASSERT_FALSE(!node["b"]);
|
||||
EXPECT_EQ(1, node["a"].as<int>());
|
||||
EXPECT_EQ(3, node["b"].as<int>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, NestedMergeKeys) {
|
||||
Node node = Load("{<<: {<<: {a: 1}}}");
|
||||
ASSERT_FALSE(!node["a"]);
|
||||
EXPECT_EQ(1, node["a"].as<int>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, EmitEmptyNode) {
|
||||
Node node;
|
||||
Emitter emitter;
|
||||
|
||||
Reference in New Issue
Block a user