mirror of
https://github.com/RPCS3/yaml-cpp.git
synced 2026-07-25 20:55:22 -04:00
Compare commits
1 Commits
yaml-cpp-0.9.0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 51a5d623e3 |
@@ -14,6 +14,9 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
|
[[noreturn]] extern void throw_bad_subscript(const YAML::Mark& mark);
|
||||||
|
[[noreturn]] extern void throw_bad_insert();
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template <typename Key, typename Enable = void>
|
template <typename Key, typename Enable = void>
|
||||||
struct get_idx {
|
struct get_idx {
|
||||||
@@ -128,7 +131,7 @@ inline node* node_data::get(const Key& key,
|
|||||||
return pNode;
|
return pNode;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
case NodeType::Scalar:
|
case NodeType::Scalar:
|
||||||
throw BadSubscript(m_mark, key);
|
throw_bad_subscript(m_mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
|
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
|
||||||
@@ -154,7 +157,7 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
|
|||||||
convert_to_map(pMemory);
|
convert_to_map(pMemory);
|
||||||
break;
|
break;
|
||||||
case NodeType::Scalar:
|
case NodeType::Scalar:
|
||||||
throw BadSubscript(m_mark, key);
|
throw_bad_subscript(m_mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
|
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
|
||||||
@@ -213,7 +216,7 @@ inline void node_data::force_insert(const Key& key, const Value& value,
|
|||||||
convert_to_map(pMemory);
|
convert_to_map(pMemory);
|
||||||
break;
|
break;
|
||||||
case NodeType::Scalar:
|
case NodeType::Scalar:
|
||||||
throw BadInsert();
|
throw_bad_insert();
|
||||||
}
|
}
|
||||||
|
|
||||||
node& k = convert_to_node(key, pMemory);
|
node& k = convert_to_node(key, pMemory);
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
|
[[noreturn]] extern void throw_invalid_node(const std::string& key);
|
||||||
|
[[noreturn]] extern void throw_bad_conversion(const YAML::Mark& mark);
|
||||||
inline Node::Node()
|
inline Node::Node()
|
||||||
: m_isValid(true), m_invalidKey{}, m_pMemory(nullptr), m_pNode(nullptr) {}
|
: m_isValid(true), m_invalidKey{}, m_pMemory(nullptr), m_pNode(nullptr) {}
|
||||||
|
|
||||||
@@ -57,7 +59,7 @@ inline Node::~Node() = default;
|
|||||||
|
|
||||||
inline void Node::EnsureNodeExists() const {
|
inline void Node::EnsureNodeExists() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
if (!m_pNode) {
|
if (!m_pNode) {
|
||||||
m_pMemory.reset(new detail::memory_holder);
|
m_pMemory.reset(new detail::memory_holder);
|
||||||
m_pNode = &m_pMemory->create_node();
|
m_pNode = &m_pMemory->create_node();
|
||||||
@@ -74,14 +76,14 @@ inline bool Node::IsDefined() const {
|
|||||||
|
|
||||||
inline Mark Node::Mark() const {
|
inline Mark Node::Mark() const {
|
||||||
if (!m_isValid) {
|
if (!m_isValid) {
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
}
|
}
|
||||||
return m_pNode ? m_pNode->mark() : Mark::null_mark();
|
return m_pNode ? m_pNode->mark() : Mark::null_mark();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NodeType::value Node::Type() const {
|
inline NodeType::value Node::Type() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->type() : NodeType::Null;
|
return m_pNode ? m_pNode->type() : NodeType::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,12 +127,12 @@ struct as_if<T, void> {
|
|||||||
|
|
||||||
T operator()() const {
|
T operator()() const {
|
||||||
if (!node.m_pNode) // no fallback
|
if (!node.m_pNode) // no fallback
|
||||||
throw InvalidNode(node.m_invalidKey);
|
throw_invalid_node(node.m_invalidKey);
|
||||||
|
|
||||||
T t;
|
T t;
|
||||||
if (convert<T>::decode(node, t))
|
if (convert<T>::decode(node, t))
|
||||||
return t;
|
return t;
|
||||||
throw TypedBadConversion<T>(node.Mark());
|
throw_bad_conversion(node.Mark()); // <T>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -141,11 +143,11 @@ struct as_if<std::string, void> {
|
|||||||
|
|
||||||
std::string operator()() const {
|
std::string operator()() const {
|
||||||
if (node.Type() == NodeType::Undefined) // no fallback
|
if (node.Type() == NodeType::Undefined) // no fallback
|
||||||
throw InvalidNode(node.m_invalidKey);
|
throw_invalid_node(node.m_invalidKey);
|
||||||
if (node.Type() == NodeType::Null)
|
if (node.Type() == NodeType::Null)
|
||||||
return "null";
|
return "null";
|
||||||
if (node.Type() != NodeType::Scalar)
|
if (node.Type() != NodeType::Scalar)
|
||||||
throw TypedBadConversion<std::string>(node.Mark());
|
throw_bad_conversion(node.Mark()); // <std::string>
|
||||||
return node.Scalar();
|
return node.Scalar();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -154,7 +156,7 @@ struct as_if<std::string, void> {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline T Node::as() const {
|
inline T Node::as() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
return as_if<T, void>(*this)();
|
return as_if<T, void>(*this)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,13 +169,13 @@ inline T Node::as(const S& fallback) const {
|
|||||||
|
|
||||||
inline const std::string& Node::Scalar() const {
|
inline const std::string& Node::Scalar() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar();
|
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string& Node::Tag() const {
|
inline const std::string& Node::Tag() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar();
|
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +186,7 @@ inline void Node::SetTag(const std::string& tag) {
|
|||||||
|
|
||||||
inline EmitterStyle::value Node::Style() const {
|
inline EmitterStyle::value Node::Style() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->style() : EmitterStyle::Default;
|
return m_pNode ? m_pNode->style() : EmitterStyle::Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +198,7 @@ inline void Node::SetStyle(EmitterStyle::value style) {
|
|||||||
// assignment
|
// assignment
|
||||||
inline bool Node::is(const Node& rhs) const {
|
inline bool Node::is(const Node& rhs) const {
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
if (!m_pNode || !rhs.m_pNode)
|
if (!m_pNode || !rhs.m_pNode)
|
||||||
return false;
|
return false;
|
||||||
return m_pNode->is(*rhs.m_pNode);
|
return m_pNode->is(*rhs.m_pNode);
|
||||||
@@ -217,7 +219,7 @@ inline Node& Node::operator=(const Node& rhs) {
|
|||||||
|
|
||||||
inline void Node::reset(const YAML::Node& rhs) {
|
inline void Node::reset(const YAML::Node& rhs) {
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
m_pMemory = rhs.m_pMemory;
|
m_pMemory = rhs.m_pMemory;
|
||||||
m_pNode = rhs.m_pNode;
|
m_pNode = rhs.m_pNode;
|
||||||
}
|
}
|
||||||
@@ -225,7 +227,7 @@ inline void Node::reset(const YAML::Node& rhs) {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Node::Assign(const T& rhs) {
|
inline void Node::Assign(const T& rhs) {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
AssignData(convert<T>::encode(rhs));
|
AssignData(convert<T>::encode(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +257,7 @@ inline void Node::AssignData(const Node& rhs) {
|
|||||||
|
|
||||||
inline void Node::AssignNode(const Node& rhs) {
|
inline void Node::AssignNode(const Node& rhs) {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
rhs.EnsureNodeExists();
|
rhs.EnsureNodeExists();
|
||||||
|
|
||||||
if (!m_pNode) {
|
if (!m_pNode) {
|
||||||
@@ -272,7 +274,7 @@ inline void Node::AssignNode(const Node& rhs) {
|
|||||||
// size/iterator
|
// size/iterator
|
||||||
inline std::size_t Node::size() const {
|
inline std::size_t Node::size() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->size() : 0;
|
return m_pNode ? m_pNode->size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +307,7 @@ inline iterator Node::end() {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Node::push_back(const T& rhs) {
|
inline void Node::push_back(const T& rhs) {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
throw_invalid_node(m_invalidKey);
|
||||||
push_back(Node(rhs));
|
push_back(Node(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,4 +17,24 @@ BadPushback::~BadPushback() YAML_CPP_NOEXCEPT = default;
|
|||||||
BadInsert::~BadInsert() YAML_CPP_NOEXCEPT = default;
|
BadInsert::~BadInsert() YAML_CPP_NOEXCEPT = default;
|
||||||
EmitterException::~EmitterException() YAML_CPP_NOEXCEPT = default;
|
EmitterException::~EmitterException() YAML_CPP_NOEXCEPT = default;
|
||||||
BadFile::~BadFile() YAML_CPP_NOEXCEPT = default;
|
BadFile::~BadFile() YAML_CPP_NOEXCEPT = default;
|
||||||
|
|
||||||
|
[[noreturn]] void throw_bad_subscript(const YAML::Mark& mark)
|
||||||
|
{
|
||||||
|
throw BadSubscript(mark, std::string{});
|
||||||
|
}
|
||||||
|
|
||||||
|
[[noreturn]] void throw_invalid_node(const std::string& key)
|
||||||
|
{
|
||||||
|
throw InvalidNode(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[noreturn]] void throw_bad_conversion(const YAML::Mark& mark)
|
||||||
|
{
|
||||||
|
throw BadConversion(mark);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[noreturn]] void throw_bad_insert()
|
||||||
|
{
|
||||||
|
throw BadInsert();
|
||||||
|
}
|
||||||
} // namespace YAML
|
} // namespace YAML
|
||||||
|
|||||||
Reference in New Issue
Block a user