Skip to content

Commit

Permalink
Merge pull request #7 from tangrams/turbo-yaml
Browse files Browse the repository at this point in the history
Turbo YAML
  • Loading branch information
tallytalwar authored Dec 12, 2016
2 parents 3ded7e0 + e6c6954 commit be501d9
Show file tree
Hide file tree
Showing 66 changed files with 3,334 additions and 1,959 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
language: c++

os:
- linux
- osx

compiler:
- clang
- gcc

before_install:
- |
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y \
&& sudo apt-get update -qq \
&& if [ "$CXX" == "g++" ]; then
sudo apt-get install -qq g++-4.7 && export CXX="g++-4.7" CC="gcc-4.7"
sudo apt-get install -qq g++-4.9 && export CXX="g++-4.9" CC="gcc-4.9"
fi
fi
before_script:
Expand Down
70 changes: 36 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enable_testing()
## Project stuff
option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" ON)
option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON)
option(YAML_CPP_INSTALL "Generate installation target" ON)

## Build options
# --> General
Expand Down Expand Up @@ -308,47 +309,48 @@ if(MSVC)
endif()
endif()

install(TARGETS yaml-cpp EXPORT yaml-cpp-targets ${_INSTALL_DESTINATIONS})
install(
DIRECTORY ${header_directory}
DESTINATION ${INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN "*.h"
)

export(
TARGETS yaml-cpp
FILE "${PROJECT_BINARY_DIR}/yaml-cpp-targets.cmake")
export(PACKAGE yaml-cpp)
set(EXPORT_TARGETS yaml-cpp CACHE INTERNAL "export targets")
if (YAML_CPP_INSTALL)
install(TARGETS yaml-cpp EXPORT yaml-cpp-targets ${_INSTALL_DESTINATIONS})
install(DIRECTORY ${header_directory}
DESTINATION ${INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN "*.h")

set(CONFIG_INCLUDE_DIRS "${YAML_CPP_SOURCE_DIR}/include")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
"${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake" @ONLY)
export(
TARGETS yaml-cpp
FILE "${PROJECT_BINARY_DIR}/yaml-cpp-targets.cmake")
export(PACKAGE yaml-cpp)
set(EXPORT_TARGETS yaml-cpp CACHE INTERNAL "export targets")

if(WIN32 AND NOT CYGWIN)
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/CMake)
else()
set(INSTALL_CMAKE_DIR ${LIB_INSTALL_DIR}/cmake/yaml-cpp)
endif()
set(CONFIG_INCLUDE_DIRS "${YAML_CPP_SOURCE_DIR}/include")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
"${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake" @ONLY)

file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INCLUDE_INSTALL_ROOT_DIR}")
set(CONFIG_INCLUDE_DIRS "\${YAML_CPP_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yaml-cpp-config.cmake" @ONLY)
if(WIN32 AND NOT CYGWIN)
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/CMake)
else()
set(INSTALL_CMAKE_DIR ${LIB_INSTALL_DIR}/cmake/yaml-cpp)
endif()

file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INCLUDE_INSTALL_ROOT_DIR}")
set(CONFIG_INCLUDE_DIRS "\${YAML_CPP_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yaml-cpp-config.cmake" @ONLY)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config-version.cmake.in
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake" @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config-version.cmake.in
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake" @ONLY)

install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yaml-cpp-config.cmake"
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
install(EXPORT yaml-cpp-targets DESTINATION ${INSTALL_CMAKE_DIR})
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yaml-cpp-config.cmake"
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
install(EXPORT yaml-cpp-targets DESTINATION ${INSTALL_CMAKE_DIR})

if(UNIX)
set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
if(UNIX)
set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
endif()
endif()


Expand Down
24 changes: 12 additions & 12 deletions include/yaml-cpp/emitfromevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ class EmitFromEvents : public EventHandler {
public:
EmitFromEvents(Emitter& emitter);

virtual void OnDocumentStart(const Mark& mark);
virtual void OnDocumentEnd();
void OnDocumentStart(const Mark& mark) override;
void OnDocumentEnd() override;

virtual void OnNull(const Mark& mark, anchor_t anchor);
virtual void OnAlias(const Mark& mark, anchor_t anchor);
virtual void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, const std::string& value);
void OnNull(const Mark& mark, anchor_t anchor) override;
void OnAlias(const Mark& mark, anchor_t anchor) override;
void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, std::string value) override;

virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor, EmitterStyle::value style);
virtual void OnSequenceEnd();
void OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor, EmitterStyle::value style) override;
void OnSequenceEnd() override;

virtual void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor, EmitterStyle::value style);
virtual void OnMapEnd();
void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor, EmitterStyle::value style) override;
void OnMapEnd() override;

private:
void BeginNode();
Expand Down
2 changes: 1 addition & 1 deletion include/yaml-cpp/emitterstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace YAML {
struct EmitterStyle {
enum value { Default, Block, Flow };
enum value : char { Default, Block, Flow };
};
}
3 changes: 2 additions & 1 deletion include/yaml-cpp/eventhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EventHandler {
virtual void OnNull(const Mark& mark, anchor_t anchor) = 0;
virtual void OnAlias(const Mark& mark, anchor_t anchor) = 0;
virtual void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, const std::string& value) = 0;
anchor_t anchor, std::string value) = 0;

virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor, EmitterStyle::value style) = 0;
Expand All @@ -28,4 +28,5 @@ class EventHandler {
anchor_t anchor, EmitterStyle::value style) = 0;
virtual void OnMapEnd() = 0;
};

}
60 changes: 36 additions & 24 deletions include/yaml-cpp/node/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ inline bool IsNaN(const std::string& input) {
// Node
template <>
struct convert<Node> {
static Node encode(const Node& rhs) { return rhs; }
static void encode(const Node& node, Node& rhs) {
rhs.reset(node);
}

static bool decode(const Node& node, Node& rhs) {
rhs.reset(node);
Expand All @@ -51,7 +53,9 @@ struct convert<Node> {
// std::string
template <>
struct convert<std::string> {
static Node encode(const std::string& rhs) { return Node(rhs); }
static void encode(const std::string& rhs, Node& node) {
node.node().set_scalar(rhs);
}

static bool decode(const Node& node, std::string& rhs) {
if (!node.IsScalar())
Expand All @@ -64,17 +68,23 @@ struct convert<std::string> {
// C-strings can only be encoded
template <>
struct convert<const char*> {
static Node encode(const char*& rhs) { return Node(rhs); }
static void encode(const char*& rhs, Node& node) {
node.node().set_scalar(rhs);
}
};

template <std::size_t N>
struct convert<const char[N]> {
static Node encode(const char(&rhs)[N]) { return Node(rhs); }
static void encode(const char(&rhs)[N], Node& node) {
node.node().set_scalar(rhs);
}
};

template <>
struct convert<_Null> {
static Node encode(const _Null& /* rhs */) { return Node(); }
static void encode(const _Null& /* rhs */, Node& node) {
node.node().set_null();
}

static bool decode(const Node& node, _Null& /* rhs */) {
return node.IsNull();
Expand All @@ -84,11 +94,11 @@ struct convert<_Null> {
#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \
template <> \
struct convert<type> { \
static Node encode(const type& rhs) { \
static void encode(const type& rhs, Node& node) { \
std::stringstream stream; \
stream.precision(std::numeric_limits<type>::digits10 + 1); \
stream << rhs; \
return Node(stream.str()); \
return node.node().set_scalar(stream.str()); \
} \
\
static bool decode(const Node& node, type& rhs) { \
Expand Down Expand Up @@ -149,20 +159,23 @@ YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long double);
// bool
template <>
struct convert<bool> {
static Node encode(bool rhs) { return rhs ? Node("true") : Node("false"); }
static void encode(bool rhs, Node& node) {
node.node().set_scalar(rhs ? "true" : "false");
}

YAML_CPP_API static bool decode(const Node& node, bool& rhs);
};

// std::map
template <typename K, typename V>
struct convert<std::map<K, V>> {
static Node encode(const std::map<K, V>& rhs) {
Node node(NodeType::Map);
static void encode(const std::map<K, V>& rhs, Node& node) {

node.node().set_type(NodeType::Map);

for (typename std::map<K, V>::const_iterator it = rhs.begin();
it != rhs.end(); ++it)
node.force_insert(it->first, it->second);
return node;
}

static bool decode(const Node& node, std::map<K, V>& rhs) {
Expand All @@ -184,12 +197,12 @@ struct convert<std::map<K, V>> {
// std::vector
template <typename T>
struct convert<std::vector<T>> {
static Node encode(const std::vector<T>& rhs) {
Node node(NodeType::Sequence);
static void encode(const std::vector<T>& rhs, Node& node) {
node.node().set_type(NodeType::Sequence);

for (typename std::vector<T>::const_iterator it = rhs.begin();
it != rhs.end(); ++it)
node.push_back(*it);
return node;
}

static bool decode(const Node& node, std::vector<T>& rhs) {
Expand All @@ -211,8 +224,9 @@ struct convert<std::vector<T>> {
// std::list
template <typename T>
struct convert<std::list<T>> {
static Node encode(const std::list<T>& rhs) {
Node node(NodeType::Sequence);
static Node encode(const std::list<T>& rhs, Node& node) {
node.node().set_type(NodeType::Sequence);

for (typename std::list<T>::const_iterator it = rhs.begin();
it != rhs.end(); ++it)
node.push_back(*it);
Expand All @@ -238,12 +252,11 @@ struct convert<std::list<T>> {
// std::array
template <typename T, std::size_t N>
struct convert<std::array<T, N>> {
static Node encode(const std::array<T, N>& rhs) {
Node node(NodeType::Sequence);
static void encode(const std::array<T, N>& rhs, Node& node) {
node.node().set_type(NodeType::Sequence);
for (const auto& element : rhs) {
node.push_back(element);
}
return node;
}

static bool decode(const Node& node, std::array<T, N>& rhs) {
Expand Down Expand Up @@ -271,11 +284,10 @@ struct convert<std::array<T, N>> {
// std::pair
template <typename T, typename U>
struct convert<std::pair<T, U>> {
static Node encode(const std::pair<T, U>& rhs) {
Node node(NodeType::Sequence);
static void encode(const std::pair<T, U>& rhs, Node& node) {
node.node().set_type(NodeType::Sequence);
node.push_back(rhs.first);
node.push_back(rhs.second);
return node;
}

static bool decode(const Node& node, std::pair<T, U>& rhs) {
Expand Down Expand Up @@ -303,8 +315,8 @@ struct convert<std::pair<T, U>> {
// binary
template <>
struct convert<Binary> {
static Node encode(const Binary& rhs) {
return Node(EncodeBase64(rhs.data(), rhs.size()));
static void encode(const Binary& rhs, Node& node) {
node.node().set_scalar(EncodeBase64(rhs.data(), rhs.size()));
}

static bool decode(const Node& node, Binary& rhs) {
Expand Down
Loading

0 comments on commit be501d9

Please sign in to comment.