diff options
Diffstat (limited to 'src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node')
13 files changed, 429 insertions, 311 deletions
diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/convert.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/convert.h index 45a878ab0c..d0eb450f73 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/convert.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/convert.h @@ -8,12 +8,20 @@ #endif #include <array> +#include <cmath> #include <limits> #include <list> #include <map> +#include <unordered_map> #include <sstream> +#include <type_traits> +#include <valarray> #include <vector> +#if __cplusplus >= 201703L +#include <string_view> +#endif + #include "yaml-cpp/binary.h" #include "yaml-cpp/node/impl.h" #include "yaml-cpp/node/iterator.h" @@ -21,6 +29,7 @@ #include "yaml-cpp/node/type.h" #include "yaml-cpp/null.h" + namespace YAML { class Binary; struct _Null; @@ -71,14 +80,33 @@ 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 Node encode(const char* rhs) { return Node(rhs); } +}; + +template <> +struct convert<char*> { + static Node encode(const char* rhs) { return Node(rhs); } }; template <std::size_t N> -struct convert<const char[N]> { - static Node encode(const char(&rhs)[N]) { return Node(rhs); } +struct convert<char[N]> { + static Node encode(const char* rhs) { return Node(rhs); } }; +#if __cplusplus >= 201703L +template <> +struct convert<std::string_view> { + static Node encode(std::string_view rhs) { return Node(std::string(rhs)); } + + static bool decode(const Node& node, std::string_view& rhs) { + if (!node.IsScalar()) + return false; + rhs = node.Scalar(); + return true; + } +}; +#endif + template <> struct convert<_Null> { static Node encode(const _Null& /* rhs */) { return Node(); } @@ -88,42 +116,98 @@ struct convert<_Null> { } }; -#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \ - template <> \ - struct convert<type> { \ - static Node encode(const type& rhs) { \ - std::stringstream stream; \ - stream.precision(std::numeric_limits<type>::digits10 + 1); \ - stream << rhs; \ - return Node(stream.str()); \ - } \ - \ - static bool decode(const Node& node, type& rhs) { \ - if (node.Type() != NodeType::Scalar) \ - return false; \ - const std::string& input = node.Scalar(); \ - std::stringstream stream(input); \ - stream.unsetf(std::ios::dec); \ - if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) \ - return true; \ - if (std::numeric_limits<type>::has_infinity) { \ - if (conversion::IsInfinity(input)) { \ - rhs = std::numeric_limits<type>::infinity(); \ - return true; \ - } else if (conversion::IsNegativeInfinity(input)) { \ - rhs = negative_op std::numeric_limits<type>::infinity(); \ - return true; \ - } \ - } \ - \ - if (std::numeric_limits<type>::has_quiet_NaN && \ - conversion::IsNaN(input)) { \ - rhs = std::numeric_limits<type>::quiet_NaN(); \ - return true; \ - } \ - \ - return false; \ - } \ +namespace conversion { +template <typename T> +typename std::enable_if< std::is_floating_point<T>::value, void>::type +inner_encode(const T& rhs, std::stringstream& stream){ + if (std::isnan(rhs)) { + stream << ".nan"; + } else if (std::isinf(rhs)) { + if (std::signbit(rhs)) { + stream << "-.inf"; + } else { + stream << ".inf"; + } + } else { + stream << rhs; + } +} + +template <typename T> +typename std::enable_if<!std::is_floating_point<T>::value, void>::type +inner_encode(const T& rhs, std::stringstream& stream){ + stream << rhs; +} + +template <typename T> +typename std::enable_if<(std::is_same<T, unsigned char>::value || + std::is_same<T, signed char>::value), bool>::type +ConvertStreamTo(std::stringstream& stream, T& rhs) { + int num; + if ((stream >> std::noskipws >> num) && (stream >> std::ws).eof()) { + if (num >= (std::numeric_limits<T>::min)() && + num <= (std::numeric_limits<T>::max)()) { + rhs = static_cast<T>(num); + return true; + } + } + return false; +} + +template <typename T> +typename std::enable_if<!(std::is_same<T, unsigned char>::value || + std::is_same<T, signed char>::value), bool>::type +ConvertStreamTo(std::stringstream& stream, T& rhs) { + if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) { + return true; + } + return false; +} +} + +#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \ + template <> \ + struct convert<type> { \ + \ + static Node encode(const type& rhs) { \ + std::stringstream stream; \ + stream.precision(std::numeric_limits<type>::max_digits10); \ + conversion::inner_encode(rhs, stream); \ + return Node(stream.str()); \ + } \ + \ + static bool decode(const Node& node, type& rhs) { \ + if (node.Type() != NodeType::Scalar) { \ + return false; \ + } \ + const std::string& input = node.Scalar(); \ + std::stringstream stream(input); \ + stream.unsetf(std::ios::dec); \ + if ((stream.peek() == '-') && std::is_unsigned<type>::value) { \ + return false; \ + } \ + if (conversion::ConvertStreamTo(stream, rhs)) { \ + return true; \ + } \ + if (std::numeric_limits<type>::has_infinity) { \ + if (conversion::IsInfinity(input)) { \ + rhs = std::numeric_limits<type>::infinity(); \ + return true; \ + } else if (conversion::IsNegativeInfinity(input)) { \ + rhs = negative_op std::numeric_limits<type>::infinity(); \ + return true; \ + } \ + } \ + \ + if (std::numeric_limits<type>::has_quiet_NaN) { \ + if (conversion::IsNaN(input)) { \ + rhs = std::numeric_limits<type>::quiet_NaN(); \ + return true; \ + } \ + } \ + \ + return false; \ + } \ } #define YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(type) \ @@ -162,81 +246,104 @@ struct convert<bool> { }; // std::map -template <typename K, typename V> -struct convert<std::map<K, V>> { - static Node encode(const std::map<K, V>& rhs) { +template <typename K, typename V, typename C, typename A> +struct convert<std::map<K, V, C, A>> { + static Node encode(const std::map<K, V, C, A>& rhs) { Node node(NodeType::Map); - for (typename std::map<K, V>::const_iterator it = rhs.begin(); - it != rhs.end(); ++it) - node.force_insert(it->first, it->second); + for (const auto& element : rhs) + node.force_insert(element.first, element.second); return node; } - static bool decode(const Node& node, std::map<K, V>& rhs) { + static bool decode(const Node& node, std::map<K, V, C, A>& rhs) { if (!node.IsMap()) return false; rhs.clear(); - for (const_iterator it = node.begin(); it != node.end(); ++it) + for (const auto& element : node) #if defined(__GNUC__) && __GNUC__ < 4 // workaround for GCC 3: - rhs[it->first.template as<K>()] = it->second.template as<V>(); + rhs[element.first.template as<K>()] = element.second.template as<V>(); #else - rhs[it->first.as<K>()] = it->second.as<V>(); + rhs[element.first.as<K>()] = element.second.as<V>(); +#endif + return true; + } +}; + +// std::unordered_map +template <typename K, typename V, typename H, typename P, typename A> +struct convert<std::unordered_map<K, V, H, P, A>> { + static Node encode(const std::unordered_map<K, V, H, P, A>& rhs) { + Node node(NodeType::Map); + for (const auto& element : rhs) + node.force_insert(element.first, element.second); + return node; + } + + static bool decode(const Node& node, std::unordered_map<K, V, H, P, A>& rhs) { + if (!node.IsMap()) + return false; + + rhs.clear(); + for (const auto& element : node) +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs[element.first.template as<K>()] = element.second.template as<V>(); +#else + rhs[element.first.as<K>()] = element.second.as<V>(); #endif return true; } }; // std::vector -template <typename T> -struct convert<std::vector<T>> { - static Node encode(const std::vector<T>& rhs) { +template <typename T, typename A> +struct convert<std::vector<T, A>> { + static Node encode(const std::vector<T, A>& rhs) { Node node(NodeType::Sequence); - for (typename std::vector<T>::const_iterator it = rhs.begin(); - it != rhs.end(); ++it) - node.push_back(*it); + for (const auto& element : rhs) + node.push_back(element); return node; } - static bool decode(const Node& node, std::vector<T>& rhs) { + static bool decode(const Node& node, std::vector<T, A>& rhs) { if (!node.IsSequence()) return false; rhs.clear(); - for (const_iterator it = node.begin(); it != node.end(); ++it) + for (const auto& element : node) #if defined(__GNUC__) && __GNUC__ < 4 // workaround for GCC 3: - rhs.push_back(it->template as<T>()); + rhs.push_back(element.template as<T>()); #else - rhs.push_back(it->as<T>()); + rhs.push_back(element.as<T>()); #endif return true; } }; // std::list -template <typename T> -struct convert<std::list<T>> { - static Node encode(const std::list<T>& rhs) { +template <typename T, typename A> +struct convert<std::list<T,A>> { + static Node encode(const std::list<T,A>& rhs) { Node node(NodeType::Sequence); - for (typename std::list<T>::const_iterator it = rhs.begin(); - it != rhs.end(); ++it) - node.push_back(*it); + for (const auto& element : rhs) + node.push_back(element); return node; } - static bool decode(const Node& node, std::list<T>& rhs) { + static bool decode(const Node& node, std::list<T,A>& rhs) { if (!node.IsSequence()) return false; rhs.clear(); - for (const_iterator it = node.begin(); it != node.end(); ++it) + for (const auto& element : node) #if defined(__GNUC__) && __GNUC__ < 4 // workaround for GCC 3: - rhs.push_back(it->template as<T>()); + rhs.push_back(element.template as<T>()); #else - rhs.push_back(it->as<T>()); + rhs.push_back(element.as<T>()); #endif return true; } @@ -275,6 +382,37 @@ struct convert<std::array<T, N>> { } }; + +// std::valarray +template <typename T> +struct convert<std::valarray<T>> { + static Node encode(const std::valarray<T>& rhs) { + Node node(NodeType::Sequence); + for (const auto& element : rhs) { + node.push_back(element); + } + return node; + } + + static bool decode(const Node& node, std::valarray<T>& rhs) { + if (!node.IsSequence()) { + return false; + } + + rhs.resize(node.size()); + 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; + } +}; + + // std::pair template <typename T, typename U> struct convert<std::pair<T, U>> { diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/bool_type.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/bool_type.h deleted file mode 100644 index 2c80705c9a..0000000000 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/bool_type.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 - -#if defined(_MSC_VER) || \ - (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ - (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 -#pragma once -#endif - -namespace YAML { -namespace detail { -struct unspecified_bool { - struct NOT_ALLOWED; - static void true_value(NOT_ALLOWED*) {} -}; -typedef void (*unspecified_bool_type)(unspecified_bool::NOT_ALLOWED*); -} -} - -#define YAML_CPP_OPERATOR_BOOL() \ - operator YAML::detail::unspecified_bool_type() const { \ - return this->operator!() ? 0 \ - : &YAML::detail::unspecified_bool::true_value; \ - } - -#endif // NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/impl.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/impl.h index 09e55f838c..b38038dfd2 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/impl.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/impl.h @@ -9,6 +9,8 @@ #include "yaml-cpp/node/detail/node.h" #include "yaml-cpp/node/detail/node_data.h" + +#include <algorithm> #include <type_traits> namespace YAML { @@ -17,7 +19,7 @@ template <typename Key, typename Enable = void> struct get_idx { static node* get(const std::vector<node*>& /* sequence */, const Key& /* key */, shared_memory_holder /* pMemory */) { - return 0; + return nullptr; } }; @@ -27,13 +29,13 @@ struct get_idx<Key, !std::is_same<Key, bool>::value>::type> { static node* get(const std::vector<node*>& sequence, const Key& key, shared_memory_holder /* pMemory */) { - return key < sequence.size() ? sequence[key] : 0; + return key < sequence.size() ? sequence[key] : nullptr; } static node* get(std::vector<node*>& sequence, const Key& key, shared_memory_holder pMemory) { - if (key > sequence.size() || (key > 0 && !sequence[key-1]->is_defined())) - return 0; + if (key > sequence.size() || (key > 0 && !sequence[key - 1]->is_defined())) + return nullptr; if (key == sequence.size()) sequence.push_back(&pMemory->create_node()); return sequence[key]; @@ -46,13 +48,51 @@ struct get_idx<Key, typename std::enable_if<std::is_signed<Key>::value>::type> { shared_memory_holder pMemory) { return key >= 0 ? get_idx<std::size_t>::get( sequence, static_cast<std::size_t>(key), pMemory) - : 0; + : nullptr; } static node* get(std::vector<node*>& sequence, const Key& key, shared_memory_holder pMemory) { return key >= 0 ? get_idx<std::size_t>::get( sequence, static_cast<std::size_t>(key), pMemory) - : 0; + : nullptr; + } +}; + +template <typename Key, typename Enable = void> +struct remove_idx { + static bool remove(std::vector<node*>&, const Key&, std::size_t&) { + return false; + } +}; + +template <typename Key> +struct remove_idx< + Key, typename std::enable_if<std::is_unsigned<Key>::value && + !std::is_same<Key, bool>::value>::type> { + + static bool remove(std::vector<node*>& sequence, const Key& key, + std::size_t& seqSize) { + if (key >= sequence.size()) { + return false; + } else { + sequence.erase(sequence.begin() + key); + if (seqSize > key) { + --seqSize; + } + return true; + } + } +}; + +template <typename Key> +struct remove_idx<Key, + typename std::enable_if<std::is_signed<Key>::value>::type> { + + static bool remove(std::vector<node*>& sequence, const Key& key, + std::size_t& seqSize) { + return key >= 0 ? remove_idx<std::size_t>::remove( + sequence, static_cast<std::size_t>(key), seqSize) + : false; } }; @@ -66,7 +106,11 @@ inline bool node::equals(const T& rhs, shared_memory_holder pMemory) { } inline bool node::equals(const char* rhs, shared_memory_holder pMemory) { - return equals<std::string>(rhs, pMemory); + std::string lhs; + if (convert<std::string>::decode(Node(*this, std::move(pMemory)), lhs)) { + return lhs == rhs; + } + return false; } // indexing @@ -78,22 +122,20 @@ inline node* node_data::get(const Key& key, break; case NodeType::Undefined: case NodeType::Null: - return NULL; + return nullptr; case NodeType::Sequence: if (node* pNode = get_idx<Key>::get(m_sequence, key, pMemory)) return pNode; - return NULL; + return nullptr; case NodeType::Scalar: - throw BadSubscript(); + throw BadSubscript(m_mark, key); } - for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) { - if (it->first->equals(key, pMemory)) { - return it->second; - } - } + auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { + return m.first->equals(key, pMemory); + }); - return NULL; + return it != m_map.end() ? it->second : nullptr; } template <typename Key> @@ -112,13 +154,15 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) { convert_to_map(pMemory); break; case NodeType::Scalar: - throw BadSubscript(); + throw BadSubscript(m_mark, key); } - for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) { - if (it->first->equals(key, pMemory)) { - return *it->second; - } + auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { + return m.first->equals(key, pMemory); + }); + + if (it != m_map.end()) { + return *it->second; } node& k = convert_to_node(key, pMemory); @@ -129,20 +173,26 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) { template <typename Key> inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) { - if (m_type != NodeType::Map) - return false; - - for (kv_pairs::iterator it = m_undefinedPairs.begin(); - it != m_undefinedPairs.end();) { - kv_pairs::iterator jt = std::next(it); - if (it->first->equals(key, pMemory)) - m_undefinedPairs.erase(it); - it = jt; + if (m_type == NodeType::Sequence) { + return remove_idx<Key>::remove(m_sequence, key, m_seqSize); } - for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) { - if (it->first->equals(key, pMemory)) { - m_map.erase(it); + if (m_type == NodeType::Map) { + 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; + } + + auto iter = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { + return m.first->equals(key, pMemory); + }); + + if (iter != m_map.end()) { + m_map.erase(iter); return true; } } diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/iterator.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/iterator.h index deec8fb62c..997c69a14c 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/iterator.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/iterator.h @@ -8,25 +8,25 @@ #endif #include "yaml-cpp/dll.h" +#include "yaml-cpp/node/detail/node_iterator.h" #include "yaml-cpp/node/node.h" #include "yaml-cpp/node/ptr.h" -#include "yaml-cpp/node/detail/node_iterator.h" #include <cstddef> #include <iterator> + namespace YAML { namespace detail { struct iterator_value; template <typename V> -class iterator_base : public std::iterator<std::forward_iterator_tag, V, - std::ptrdiff_t, V*, V> { +class iterator_base { private: template <typename> friend class iterator_base; struct enabler {}; - typedef node_iterator base_type; + using base_type = node_iterator; struct proxy { explicit proxy(const V& x) : m_ref(x) {} @@ -37,7 +37,11 @@ class iterator_base : public std::iterator<std::forward_iterator_tag, V, }; public: - typedef typename iterator_base::value_type value_type; + using iterator_category = std::forward_iterator_tag; + using value_type = V; + using difference_type = std::ptrdiff_t; + using pointer = V*; + using reference = V; public: iterator_base() : m_iterator(), m_pMemory() {} @@ -86,7 +90,7 @@ class iterator_base : public std::iterator<std::forward_iterator_tag, V, base_type m_iterator; shared_memory_holder m_pMemory; }; -} -} +} // namespace detail +} // namespace YAML #endif // VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/iterator_fwd.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/iterator_fwd.h index 5f1ffe7436..75c9de086c 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/iterator_fwd.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/iterator_fwd.h @@ -20,8 +20,8 @@ template <typename V> class iterator_base; } -typedef detail::iterator_base<detail::iterator_value> iterator; -typedef detail::iterator_base<const detail::iterator_value> const_iterator; +using iterator = detail::iterator_base<detail::iterator_value>; +using const_iterator = detail::iterator_base<const detail::iterator_value>; } #endif // VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/memory.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/memory.h index 8f2bc2657a..e881545bf2 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/memory.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/memory.h @@ -22,11 +22,12 @@ namespace YAML { namespace detail { class YAML_CPP_API memory { public: + memory() : m_nodes{} {} node& create_node(); void merge(const memory& rhs); private: - typedef std::set<shared_node> Nodes; + using Nodes = std::set<shared_node>; Nodes m_nodes; }; @@ -40,7 +41,7 @@ class YAML_CPP_API memory_holder { private: shared_memory m_pMemory; }; -} -} +} // namespace detail +} // namespace YAML #endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node.h index 8a776f62a9..acf60ffb6d 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node.h @@ -7,18 +7,24 @@ #pragma once #endif -#include "yaml-cpp/emitterstyle.h" #include "yaml-cpp/dll.h" -#include "yaml-cpp/node/type.h" -#include "yaml-cpp/node/ptr.h" +#include "yaml-cpp/emitterstyle.h" #include "yaml-cpp/node/detail/node_ref.h" +#include "yaml-cpp/node/ptr.h" +#include "yaml-cpp/node/type.h" #include <set> +#include <atomic> namespace YAML { namespace detail { class node { + private: + struct less { + bool operator ()(const node* l, const node* r) const {return l->m_index < r->m_index;} + }; + public: - node() : m_pRef(new node_ref) {} + node() : m_pRef(new node_ref), m_dependencies{}, m_index{} {} node(const node&) = delete; node& operator=(const node&) = delete; @@ -42,9 +48,8 @@ class node { return; m_pRef->mark_defined(); - for (nodes::iterator it = m_dependencies.begin(); - it != m_dependencies.end(); ++it) - (*it)->mark_defined(); + for (node* dependency : m_dependencies) + dependency->mark_defined(); m_dependencies.clear(); } @@ -109,6 +114,7 @@ class node { void push_back(node& input, shared_memory_holder pMemory) { m_pRef->push_back(input, pMemory); input.add_dependency(*this); + m_index = m_amount.fetch_add(1); } void insert(node& key, node& value, shared_memory_holder pMemory) { m_pRef->insert(key, value, pMemory); @@ -120,7 +126,7 @@ class node { 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 + // it, and returns a pointer so that it can be nullptr (if there is no such // key). return static_cast<const node_ref&>(*m_pRef).get(key, pMemory); } @@ -137,7 +143,7 @@ class node { node* get(node& 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 + // it, and returns a pointer so that it can be nullptr (if there is no such // key). return static_cast<const node_ref&>(*m_pRef).get(key, pMemory); } @@ -160,10 +166,12 @@ class node { private: shared_node_ref m_pRef; - typedef std::set<node*> nodes; + using nodes = std::set<node*, less>; nodes m_dependencies; + size_t m_index; + static YAML_CPP_API std::atomic<size_t> m_amount; }; -} -} +} // namespace detail +} // namespace YAML #endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node_data.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node_data.h index 50bcd74352..07cf81aa09 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node_data.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node_data.h @@ -60,8 +60,8 @@ class YAML_CPP_API node_data { node_iterator end(); // sequence - void push_back(node& node, shared_memory_holder pMemory); - void insert(node& key, node& value, shared_memory_holder pMemory); + void push_back(node& node, const shared_memory_holder& pMemory); + void insert(node& key, node& value, const shared_memory_holder& pMemory); // indexing template <typename Key> @@ -71,9 +71,9 @@ class YAML_CPP_API node_data { template <typename Key> bool remove(const Key& key, shared_memory_holder pMemory); - node* get(node& key, shared_memory_holder pMemory) const; - node& get(node& key, shared_memory_holder pMemory); - bool remove(node& key, shared_memory_holder pMemory); + node* get(node& key, const shared_memory_holder& pMemory) const; + node& get(node& key, const shared_memory_holder& pMemory); + bool remove(node& key, const shared_memory_holder& pMemory); // map template <typename Key, typename Value> @@ -81,7 +81,7 @@ class YAML_CPP_API node_data { shared_memory_holder pMemory); public: - static std::string empty_scalar; + static const std::string& empty_scalar(); private: void compute_seq_size() const; @@ -91,8 +91,8 @@ class YAML_CPP_API node_data { void reset_map(); void insert_map_pair(node& key, node& value); - void convert_to_map(shared_memory_holder pMemory); - void convert_sequence_to_map(shared_memory_holder pMemory); + void convert_to_map(const shared_memory_holder& pMemory); + void convert_sequence_to_map(const shared_memory_holder& pMemory); template <typename T> static node& convert_to_node(const T& rhs, shared_memory_holder pMemory); @@ -108,17 +108,17 @@ class YAML_CPP_API node_data { std::string m_scalar; // sequence - typedef std::vector<node*> node_seq; + using node_seq = std::vector<node *>; node_seq m_sequence; mutable std::size_t m_seqSize; // map - typedef std::vector<std::pair<node*, node*>> node_map; + using node_map = std::vector<std::pair<node*, node*>>; node_map m_map; - typedef std::pair<node*, node*> kv_pair; - typedef std::list<kv_pair> kv_pairs; + using kv_pair = std::pair<node*, node*>; + using kv_pairs = std::list<kv_pair>; mutable kv_pairs m_undefinedPairs; }; } diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node_iterator.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node_iterator.h index 088090fe74..49dcf958db 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node_iterator.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/detail/node_iterator.h @@ -24,11 +24,11 @@ struct iterator_type { template <typename V> struct node_iterator_value : public std::pair<V*, V*> { - typedef std::pair<V*, V*> kv; + using kv = std::pair<V*, V*>; - node_iterator_value() : kv(), pNode(0) {} + node_iterator_value() : kv(), pNode(nullptr) {} explicit node_iterator_value(V& rhs) : kv(), pNode(&rhs) {} - explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(0) {} + explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(nullptr) {} V& operator*() const { return *pNode; } V& operator->() const { return *pNode; } @@ -36,26 +36,23 @@ struct node_iterator_value : public std::pair<V*, V*> { V* pNode; }; -typedef std::vector<node*> node_seq; -typedef std::vector<std::pair<node*, node*>> node_map; +using node_seq = std::vector<node *>; +using node_map = std::vector<std::pair<node*, node*>>; template <typename V> struct node_iterator_type { - typedef node_seq::iterator seq; - typedef node_map::iterator map; + using seq = node_seq::iterator; + using map = node_map::iterator; }; template <typename V> struct node_iterator_type<const V> { - typedef node_seq::const_iterator seq; - typedef node_map::const_iterator map; + using seq = node_seq::const_iterator; + using map = node_map::const_iterator; }; template <typename V> -class node_iterator_base - : public std::iterator<std::forward_iterator_tag, node_iterator_value<V>, - std::ptrdiff_t, node_iterator_value<V>*, - node_iterator_value<V>> { +class node_iterator_base { private: struct enabler {}; @@ -68,9 +65,13 @@ class node_iterator_base }; public: - typedef typename node_iterator_type<V>::seq SeqIter; - typedef typename node_iterator_type<V>::map MapIter; - typedef node_iterator_value<V> value_type; + using iterator_category = std::forward_iterator_tag; + using value_type = node_iterator_value<V>; + using difference_type = std::ptrdiff_t; + using pointer = node_iterator_value<V>*; + using reference = node_iterator_value<V>; + using SeqIter = typename node_iterator_type<V>::seq; + using MapIter = typename node_iterator_type<V>::map; node_iterator_base() : m_type(iterator_type::NoneType), m_seqIt(), m_mapIt(), m_mapEnd() {} @@ -172,8 +173,8 @@ class node_iterator_base MapIter m_mapIt, m_mapEnd; }; -typedef node_iterator_base<node> node_iterator; -typedef node_iterator_base<const node> const_node_iterator; +using node_iterator = node_iterator_base<node>; +using const_node_iterator = node_iterator_base<const node>; } } diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/impl.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/impl.h index 20c487a687..312281f18c 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/impl.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/impl.h @@ -7,18 +7,21 @@ #pragma once #endif -#include "yaml-cpp/node/node.h" -#include "yaml-cpp/node/iterator.h" +#include "yaml-cpp/exceptions.h" #include "yaml-cpp/node/detail/memory.h" #include "yaml-cpp/node/detail/node.h" -#include "yaml-cpp/exceptions.h" +#include "yaml-cpp/node/iterator.h" +#include "yaml-cpp/node/node.h" +#include <sstream> #include <string> namespace YAML { -inline Node::Node() : m_isValid(true), m_pNode(NULL) {} +inline Node::Node() + : m_isValid(true), m_invalidKey{}, m_pMemory(nullptr), m_pNode(nullptr) {} inline Node::Node(NodeType::value type) : m_isValid(true), + m_invalidKey{}, m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node()) { m_pNode->set_type(type); @@ -27,6 +30,7 @@ inline Node::Node(NodeType::value type) template <typename T> inline Node::Node(const T& rhs) : m_isValid(true), + m_invalidKey{}, m_pMemory(new detail::memory_holder), m_pNode(&m_pMemory->create_node()) { Assign(rhs); @@ -34,24 +38,26 @@ inline Node::Node(const T& rhs) inline Node::Node(const detail::iterator_value& rhs) : m_isValid(rhs.m_isValid), + m_invalidKey(rhs.m_invalidKey), m_pMemory(rhs.m_pMemory), m_pNode(rhs.m_pNode) {} -inline Node::Node(const Node& rhs) - : m_isValid(rhs.m_isValid), - m_pMemory(rhs.m_pMemory), - m_pNode(rhs.m_pNode) {} +inline Node::Node(const Node&) = default; + +inline Node::Node(Zombie) + : m_isValid(false), m_invalidKey{}, m_pMemory{}, m_pNode(nullptr) {} -inline Node::Node(Zombie) : m_isValid(false), m_pNode(NULL) {} +inline Node::Node(Zombie, const std::string& key) + : m_isValid(false), m_invalidKey(key), m_pMemory{}, m_pNode(nullptr) {} inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory) - : m_isValid(true), m_pMemory(pMemory), m_pNode(&node) {} + : m_isValid(true), m_invalidKey{}, m_pMemory(pMemory), m_pNode(&node) {} -inline Node::~Node() {} +inline Node::~Node() = default; inline void Node::EnsureNodeExists() const { if (!m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); if (!m_pNode) { m_pMemory.reset(new detail::memory_holder); m_pNode = &m_pMemory->create_node(); @@ -68,14 +74,14 @@ inline bool Node::IsDefined() const { inline Mark Node::Mark() const { if (!m_isValid) { - throw InvalidNode(); + throw InvalidNode(m_invalidKey); } return m_pNode ? m_pNode->mark() : Mark::null_mark(); } inline NodeType::value Node::Type() const { if (!m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); return m_pNode ? m_pNode->type() : NodeType::Null; } @@ -104,6 +110,8 @@ struct as_if<std::string, S> { const Node& node; std::string operator()(const S& fallback) const { + if (node.Type() == NodeType::Null) + return "null"; if (node.Type() != NodeType::Scalar) return fallback; return node.Scalar(); @@ -132,6 +140,8 @@ struct as_if<std::string, void> { const Node& node; std::string operator()() const { + if (node.Type() == NodeType::Null) + return "null"; if (node.Type() != NodeType::Scalar) throw TypedBadConversion<std::string>(node.Mark()); return node.Scalar(); @@ -142,7 +152,7 @@ struct as_if<std::string, void> { template <typename T> inline T Node::as() const { if (!m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); return as_if<T, void>(*this)(); } @@ -155,32 +165,28 @@ inline T Node::as(const S& fallback) const { inline const std::string& Node::Scalar() const { if (!m_isValid) - throw InvalidNode(); - return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar; + throw InvalidNode(m_invalidKey); + return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar(); } inline const std::string& Node::Tag() const { if (!m_isValid) - throw InvalidNode(); - return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar; + throw InvalidNode(m_invalidKey); + return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar(); } inline void Node::SetTag(const std::string& tag) { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); m_pNode->set_tag(tag); } inline EmitterStyle::value Node::Style() const { if (!m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); return m_pNode ? m_pNode->style() : EmitterStyle::Default; } inline void Node::SetStyle(EmitterStyle::value style) { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); m_pNode->set_style(style); } @@ -188,7 +194,7 @@ inline void Node::SetStyle(EmitterStyle::value style) { // assignment inline bool Node::is(const Node& rhs) const { if (!m_isValid || !rhs.m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); if (!m_pNode || !rhs.m_pNode) return false; return m_pNode->is(*rhs.m_pNode); @@ -196,15 +202,20 @@ inline bool Node::is(const Node& rhs) const { template <typename T> inline Node& Node::operator=(const T& rhs) { - if (!m_isValid) - throw InvalidNode(); Assign(rhs); return *this; } +inline Node& Node::operator=(const Node& rhs) { + if (is(rhs)) + return *this; + AssignNode(rhs); + return *this; +} + inline void Node::reset(const YAML::Node& rhs) { if (!m_isValid || !rhs.m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); m_pMemory = rhs.m_pMemory; m_pNode = rhs.m_pNode; } @@ -212,44 +223,27 @@ inline void Node::reset(const YAML::Node& rhs) { template <typename T> inline void Node::Assign(const T& rhs) { if (!m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); AssignData(convert<T>::encode(rhs)); } template <> inline void Node::Assign(const std::string& rhs) { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); m_pNode->set_scalar(rhs); } inline void Node::Assign(const char* rhs) { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); m_pNode->set_scalar(rhs); } inline void Node::Assign(char* rhs) { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); m_pNode->set_scalar(rhs); } -inline Node& Node::operator=(const Node& rhs) { - if (!m_isValid || !rhs.m_isValid) - throw InvalidNode(); - if (is(rhs)) - return *this; - AssignNode(rhs); - return *this; -} - inline void Node::AssignData(const Node& rhs) { - if (!m_isValid || !rhs.m_isValid) - throw InvalidNode(); EnsureNodeExists(); rhs.EnsureNodeExists(); @@ -258,8 +252,8 @@ inline void Node::AssignData(const Node& rhs) { } inline void Node::AssignNode(const Node& rhs) { - if (!m_isValid || !rhs.m_isValid) - throw InvalidNode(); + if (!m_isValid) + throw InvalidNode(m_invalidKey); rhs.EnsureNodeExists(); if (!m_pNode) { @@ -276,7 +270,7 @@ inline void Node::AssignNode(const Node& rhs) { // size/iterator inline std::size_t Node::size() const { if (!m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); return m_pNode ? m_pNode->size() : 0; } @@ -309,13 +303,11 @@ inline iterator Node::end() { template <typename T> inline void Node::push_back(const T& rhs) { if (!m_isValid) - throw InvalidNode(); + throw InvalidNode(m_invalidKey); push_back(Node(rhs)); } inline void Node::push_back(const Node& rhs) { - if (!m_isValid || !rhs.m_isValid) - throw InvalidNode(); EnsureNodeExists(); rhs.EnsureNodeExists(); @@ -323,99 +315,49 @@ inline void Node::push_back(const Node& rhs) { m_pMemory->merge(*rhs.m_pMemory); } -// helpers for indexing -namespace detail { -template <typename T> -struct to_value_t { - explicit to_value_t(const T& t_) : t(t_) {} - const T& t; - typedef const T& return_type; - - const T& operator()() const { return t; } -}; - -template <> -struct to_value_t<const char*> { - explicit to_value_t(const char* t_) : t(t_) {} - const char* t; - typedef std::string return_type; - - const std::string operator()() const { return t; } -}; - -template <> -struct to_value_t<char*> { - explicit to_value_t(char* t_) : t(t_) {} - const char* t; - typedef std::string return_type; - - const std::string operator()() const { return t; } -}; - -template <std::size_t N> -struct to_value_t<char[N]> { - explicit to_value_t(const char* t_) : t(t_) {} - const char* t; - typedef std::string return_type; - - const std::string operator()() const { return t; } -}; - -// converts C-strings to std::strings so they can be copied -template <typename T> -inline typename to_value_t<T>::return_type to_value(const T& t) { - return to_value_t<T>(t)(); -} +template<typename Key> +std::string key_to_string(const Key& key) { + return streamable_to_string<Key, is_streamable<std::stringstream, Key>::value>().impl(key); } // indexing template <typename Key> inline const Node Node::operator[](const Key& key) const { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); - detail::node* value = static_cast<const detail::node&>(*m_pNode) - .get(detail::to_value(key), m_pMemory); + detail::node* value = + static_cast<const detail::node&>(*m_pNode).get(key, m_pMemory); if (!value) { - return Node(ZombieNode); + return Node(ZombieNode, key_to_string(key)); } return Node(*value, m_pMemory); } template <typename Key> inline Node Node::operator[](const Key& key) { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); - detail::node& value = m_pNode->get(detail::to_value(key), m_pMemory); + detail::node& value = m_pNode->get(key, m_pMemory); return Node(value, m_pMemory); } template <typename Key> inline bool Node::remove(const Key& key) { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); - return m_pNode->remove(detail::to_value(key), m_pMemory); + return m_pNode->remove(key, m_pMemory); } inline const Node Node::operator[](const Node& key) const { - if (!m_isValid || !key.m_isValid) - throw InvalidNode(); EnsureNodeExists(); key.EnsureNodeExists(); m_pMemory->merge(*key.m_pMemory); detail::node* value = static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory); if (!value) { - return Node(ZombieNode); + return Node(ZombieNode, key_to_string(key)); } return Node(*value, m_pMemory); } inline Node Node::operator[](const Node& key) { - if (!m_isValid || !key.m_isValid) - throw InvalidNode(); EnsureNodeExists(); key.EnsureNodeExists(); m_pMemory->merge(*key.m_pMemory); @@ -424,8 +366,6 @@ inline Node Node::operator[](const Node& key) { } inline bool Node::remove(const Node& key) { - if (!m_isValid || !key.m_isValid) - throw InvalidNode(); EnsureNodeExists(); key.EnsureNodeExists(); return m_pNode->remove(*key.m_pNode, m_pMemory); @@ -434,15 +374,12 @@ inline bool Node::remove(const Node& key) { // map template <typename Key, typename Value> inline void Node::force_insert(const Key& key, const Value& value) { - if (!m_isValid) - throw InvalidNode(); EnsureNodeExists(); - m_pNode->force_insert(detail::to_value(key), detail::to_value(value), - m_pMemory); + m_pNode->force_insert(key, value, m_pMemory); } // free functions inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); } -} +} // namespace YAML #endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/iterator.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/iterator.h index 366a9c807f..1fcf6e400f 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/iterator.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/iterator.h @@ -15,10 +15,13 @@ #include <utility> #include <vector> +// Assert in place so gcc + libc++ combination properly builds +static_assert(std::is_constructible<YAML::Node, const YAML::Node&>::value, "Node must be copy constructable"); + namespace YAML { namespace detail { struct iterator_value : public Node, std::pair<Node, Node> { - iterator_value() {} + iterator_value() = default; explicit iterator_value(const Node& rhs) : Node(rhs), std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {} diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/node.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/node.h index 1ded7d27b7..c9e9a0a4bc 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/node.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/node.h @@ -8,11 +8,11 @@ #endif #include <stdexcept> +#include <string> #include "yaml-cpp/dll.h" #include "yaml-cpp/emitterstyle.h" #include "yaml-cpp/mark.h" -#include "yaml-cpp/node/detail/bool_type.h" #include "yaml-cpp/node/detail/iterator_fwd.h" #include "yaml-cpp/node/ptr.h" #include "yaml-cpp/node/type.h" @@ -38,8 +38,8 @@ class YAML_CPP_API Node { template <typename T, typename S> friend struct as_if; - typedef YAML::iterator iterator; - typedef YAML::const_iterator const_iterator; + using iterator = YAML::iterator; + using const_iterator = YAML::const_iterator; Node(); explicit Node(NodeType::value type); @@ -58,7 +58,7 @@ class YAML_CPP_API Node { bool IsMap() const { return Type() == NodeType::Map; } // bool conversions - YAML_CPP_OPERATOR_BOOL() + explicit operator bool() const { return IsDefined(); } bool operator!() const { return !IsDefined(); } // access @@ -116,6 +116,7 @@ class YAML_CPP_API Node { private: enum Zombie { ZombieNode }; explicit Node(Zombie); + explicit Node(Zombie, const std::string&); explicit Node(detail::node& node, detail::shared_memory_holder pMemory); void EnsureNodeExists() const; @@ -130,6 +131,8 @@ class YAML_CPP_API Node { private: bool m_isValid; + // String representation of invalid key, if the node is invalid. + std::string m_invalidKey; mutable detail::shared_memory_holder m_pMemory; mutable detail::node* m_pNode; }; diff --git a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/ptr.h b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/ptr.h index ce085dd5cd..f55d95ed9c 100644 --- a/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/ptr.h +++ b/src/libs/3rdparty/yaml-cpp/include/yaml-cpp/node/ptr.h @@ -7,7 +7,6 @@ #pragma once #endif -#include "yaml-cpp/dll.h" #include <memory> namespace YAML { @@ -18,11 +17,11 @@ class node_data; class memory; class memory_holder; -typedef std::shared_ptr<node> shared_node; -typedef std::shared_ptr<node_ref> shared_node_ref; -typedef std::shared_ptr<node_data> shared_node_data; -typedef std::shared_ptr<memory_holder> shared_memory_holder; -typedef std::shared_ptr<memory> shared_memory; +using shared_node = std::shared_ptr<node>; +using shared_node_ref = std::shared_ptr<node_ref>; +using shared_node_data = std::shared_ptr<node_data>; +using shared_memory_holder = std::shared_ptr<memory_holder>; +using shared_memory = std::shared_ptr<memory>; } } |