Merge branch 'master' into doxygen
This commit is contained in:
commit
b81a633ec9
@ -12,6 +12,11 @@ endif()
|
|||||||
if(POLICY CMP0015)
|
if(POLICY CMP0015)
|
||||||
cmake_policy(SET CMP0015 OLD)
|
cmake_policy(SET CMP0015 OLD)
|
||||||
endif()
|
endif()
|
||||||
|
# see https://cmake.org/cmake/help/latest/policy/CMP0042.html
|
||||||
|
if(POLICY CMP0042)
|
||||||
|
# Enable MACOSX_RPATH by default.
|
||||||
|
cmake_policy(SET CMP0042 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
@ -149,9 +154,11 @@ if(WIN32)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# GCC or Clang specialities
|
# GCC or Clang or Intel Compiler specialities
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
|
||||||
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
|
||||||
|
CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||||
|
|
||||||
### General stuff
|
### General stuff
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(CMAKE_SHARED_LIBRARY_PREFIX "") # DLLs do not have a "lib" prefix
|
set(CMAKE_SHARED_LIBRARY_PREFIX "") # DLLs do not have a "lib" prefix
|
||||||
@ -219,13 +226,14 @@ if(MSVC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# correct linker options
|
# 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)
|
foreach(config_name "" DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
|
||||||
set(var_name "${flag_var}")
|
set(var_name "${flag_var}")
|
||||||
if(NOT "${config_name}" STREQUAL "")
|
if(NOT "${config_name}" STREQUAL "")
|
||||||
set(var_name "${var_name}_${config_name}")
|
set(var_name "${var_name}_${config_name}")
|
||||||
endif()
|
endif()
|
||||||
string(REPLACE "/MD" "${LIB_RT_OPTION}" ${var_name} "${${var_name}}")
|
string(REPLACE "/MD" "${LIB_RT_OPTION}" ${var_name} "${${var_name}}")
|
||||||
|
set(${var_name} "${${var_name}}" CACHE STRING "" FORCE)
|
||||||
endforeach()
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -30,7 +30,7 @@ yaml-cpp uses [CMake](http://www.cmake.org) to support cross-platform building.
|
|||||||
|
|
||||||
|
|
||||||
* The `generator` is whatever type of build system you'd like to use. To see a full list of generators on your platform, just run `cmake` (with no arguments). For example:
|
* The `generator` is whatever type of build system you'd like to use. To see a full list of generators on your platform, just run `cmake` (with no arguments). For example:
|
||||||
* On Windows, you might use "Visual Studio 12 2013" to generate a Visual Studio 2013 solution
|
* On Windows, you might use "Visual Studio 12 2013" to generate a Visual Studio 2013 solution or "Visual Studio 14 2015 Win64" to generate a 64-bit Visual Studio 2015 solution.
|
||||||
* On OS X, you might use "Xcode" to generate an Xcode project
|
* On OS X, you might use "Xcode" to generate an Xcode project
|
||||||
* On a UNIX-y system, simply omit the option to generate a makefile
|
* On a UNIX-y system, simply omit the option to generate a makefile
|
||||||
|
|
||||||
|
|||||||
@ -162,12 +162,12 @@ inline Emitter& Emitter::WriteStreamable(T value) {
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream) {
|
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream) {
|
||||||
stream.precision(GetFloatPrecision());
|
stream.precision(static_cast<std::streamsize>(GetFloatPrecision()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream) {
|
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream) {
|
||||||
stream.precision(GetDoublePrecision());
|
stream.precision(static_cast<std::streamsize>(GetDoublePrecision()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// overloads of insertion
|
// overloads of insertion
|
||||||
|
|||||||
@ -9,9 +9,9 @@
|
|||||||
|
|
||||||
#include "yaml-cpp/mark.h"
|
#include "yaml-cpp/mark.h"
|
||||||
#include "yaml-cpp/traits.h"
|
#include "yaml-cpp/traits.h"
|
||||||
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
// error messages
|
// error messages
|
||||||
@ -89,7 +89,7 @@ const char* const BAD_FILE = "bad file";
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline const std::string KEY_NOT_FOUND_WITH_KEY(
|
inline const std::string KEY_NOT_FOUND_WITH_KEY(
|
||||||
const T&, typename disable_if<is_numeric<T> >::type* = 0) {
|
const T&, typename disable_if<is_numeric<T>>::type* = 0) {
|
||||||
return KEY_NOT_FOUND;
|
return KEY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline const std::string KEY_NOT_FOUND_WITH_KEY(
|
inline const std::string KEY_NOT_FOUND_WITH_KEY(
|
||||||
const T& key, typename enable_if<is_numeric<T> >::type* = 0) {
|
const T& key, typename enable_if<is_numeric<T>>::type* = 0) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << KEY_NOT_FOUND << ": " << key;
|
stream << KEY_NOT_FOUND << ": " << key;
|
||||||
return stream.str();
|
return stream.str();
|
||||||
@ -112,7 +112,9 @@ class Exception : public std::runtime_error {
|
|||||||
public:
|
public:
|
||||||
Exception(const Mark& mark_, const std::string& msg_)
|
Exception(const Mark& mark_, const std::string& msg_)
|
||||||
: std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
|
: std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
|
||||||
virtual ~Exception() throw() {}
|
virtual ~Exception() noexcept;
|
||||||
|
|
||||||
|
Exception(const Exception&) = default;
|
||||||
|
|
||||||
Mark mark;
|
Mark mark;
|
||||||
std::string msg;
|
std::string msg;
|
||||||
@ -135,12 +137,16 @@ class ParserException : public Exception {
|
|||||||
public:
|
public:
|
||||||
ParserException(const Mark& mark_, const std::string& msg_)
|
ParserException(const Mark& mark_, const std::string& msg_)
|
||||||
: Exception(mark_, msg_) {}
|
: Exception(mark_, msg_) {}
|
||||||
|
ParserException(const ParserException&) = default;
|
||||||
|
virtual ~ParserException() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RepresentationException : public Exception {
|
class RepresentationException : public Exception {
|
||||||
public:
|
public:
|
||||||
RepresentationException(const Mark& mark_, const std::string& msg_)
|
RepresentationException(const Mark& mark_, const std::string& msg_)
|
||||||
: Exception(mark_, msg_) {}
|
: Exception(mark_, msg_) {}
|
||||||
|
RepresentationException(const RepresentationException&) = default;
|
||||||
|
virtual ~RepresentationException() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
// representation exceptions
|
// representation exceptions
|
||||||
@ -148,6 +154,8 @@ class InvalidScalar : public RepresentationException {
|
|||||||
public:
|
public:
|
||||||
InvalidScalar(const Mark& mark_)
|
InvalidScalar(const Mark& mark_)
|
||||||
: RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
|
: RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
|
||||||
|
InvalidScalar(const InvalidScalar&) = default;
|
||||||
|
virtual ~InvalidScalar() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class KeyNotFound : public RepresentationException {
|
class KeyNotFound : public RepresentationException {
|
||||||
@ -156,6 +164,8 @@ class KeyNotFound : public RepresentationException {
|
|||||||
KeyNotFound(const Mark& mark_, const T& key_)
|
KeyNotFound(const Mark& mark_, const T& key_)
|
||||||
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {
|
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {
|
||||||
}
|
}
|
||||||
|
KeyNotFound(const KeyNotFound&) = default;
|
||||||
|
virtual ~KeyNotFound() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -163,7 +173,7 @@ class TypedKeyNotFound : public KeyNotFound {
|
|||||||
public:
|
public:
|
||||||
TypedKeyNotFound(const Mark& mark_, const T& key_)
|
TypedKeyNotFound(const Mark& mark_, const T& key_)
|
||||||
: KeyNotFound(mark_, key_), key(key_) {}
|
: KeyNotFound(mark_, key_), key(key_) {}
|
||||||
virtual ~TypedKeyNotFound() throw() {}
|
virtual ~TypedKeyNotFound() noexcept {}
|
||||||
|
|
||||||
T key;
|
T key;
|
||||||
};
|
};
|
||||||
@ -178,12 +188,16 @@ class InvalidNode : public RepresentationException {
|
|||||||
public:
|
public:
|
||||||
InvalidNode()
|
InvalidNode()
|
||||||
: RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {}
|
: RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {}
|
||||||
|
InvalidNode(const InvalidNode&) = default;
|
||||||
|
virtual ~InvalidNode() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BadConversion : public RepresentationException {
|
class BadConversion : public RepresentationException {
|
||||||
public:
|
public:
|
||||||
explicit BadConversion(const Mark& mark_)
|
explicit BadConversion(const Mark& mark_)
|
||||||
: RepresentationException(mark_, ErrorMsg::BAD_CONVERSION) {}
|
: RepresentationException(mark_, ErrorMsg::BAD_CONVERSION) {}
|
||||||
|
BadConversion(const BadConversion&) = default;
|
||||||
|
virtual ~BadConversion() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -196,35 +210,47 @@ class BadDereference : public RepresentationException {
|
|||||||
public:
|
public:
|
||||||
BadDereference()
|
BadDereference()
|
||||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
|
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
|
||||||
|
BadDereference(const BadDereference&) = default;
|
||||||
|
virtual ~BadDereference() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BadSubscript : public RepresentationException {
|
class BadSubscript : public RepresentationException {
|
||||||
public:
|
public:
|
||||||
BadSubscript()
|
BadSubscript()
|
||||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
|
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
|
||||||
|
BadSubscript(const BadSubscript&) = default;
|
||||||
|
virtual ~BadSubscript() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BadPushback : public RepresentationException {
|
class BadPushback : public RepresentationException {
|
||||||
public:
|
public:
|
||||||
BadPushback()
|
BadPushback()
|
||||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
|
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
|
||||||
|
BadPushback(const BadPushback&) = default;
|
||||||
|
virtual ~BadPushback() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BadInsert : public RepresentationException {
|
class BadInsert : public RepresentationException {
|
||||||
public:
|
public:
|
||||||
BadInsert()
|
BadInsert()
|
||||||
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
|
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
|
||||||
|
BadInsert(const BadInsert&) = default;
|
||||||
|
virtual ~BadInsert() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EmitterException : public Exception {
|
class EmitterException : public Exception {
|
||||||
public:
|
public:
|
||||||
EmitterException(const std::string& msg_)
|
EmitterException(const std::string& msg_)
|
||||||
: Exception(Mark::null_mark(), msg_) {}
|
: Exception(Mark::null_mark(), msg_) {}
|
||||||
|
EmitterException(const EmitterException&) = default;
|
||||||
|
virtual ~EmitterException() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BadFile : public Exception {
|
class BadFile : public Exception {
|
||||||
public:
|
public:
|
||||||
BadFile() : Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
|
BadFile() : Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
|
||||||
|
BadFile(const BadFile&) = default;
|
||||||
|
virtual ~BadFile() noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -162,7 +163,7 @@ struct convert<bool> {
|
|||||||
|
|
||||||
// std::map
|
// std::map
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
struct convert<std::map<K, V> > {
|
struct convert<std::map<K, V>> {
|
||||||
static Node encode(const std::map<K, V>& rhs) {
|
static Node encode(const std::map<K, V>& rhs) {
|
||||||
Node node(NodeType::Map);
|
Node node(NodeType::Map);
|
||||||
for (typename std::map<K, V>::const_iterator it = rhs.begin();
|
for (typename std::map<K, V>::const_iterator it = rhs.begin();
|
||||||
@ -189,7 +190,7 @@ struct convert<std::map<K, V> > {
|
|||||||
|
|
||||||
// std::vector
|
// std::vector
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct convert<std::vector<T> > {
|
struct convert<std::vector<T>> {
|
||||||
static Node encode(const std::vector<T>& rhs) {
|
static Node encode(const std::vector<T>& rhs) {
|
||||||
Node node(NodeType::Sequence);
|
Node node(NodeType::Sequence);
|
||||||
for (typename std::vector<T>::const_iterator it = rhs.begin();
|
for (typename std::vector<T>::const_iterator it = rhs.begin();
|
||||||
@ -216,7 +217,7 @@ struct convert<std::vector<T> > {
|
|||||||
|
|
||||||
// std::list
|
// std::list
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct convert<std::list<T> > {
|
struct convert<std::list<T>> {
|
||||||
static Node encode(const std::list<T>& rhs) {
|
static Node encode(const std::list<T>& rhs) {
|
||||||
Node node(NodeType::Sequence);
|
Node node(NodeType::Sequence);
|
||||||
for (typename std::list<T>::const_iterator it = rhs.begin();
|
for (typename std::list<T>::const_iterator it = rhs.begin();
|
||||||
@ -241,9 +242,42 @@ 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);
|
||||||
|
for (const auto& element : rhs) {
|
||||||
|
node.push_back(element);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, std::array<T, N>& rhs) {
|
||||||
|
if (!isNodeValid(node)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i = 0u; i < node.size(); ++i) {
|
||||||
|
#if defined(__GNUC__) && __GNUC__ < 4
|
||||||
|
// workaround for GCC 3:
|
||||||
|
rhs[i] = node[i].template as<T>();
|
||||||
|
#else
|
||||||
|
rhs[i] = node[i].as<T>();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool isNodeValid(const Node& node) {
|
||||||
|
return node.IsSequence() && node.size() == N;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// std::pair
|
// std::pair
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
struct convert<std::pair<T, U> > {
|
struct convert<std::pair<T, U>> {
|
||||||
static Node encode(const std::pair<T, U>& rhs) {
|
static Node encode(const std::pair<T, U>& rhs) {
|
||||||
Node node(NodeType::Sequence);
|
Node node(NodeType::Sequence);
|
||||||
node.push_back(rhs.first);
|
node.push_back(rhs.first);
|
||||||
|
|||||||
@ -32,7 +32,7 @@ struct get_idx<Key,
|
|||||||
|
|
||||||
static node* get(std::vector<node*>& sequence, const Key& key,
|
static node* get(std::vector<node*>& sequence, const Key& key,
|
||||||
shared_memory_holder pMemory) {
|
shared_memory_holder pMemory) {
|
||||||
if (key > sequence.size())
|
if (key > sequence.size() || (key > 0 && !sequence[key-1]->is_defined()))
|
||||||
return 0;
|
return 0;
|
||||||
if (key == sequence.size())
|
if (key == sequence.size())
|
||||||
sequence.push_back(&pMemory->create_node());
|
sequence.push_back(&pMemory->create_node());
|
||||||
@ -132,6 +132,14 @@ inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) {
|
|||||||
if (m_type != NodeType::Map)
|
if (m_type != NodeType::Map)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
kv_pairs::iterator it = m_undefinedPairs.begin();
|
||||||
|
while (it != m_undefinedPairs.end()) {
|
||||||
|
kv_pairs::iterator jt = std::next(it);
|
||||||
|
if (it->first->equals(key, pMemory))
|
||||||
|
m_undefinedPairs.erase(it);
|
||||||
|
it = jt;
|
||||||
|
}
|
||||||
|
|
||||||
for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) {
|
for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) {
|
||||||
if (it->first->equals(key, pMemory)) {
|
if (it->first->equals(key, pMemory)) {
|
||||||
m_map.erase(it);
|
m_map.erase(it);
|
||||||
|
|||||||
@ -114,7 +114,7 @@ class YAML_CPP_API node_data {
|
|||||||
mutable std::size_t m_seqSize;
|
mutable std::size_t m_seqSize;
|
||||||
|
|
||||||
// map
|
// map
|
||||||
typedef std::map<node*, node*> node_map;
|
typedef std::vector<std::pair<node*, node*>> node_map;
|
||||||
node_map m_map;
|
node_map m_map;
|
||||||
|
|
||||||
typedef std::pair<node*, node*> kv_pair;
|
typedef std::pair<node*, node*> kv_pair;
|
||||||
|
|||||||
@ -37,7 +37,7 @@ struct node_iterator_value : public std::pair<V*, V*> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<node*> node_seq;
|
typedef std::vector<node*> node_seq;
|
||||||
typedef std::map<node*, node*> node_map;
|
typedef std::vector<std::pair<node*, node*>> node_map;
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
struct node_iterator_type {
|
struct node_iterator_type {
|
||||||
@ -55,7 +55,7 @@ template <typename V>
|
|||||||
class node_iterator_base
|
class node_iterator_base
|
||||||
: public std::iterator<std::forward_iterator_tag, node_iterator_value<V>,
|
: public std::iterator<std::forward_iterator_tag, node_iterator_value<V>,
|
||||||
std::ptrdiff_t, node_iterator_value<V>*,
|
std::ptrdiff_t, node_iterator_value<V>*,
|
||||||
node_iterator_value<V> > {
|
node_iterator_value<V>> {
|
||||||
private:
|
private:
|
||||||
struct enabler {};
|
struct enabler {};
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,6 @@ YAML_CPP_API std::ostream& operator<<(std::ostream& out, const Node& node);
|
|||||||
|
|
||||||
/** Converts the node to a YAML string. */
|
/** Converts the node to a YAML string. */
|
||||||
YAML_CPP_API std::string Dump(const Node& node);
|
YAML_CPP_API std::string Dump(const Node& node);
|
||||||
} // namespace YAML
|
} // namespace YAML
|
||||||
|
|
||||||
#endif // NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|||||||
@ -103,7 +103,7 @@ struct as_if<std::string, S> {
|
|||||||
explicit as_if(const Node& node_) : node(node_) {}
|
explicit as_if(const Node& node_) : node(node_) {}
|
||||||
const Node& node;
|
const Node& node;
|
||||||
|
|
||||||
const std::string operator()(const S& fallback) const {
|
std::string operator()(const S& fallback) const {
|
||||||
if (node.Type() != NodeType::Scalar)
|
if (node.Type() != NodeType::Scalar)
|
||||||
return fallback;
|
return fallback;
|
||||||
return node.Scalar();
|
return node.Scalar();
|
||||||
@ -115,7 +115,7 @@ struct as_if<T, void> {
|
|||||||
explicit as_if(const Node& node_) : node(node_) {}
|
explicit as_if(const Node& node_) : node(node_) {}
|
||||||
const Node& node;
|
const Node& node;
|
||||||
|
|
||||||
const T operator()() const {
|
T operator()() const {
|
||||||
if (!node.m_pNode)
|
if (!node.m_pNode)
|
||||||
throw TypedBadConversion<T>(node.Mark());
|
throw TypedBadConversion<T>(node.Mark());
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ struct as_if<std::string, void> {
|
|||||||
explicit as_if(const Node& node_) : node(node_) {}
|
explicit as_if(const Node& node_) : node(node_) {}
|
||||||
const Node& node;
|
const Node& node;
|
||||||
|
|
||||||
const std::string operator()() const {
|
std::string operator()() const {
|
||||||
if (node.Type() != NodeType::Scalar)
|
if (node.Type() != NodeType::Scalar)
|
||||||
throw TypedBadConversion<std::string>(node.Mark());
|
throw TypedBadConversion<std::string>(node.Mark());
|
||||||
return node.Scalar();
|
return node.Scalar();
|
||||||
|
|||||||
@ -58,7 +58,7 @@ class YAML_CPP_API Node {
|
|||||||
bool IsMap() const { return Type() == NodeType::Map; }
|
bool IsMap() const { return Type() == NodeType::Map; }
|
||||||
|
|
||||||
// bool conversions
|
// bool conversions
|
||||||
YAML_CPP_OPERATOR_BOOL();
|
YAML_CPP_OPERATOR_BOOL()
|
||||||
bool operator!() const { return !IsDefined(); }
|
bool operator!() const { return !IsDefined(); }
|
||||||
|
|
||||||
// access
|
// access
|
||||||
|
|||||||
@ -47,7 +47,7 @@ class YAML_CPP_API Parser : private noncopyable {
|
|||||||
void Load(std::istream& in);
|
void Load(std::istream& in);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the next document by calling events on the {@param eventHandler}.
|
* Handles the next document by calling events on the {@code eventHandler}.
|
||||||
*
|
*
|
||||||
* @throw a ParserException on error.
|
* @throw a ParserException on error.
|
||||||
* @return false if there are no more documents
|
* @return false if there are no more documents
|
||||||
|
|||||||
@ -22,4 +22,4 @@ std::string Dump(const Node& node) {
|
|||||||
emitter << node;
|
emitter << node;
|
||||||
return emitter.c_str();
|
return emitter.c_str();
|
||||||
}
|
}
|
||||||
} // namespace YAML
|
} // namespace YAML
|
||||||
|
|||||||
@ -111,7 +111,7 @@ void EmitFromEvents::BeginNode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) {
|
void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) {
|
||||||
if (!tag.empty() && tag != "?")
|
if (!tag.empty() && tag != "?" && tag != "!")
|
||||||
m_emitter << VerbatimTag(tag);
|
m_emitter << VerbatimTag(tag);
|
||||||
if (anchor)
|
if (anchor)
|
||||||
m_emitter << Anchor(ToString(anchor));
|
m_emitter << Anchor(ToString(anchor));
|
||||||
|
|||||||
@ -124,7 +124,8 @@ void EmitterState::StartedScalar() {
|
|||||||
void EmitterState::StartedGroup(GroupType::value type) {
|
void EmitterState::StartedGroup(GroupType::value type) {
|
||||||
StartedNode();
|
StartedNode();
|
||||||
|
|
||||||
const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.back()->indent);
|
const std::size_t lastGroupIndent =
|
||||||
|
(m_groups.empty() ? 0 : m_groups.back()->indent);
|
||||||
m_curIndent += lastGroupIndent;
|
m_curIndent += lastGroupIndent;
|
||||||
|
|
||||||
// TODO: Create move constructors for settings types to simplify transfer
|
// TODO: Create move constructors for settings types to simplify transfer
|
||||||
@ -193,7 +194,7 @@ FlowType::value EmitterState::CurGroupFlowType() const {
|
|||||||
return m_groups.empty() ? FlowType::NoType : m_groups.back()->flowType;
|
return m_groups.empty() ? FlowType::NoType : m_groups.back()->flowType;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EmitterState::CurGroupIndent() const {
|
std::size_t EmitterState::CurGroupIndent() const {
|
||||||
return m_groups.empty() ? 0 : m_groups.back()->indent;
|
return m_groups.empty() ? 0 : m_groups.back()->indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +206,7 @@ bool EmitterState::CurGroupLongKey() const {
|
|||||||
return m_groups.empty() ? false : m_groups.back()->longKey;
|
return m_groups.empty() ? false : m_groups.back()->longKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EmitterState::LastIndent() const {
|
std::size_t EmitterState::LastIndent() const {
|
||||||
if (m_groups.size() <= 1) {
|
if (m_groups.size() <= 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -347,15 +348,16 @@ bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetFloatPrecision(int value, FmtScope::value scope) {
|
bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) {
|
||||||
if (value < 0 || value > std::numeric_limits<float>::digits10 + 1)
|
if (value > std::numeric_limits<float>::digits10 + 1)
|
||||||
return false;
|
return false;
|
||||||
_Set(m_floatPrecision, value, scope);
|
_Set(m_floatPrecision, value, scope);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetDoublePrecision(int value, FmtScope::value scope) {
|
bool EmitterState::SetDoublePrecision(std::size_t value,
|
||||||
if (value < 0 || value > std::numeric_limits<double>::digits10 + 1)
|
FmtScope::value scope) {
|
||||||
|
if (value > std::numeric_limits<double>::digits10 + 1)
|
||||||
return false;
|
return false;
|
||||||
_Set(m_doublePrecision, value, scope);
|
_Set(m_doublePrecision, value, scope);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -58,12 +58,12 @@ class EmitterState {
|
|||||||
|
|
||||||
GroupType::value CurGroupType() const;
|
GroupType::value CurGroupType() const;
|
||||||
FlowType::value CurGroupFlowType() const;
|
FlowType::value CurGroupFlowType() const;
|
||||||
int CurGroupIndent() const;
|
std::size_t CurGroupIndent() const;
|
||||||
std::size_t CurGroupChildCount() const;
|
std::size_t CurGroupChildCount() const;
|
||||||
bool CurGroupLongKey() const;
|
bool CurGroupLongKey() const;
|
||||||
|
|
||||||
int LastIndent() const;
|
std::size_t LastIndent() const;
|
||||||
int CurIndent() const { return m_curIndent; }
|
std::size_t CurIndent() const { return m_curIndent; }
|
||||||
bool HasAnchor() const { return m_hasAnchor; }
|
bool HasAnchor() const { return m_hasAnchor; }
|
||||||
bool HasTag() const { return m_hasTag; }
|
bool HasTag() const { return m_hasTag; }
|
||||||
bool HasBegunNode() const {
|
bool HasBegunNode() const {
|
||||||
@ -95,12 +95,12 @@ class EmitterState {
|
|||||||
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
|
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
|
||||||
|
|
||||||
bool SetIndent(std::size_t value, FmtScope::value scope);
|
bool SetIndent(std::size_t value, FmtScope::value scope);
|
||||||
int GetIndent() const { return m_indent.get(); }
|
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::value scope);
|
||||||
int GetPreCommentIndent() const { return m_preCommentIndent.get(); }
|
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::value scope);
|
||||||
int GetPostCommentIndent() const { return m_postCommentIndent.get(); }
|
std::size_t GetPostCommentIndent() const { return m_postCommentIndent.get(); }
|
||||||
|
|
||||||
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
|
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
|
||||||
FmtScope::value scope);
|
FmtScope::value scope);
|
||||||
@ -109,9 +109,9 @@ class EmitterState {
|
|||||||
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
|
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
|
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
|
||||||
|
|
||||||
bool SetFloatPrecision(int value, FmtScope::value scope);
|
bool SetFloatPrecision(std::size_t value, FmtScope::value scope);
|
||||||
std::size_t GetFloatPrecision() const { return m_floatPrecision.get(); }
|
std::size_t GetFloatPrecision() const { return m_floatPrecision.get(); }
|
||||||
bool SetDoublePrecision(int value, FmtScope::value scope);
|
bool SetDoublePrecision(std::size_t value, FmtScope::value scope);
|
||||||
std::size_t GetDoublePrecision() const { return m_doublePrecision.get(); }
|
std::size_t GetDoublePrecision() const { return m_doublePrecision.get(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -137,8 +137,8 @@ class EmitterState {
|
|||||||
Setting<EMITTER_MANIP> m_seqFmt;
|
Setting<EMITTER_MANIP> m_seqFmt;
|
||||||
Setting<EMITTER_MANIP> m_mapFmt;
|
Setting<EMITTER_MANIP> m_mapFmt;
|
||||||
Setting<EMITTER_MANIP> m_mapKeyFmt;
|
Setting<EMITTER_MANIP> m_mapKeyFmt;
|
||||||
Setting<int> m_floatPrecision;
|
Setting<std::size_t> m_floatPrecision;
|
||||||
Setting<int> m_doublePrecision;
|
Setting<std::size_t> m_doublePrecision;
|
||||||
|
|
||||||
SettingChanges m_modifiedSettings;
|
SettingChanges m_modifiedSettings;
|
||||||
SettingChanges m_globalModifiedSettings;
|
SettingChanges m_globalModifiedSettings;
|
||||||
@ -149,7 +149,7 @@ class EmitterState {
|
|||||||
|
|
||||||
GroupType::value type;
|
GroupType::value type;
|
||||||
FlowType::value flowType;
|
FlowType::value flowType;
|
||||||
int indent;
|
std::size_t indent;
|
||||||
std::size_t childCount;
|
std::size_t childCount;
|
||||||
bool longKey;
|
bool longKey;
|
||||||
|
|
||||||
|
|||||||
@ -354,7 +354,7 @@ bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
||||||
int indent) {
|
std::size_t indent) {
|
||||||
out << "|\n";
|
out << "|\n";
|
||||||
out << IndentTo(indent);
|
out << IndentTo(indent);
|
||||||
int codePoint;
|
int codePoint;
|
||||||
@ -380,6 +380,8 @@ bool WriteChar(ostream_wrapper& out, char ch) {
|
|||||||
out << "\"\\n\"";
|
out << "\"\\n\"";
|
||||||
} else if (ch == '\b') {
|
} else if (ch == '\b') {
|
||||||
out << "\"\\b\"";
|
out << "\"\\b\"";
|
||||||
|
} else if (ch == '\\') {
|
||||||
|
out << "\"\\\\\"";
|
||||||
} else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ') {
|
} else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ') {
|
||||||
out << "\"" << ch << "\"";
|
out << "\"" << ch << "\"";
|
||||||
} else {
|
} else {
|
||||||
@ -391,7 +393,7 @@ bool WriteChar(ostream_wrapper& out, char ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool WriteComment(ostream_wrapper& out, const std::string& str,
|
bool WriteComment(ostream_wrapper& out, const std::string& str,
|
||||||
int postCommentIndent) {
|
std::size_t postCommentIndent) {
|
||||||
const std::size_t curIndent = out.col();
|
const std::size_t curIndent = out.col();
|
||||||
out << "#" << Indentation(postCommentIndent);
|
out << "#" << Indentation(postCommentIndent);
|
||||||
out.set_comment();
|
out.set_comment();
|
||||||
|
|||||||
@ -34,10 +34,10 @@ bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str);
|
|||||||
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
|
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
|
||||||
bool escapeNonAscii);
|
bool escapeNonAscii);
|
||||||
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
||||||
int indent);
|
std::size_t indent);
|
||||||
bool WriteChar(ostream_wrapper& out, char ch);
|
bool WriteChar(ostream_wrapper& out, char ch);
|
||||||
bool WriteComment(ostream_wrapper& out, const std::string& str,
|
bool WriteComment(ostream_wrapper& out, const std::string& str,
|
||||||
int postCommentIndent);
|
std::size_t postCommentIndent);
|
||||||
bool WriteAlias(ostream_wrapper& out, const std::string& str);
|
bool WriteAlias(ostream_wrapper& out, const std::string& str);
|
||||||
bool WriteAnchor(ostream_wrapper& out, const std::string& str);
|
bool WriteAnchor(ostream_wrapper& out, const std::string& str);
|
||||||
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim);
|
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim);
|
||||||
|
|||||||
19
src/exceptions.cpp
Normal file
19
src/exceptions.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "yaml-cpp/exceptions.h"
|
||||||
|
|
||||||
|
namespace YAML {
|
||||||
|
|
||||||
|
// These destructors are defined out-of-line so the vtable is only emitted once.
|
||||||
|
Exception::~Exception() noexcept {}
|
||||||
|
ParserException::~ParserException() noexcept {}
|
||||||
|
RepresentationException::~RepresentationException() noexcept {}
|
||||||
|
InvalidScalar::~InvalidScalar() noexcept {}
|
||||||
|
KeyNotFound::~KeyNotFound() noexcept {}
|
||||||
|
InvalidNode::~InvalidNode() noexcept {}
|
||||||
|
BadConversion::~BadConversion() noexcept {}
|
||||||
|
BadDereference::~BadDereference() noexcept {}
|
||||||
|
BadSubscript::~BadSubscript() noexcept {}
|
||||||
|
BadPushback::~BadPushback() noexcept {}
|
||||||
|
BadInsert::~BadInsert() noexcept {}
|
||||||
|
EmitterException::~EmitterException() noexcept {}
|
||||||
|
BadFile::~BadFile() noexcept {}
|
||||||
|
}
|
||||||
@ -256,9 +256,10 @@ void node_data::reset_map() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void node_data::insert_map_pair(node& key, node& value) {
|
void node_data::insert_map_pair(node& key, node& value) {
|
||||||
m_map[&key] = &value;
|
m_map.emplace_back(&key, &value);
|
||||||
|
|
||||||
if (!key.is_defined() || !value.is_defined())
|
if (!key.is_defined() || !value.is_defined())
|
||||||
m_undefinedPairs.push_back(kv_pair(&key, &value));
|
m_undefinedPairs.emplace_back(&key, &value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_data::convert_to_map(shared_memory_holder pMemory) {
|
void node_data::convert_to_map(shared_memory_holder pMemory) {
|
||||||
|
|||||||
@ -48,9 +48,8 @@ void NodeBuilder::OnScalar(const Mark& mark, const std::string& tag,
|
|||||||
Pop();
|
Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBuilder::OnSequenceStart(const Mark& mark,
|
void NodeBuilder::OnSequenceStart(const Mark& mark, const std::string& tag,
|
||||||
const std::string& tag, anchor_t anchor,
|
anchor_t anchor, EmitterStyle::value style) {
|
||||||
EmitterStyle::value style) {
|
|
||||||
detail::node& node = Push(mark, anchor);
|
detail::node& node = Push(mark, anchor);
|
||||||
node.set_tag(tag);
|
node.set_tag(tag);
|
||||||
node.set_type(NodeType::Sequence);
|
node.set_type(NodeType::Sequence);
|
||||||
|
|||||||
@ -4,6 +4,7 @@ namespace YAML {
|
|||||||
_Null Null;
|
_Null Null;
|
||||||
|
|
||||||
bool IsNullString(const std::string& str) {
|
bool IsNullString(const std::string& str) {
|
||||||
return str.empty() || str == "~" || str == "null" || str == "Null" || str == "NULL";
|
return str.empty() || str == "~" || str == "null" || str == "Null" ||
|
||||||
|
str == "NULL";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,29 +22,21 @@ class ptr_vector : private YAML::noncopyable {
|
|||||||
public:
|
public:
|
||||||
ptr_vector() {}
|
ptr_vector() {}
|
||||||
|
|
||||||
void clear() {
|
void clear() { m_data.clear(); }
|
||||||
m_data.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t size() const { return m_data.size(); }
|
std::size_t size() const { return m_data.size(); }
|
||||||
bool empty() const { return m_data.empty(); }
|
bool empty() const { return m_data.empty(); }
|
||||||
|
|
||||||
void push_back(std::unique_ptr<T>&& t) {
|
void push_back(std::unique_ptr<T>&& t) { m_data.push_back(std::move(t)); }
|
||||||
m_data.push_back(std::move(t));
|
|
||||||
}
|
|
||||||
T& operator[](std::size_t i) { return *m_data[i]; }
|
T& operator[](std::size_t i) { return *m_data[i]; }
|
||||||
const T& operator[](std::size_t i) const { return *m_data[i]; }
|
const T& operator[](std::size_t i) const { return *m_data[i]; }
|
||||||
|
|
||||||
T& back() {
|
T& back() { return *(m_data.back().get()); }
|
||||||
return *(m_data.back().get());
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& back() const {
|
const T& back() const { return *(m_data.back().get()); }
|
||||||
return *(m_data.back().get());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<T>> m_data;
|
std::vector<std::unique_ptr<T>> m_data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "yaml-cpp/dll.h"
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
class Stream;
|
class Stream;
|
||||||
|
|
||||||
@ -26,7 +28,7 @@ enum REGEX_OP {
|
|||||||
// simplified regular expressions
|
// simplified regular expressions
|
||||||
// . Only straightforward matches (no repeated characters)
|
// . Only straightforward matches (no repeated characters)
|
||||||
// . Only matches from start of string
|
// . Only matches from start of string
|
||||||
class RegEx {
|
class YAML_CPP_API RegEx {
|
||||||
public:
|
public:
|
||||||
RegEx();
|
RegEx();
|
||||||
RegEx(char ch);
|
RegEx(char ch);
|
||||||
@ -34,10 +36,10 @@ class RegEx {
|
|||||||
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
|
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
|
||||||
~RegEx() {}
|
~RegEx() {}
|
||||||
|
|
||||||
friend RegEx operator!(const RegEx& ex);
|
friend YAML_CPP_API RegEx operator!(const RegEx& ex);
|
||||||
friend RegEx operator||(const RegEx& ex1, const RegEx& ex2);
|
friend YAML_CPP_API RegEx operator||(const RegEx& ex1, const RegEx& ex2);
|
||||||
friend RegEx operator&&(const RegEx& ex1, const RegEx& ex2);
|
friend YAML_CPP_API RegEx operator&&(const RegEx& ex1, const RegEx& ex2);
|
||||||
friend RegEx operator+(const RegEx& ex1, const RegEx& ex2);
|
friend YAML_CPP_API RegEx operator+(const RegEx& ex1, const RegEx& ex2);
|
||||||
|
|
||||||
bool Matches(char ch) const;
|
bool Matches(char ch) const;
|
||||||
bool Matches(const std::string& str) const;
|
bool Matches(const std::string& str) const;
|
||||||
|
|||||||
@ -65,9 +65,9 @@ void Scanner::EnsureTokensInQueue() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no token? maybe we've actually finished
|
// no token? maybe we've actually finished
|
||||||
if (m_endedStream) {
|
if (m_endedStream) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// no? then scan...
|
// no? then scan...
|
||||||
ScanNextToken();
|
ScanNextToken();
|
||||||
|
|||||||
@ -46,6 +46,12 @@ TEST_F(EmitterTest, SimpleScalar) {
|
|||||||
ExpectEmit("Hello, World!");
|
ExpectEmit("Hello, World!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(EmitterTest, SimpleQuotedScalar) {
|
||||||
|
Node n(Load("\"test\""));
|
||||||
|
out << n;
|
||||||
|
ExpectEmit("test");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(EmitterTest, SimpleSeq) {
|
TEST_F(EmitterTest, SimpleSeq) {
|
||||||
out << BeginSeq;
|
out << BeginSeq;
|
||||||
out << "eggs";
|
out << "eggs";
|
||||||
@ -970,6 +976,14 @@ TEST_F(EmitterTest, ValueOfDoubleQuote) {
|
|||||||
ExpectEmit("foo: \"\\\"\"");
|
ExpectEmit("foo: \"\\\"\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(EmitterTest, ValueOfBackslash) {
|
||||||
|
out << YAML::BeginMap;
|
||||||
|
out << YAML::Key << "foo" << YAML::Value << '\\';
|
||||||
|
out << YAML::EndMap;
|
||||||
|
|
||||||
|
ExpectEmit("foo: \"\\\\\"");
|
||||||
|
}
|
||||||
|
|
||||||
class EmitterErrorTest : public ::testing::Test {
|
class EmitterErrorTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void ExpectEmitError(const std::string& expectedError) {
|
void ExpectEmitError(const std::string& expectedError) {
|
||||||
|
|||||||
@ -12,6 +12,14 @@
|
|||||||
using ::testing::AnyOf;
|
using ::testing::AnyOf;
|
||||||
using ::testing::Eq;
|
using ::testing::Eq;
|
||||||
|
|
||||||
|
#define EXPECT_THROW_REPRESENTATION_EXCEPTION(statement, message) \
|
||||||
|
ASSERT_THROW(statement, RepresentationException); \
|
||||||
|
try { \
|
||||||
|
statement; \
|
||||||
|
} catch (const RepresentationException& e) { \
|
||||||
|
EXPECT_EQ(e.msg, message); \
|
||||||
|
}
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
namespace {
|
namespace {
|
||||||
TEST(NodeTest, SimpleScalar) {
|
TEST(NodeTest, SimpleScalar) {
|
||||||
@ -80,6 +88,24 @@ TEST(NodeTest, MapWithUndefinedValues) {
|
|||||||
EXPECT_EQ(2, node.size());
|
EXPECT_EQ(2, node.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(NodeTest, SeqIntoMap) {
|
||||||
|
Node node;
|
||||||
|
node[0] = "test";
|
||||||
|
node[1];
|
||||||
|
node[2] = "value";
|
||||||
|
EXPECT_TRUE(node.IsMap());
|
||||||
|
EXPECT_EQ("test", node[0].as<std::string>());
|
||||||
|
EXPECT_EQ("value", node[2].as<std::string>());
|
||||||
|
EXPECT_EQ(2, node.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(NodeTest, RemoveUnassignedNode) {
|
||||||
|
Node node(NodeType::Map);
|
||||||
|
node["key"];
|
||||||
|
node.remove("key");
|
||||||
|
EXPECT_EQ(0, node.size());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(NodeTest, MapForceInsert) {
|
TEST(NodeTest, MapForceInsert) {
|
||||||
Node node;
|
Node node;
|
||||||
Node k1("k1");
|
Node k1("k1");
|
||||||
@ -95,8 +121,8 @@ TEST(NodeTest, MapForceInsert) {
|
|||||||
|
|
||||||
node.force_insert(k2, v2);
|
node.force_insert(k2, v2);
|
||||||
EXPECT_EQ("v1", node["k1"].as<std::string>());
|
EXPECT_EQ("v1", node["k1"].as<std::string>());
|
||||||
EXPECT_EQ("v2", node["k2"].as<std::string>());
|
EXPECT_EQ("v1", node["k2"].as<std::string>());
|
||||||
EXPECT_EQ(2, node.size());
|
EXPECT_EQ(3, node.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NodeTest, UndefinedConstNodeWithFallback) {
|
TEST(NodeTest, UndefinedConstNodeWithFallback) {
|
||||||
@ -124,7 +150,7 @@ TEST(NodeTest, ConstIteratorOnConstUndefinedNode) {
|
|||||||
std::size_t count = 0;
|
std::size_t count = 0;
|
||||||
for (const_iterator it = undefinedCn.begin(); it != undefinedCn.end(); ++it) {
|
for (const_iterator it = undefinedCn.begin(); it != undefinedCn.end(); ++it) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
EXPECT_EQ(0, count);
|
EXPECT_EQ(0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +162,8 @@ TEST(NodeTest, IteratorOnConstUndefinedNode) {
|
|||||||
Node& nonConstUndefinedNode = const_cast<Node&>(undefinedCn);
|
Node& nonConstUndefinedNode = const_cast<Node&>(undefinedCn);
|
||||||
|
|
||||||
std::size_t count = 0;
|
std::size_t count = 0;
|
||||||
for (iterator it = nonConstUndefinedNode.begin(); it != nonConstUndefinedNode.end(); ++it) {
|
for (iterator it = nonConstUndefinedNode.begin();
|
||||||
|
it != nonConstUndefinedNode.end(); ++it) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
EXPECT_EQ(0, count);
|
EXPECT_EQ(0, count);
|
||||||
@ -154,6 +181,22 @@ TEST(NodeTest, SimpleSubkeys) {
|
|||||||
EXPECT_EQ("monkey", node["username"].as<std::string>());
|
EXPECT_EQ("monkey", node["username"].as<std::string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(NodeTest, StdArray) {
|
||||||
|
std::array<int, 5> evens{{2, 4, 6, 8, 10}};
|
||||||
|
Node node;
|
||||||
|
node["evens"] = evens;
|
||||||
|
std::array<int, 5> actualEvens = node["evens"].as<std::array<int, 5>>();
|
||||||
|
EXPECT_EQ(evens, actualEvens);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(NodeTest, StdArrayWrongSize) {
|
||||||
|
std::array<int, 3> evens{{2, 4, 6}};
|
||||||
|
Node node;
|
||||||
|
node["evens"] = evens;
|
||||||
|
EXPECT_THROW_REPRESENTATION_EXCEPTION(
|
||||||
|
(node["evens"].as<std::array<int, 5>>()), ErrorMsg::BAD_CONVERSION);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(NodeTest, StdVector) {
|
TEST(NodeTest, StdVector) {
|
||||||
std::vector<int> primes;
|
std::vector<int> primes;
|
||||||
primes.push_back(2);
|
primes.push_back(2);
|
||||||
@ -165,7 +208,7 @@ TEST(NodeTest, StdVector) {
|
|||||||
|
|
||||||
Node node;
|
Node node;
|
||||||
node["primes"] = primes;
|
node["primes"] = primes;
|
||||||
EXPECT_EQ(primes, node["primes"].as<std::vector<int> >());
|
EXPECT_EQ(primes, node["primes"].as<std::vector<int>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NodeTest, StdList) {
|
TEST(NodeTest, StdList) {
|
||||||
@ -179,7 +222,7 @@ TEST(NodeTest, StdList) {
|
|||||||
|
|
||||||
Node node;
|
Node node;
|
||||||
node["primes"] = primes;
|
node["primes"] = primes;
|
||||||
EXPECT_EQ(primes, node["primes"].as<std::list<int> >());
|
EXPECT_EQ(primes, node["primes"].as<std::list<int>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NodeTest, StdMap) {
|
TEST(NodeTest, StdMap) {
|
||||||
@ -192,7 +235,7 @@ TEST(NodeTest, StdMap) {
|
|||||||
|
|
||||||
Node node;
|
Node node;
|
||||||
node["squares"] = squares;
|
node["squares"] = squares;
|
||||||
std::map<int, int> actualSquares = node["squares"].as<std::map<int, int> >();
|
std::map<int, int> actualSquares = node["squares"].as<std::map<int, int>>();
|
||||||
EXPECT_EQ(squares, actualSquares);
|
EXPECT_EQ(squares, actualSquares);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +247,7 @@ TEST(NodeTest, StdPair) {
|
|||||||
Node node;
|
Node node;
|
||||||
node["pair"] = p;
|
node["pair"] = p;
|
||||||
std::pair<int, std::string> actualP =
|
std::pair<int, std::string> actualP =
|
||||||
node["pair"].as<std::pair<int, std::string> >();
|
node["pair"].as<std::pair<int, std::string>>();
|
||||||
EXPECT_EQ(p, actualP);
|
EXPECT_EQ(p, actualP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "yaml-cpp/emitterstyle.h"
|
#include "yaml-cpp/emitterstyle.h"
|
||||||
#include "yaml-cpp/eventhandler.h"
|
#include "yaml-cpp/eventhandler.h"
|
||||||
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
|
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
class NullEventHandler : public YAML::EventHandler {
|
class NullEventHandler : public YAML::EventHandler {
|
||||||
public:
|
public:
|
||||||
typedef YAML::Mark Mark;
|
typedef YAML::Mark Mark;
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
prefix=@CMAKE_INSTALL_PREFIX@
|
libdir=@LIB_INSTALL_DIR@
|
||||||
exec_prefix=@CMAKE_INSTALL_PREFIX@
|
includedir=@INCLUDE_INSTALL_ROOT_DIR@
|
||||||
libdir=${prefix}/@LIB_INSTALL_DIR@
|
|
||||||
includedir=${prefix}/@INCLUDE_INSTALL_ROOT_DIR@
|
|
||||||
|
|
||||||
Name: Yaml-cpp
|
Name: Yaml-cpp
|
||||||
Description: A YAML parser and emitter for C++
|
Description: A YAML parser and emitter for C++
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user