Compare commits

...
Author SHA1 Message Date
Oliver Hamlet d5014a067f Merge branch 'no-lib-prefixes-suffixes' into patched-for-loot 2016-04-12 06:58:21 +01:00
Oliver Hamlet 43438653c4 Remove library prefixes and suffixes
Having inconsistent library naming between different builds (eg.
Release/Debug/MT/MD) makes linking more difficult for projects that use
yaml-cpp.
2016-04-12 06:56:51 +01:00
Oliver Hamlet e377ae191d Merge branch 'merge-key-support' into patched-for-loot 2016-02-14 11:48:51 +00:00
Oliver Hamlet 8fabe1f869 Merge branch 'fix-emitter-styling' into patched-for-loot 2016-02-14 11:48:47 +00:00
Oliver Hamlet f5163e0bfe Fix broken emitter styling
Setting the global emitter styling doesn't override inherited styles, so
don't inherit.
2016-02-14 00:14:47 +00:00
Oliver Hamlet aae9bbb003 Revert compiler flag variables in CMake config.
This is a partial revert of d59586630e.
2016-02-13 23:41:15 +00:00
Oliver Hamlet c7e490f9d6 Add support for merge keys. 2016-02-13 22:42:52 +00:00
6 changed files with 84 additions and 40 deletions
+7 -36
View File
@@ -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}
+31 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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)
+17
View File
@@ -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;
+26
View File
@@ -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;