Merge branch 'master' into 393-containers
This commit is contained in:
commit
ee87681f96
@ -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
|
||||||
|
|||||||
@ -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;
|
||||||
@ -163,7 +165,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;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -241,6 +242,40 @@ struct convert<std::list<T,A> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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> > {
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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) {
|
||||||
@ -154,6 +162,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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user