node_data.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  2. #define VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  3. #if defined(_MSC_VER) || \
  4. (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
  5. (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
  6. #pragma once
  7. #endif
  8. #include <list>
  9. #include <map>
  10. #include <string>
  11. #include <utility>
  12. #include <vector>
  13. #include "yaml-cpp/dll.h"
  14. #include "yaml-cpp/node/detail/node_iterator.h"
  15. #include "yaml-cpp/node/iterator.h"
  16. #include "yaml-cpp/node/ptr.h"
  17. #include "yaml-cpp/node/type.h"
  18. namespace YAML {
  19. namespace detail {
  20. class node;
  21. } // namespace detail
  22. } // namespace YAML
  23. namespace YAML {
  24. namespace detail {
  25. class YAML_CPP_API node_data {
  26. public:
  27. node_data();
  28. node_data(const node_data&) = delete;
  29. node_data& operator=(const node_data&) = delete;
  30. void mark_defined();
  31. void set_mark(const Mark& mark);
  32. void set_type(NodeType::value type);
  33. void set_tag(const std::string& tag);
  34. void set_null();
  35. void set_scalar(const std::string& scalar);
  36. void set_style(EmitterStyle::value style);
  37. bool is_defined() const { return m_isDefined; }
  38. const Mark& mark() const { return m_mark; }
  39. NodeType::value type() const {
  40. return m_isDefined ? m_type : NodeType::Undefined;
  41. }
  42. const std::string& scalar() const { return m_scalar; }
  43. const std::string& tag() const { return m_tag; }
  44. EmitterStyle::value style() const { return m_style; }
  45. // size/iterator
  46. std::size_t size() const;
  47. const_node_iterator begin() const;
  48. node_iterator begin();
  49. const_node_iterator end() const;
  50. node_iterator end();
  51. // sequence
  52. void push_back(node& node, shared_memory_holder pMemory);
  53. void insert(node& key, node& value, shared_memory_holder pMemory);
  54. // indexing
  55. template <typename Key>
  56. node* get(const Key& key, shared_memory_holder pMemory) const;
  57. template <typename Key>
  58. node& get(const Key& key, shared_memory_holder pMemory);
  59. template <typename Key>
  60. bool remove(const Key& key, shared_memory_holder pMemory);
  61. node* get(node& key, shared_memory_holder pMemory) const;
  62. node& get(node& key, shared_memory_holder pMemory);
  63. bool remove(node& key, shared_memory_holder pMemory);
  64. // map
  65. template <typename Key, typename Value>
  66. void force_insert(const Key& key, const Value& value,
  67. shared_memory_holder pMemory);
  68. public:
  69. static const std::string& empty_scalar();
  70. private:
  71. void compute_seq_size() const;
  72. void compute_map_size() const;
  73. void reset_sequence();
  74. void reset_map();
  75. void insert_map_pair(node& key, node& value);
  76. void convert_to_map(shared_memory_holder pMemory);
  77. void convert_sequence_to_map(shared_memory_holder pMemory);
  78. template <typename T>
  79. static node& convert_to_node(const T& rhs, shared_memory_holder pMemory);
  80. private:
  81. bool m_isDefined;
  82. Mark m_mark;
  83. NodeType::value m_type;
  84. std::string m_tag;
  85. EmitterStyle::value m_style;
  86. // scalar
  87. std::string m_scalar;
  88. // sequence
  89. using node_seq = std::vector<node *>;
  90. node_seq m_sequence;
  91. mutable std::size_t m_seqSize;
  92. // map
  93. using node_map = std::vector<std::pair<node*, node*>>;
  94. node_map m_map;
  95. using kv_pair = std::pair<node*, node*>;
  96. using kv_pairs = std::list<kv_pair>;
  97. mutable kv_pairs m_undefinedPairs;
  98. };
  99. }
  100. }
  101. #endif // VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66