node_ref.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  2. #define VALUE_DETAIL_NODE_REF_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 "yaml-cpp/dll.h"
  9. #include "yaml-cpp/node/type.h"
  10. #include "yaml-cpp/node/ptr.h"
  11. #include "yaml-cpp/node/detail/node_data.h"
  12. namespace YAML {
  13. namespace detail {
  14. class node_ref {
  15. public:
  16. node_ref() : m_pData(new node_data) {}
  17. node_ref(const node_ref&) = delete;
  18. node_ref& operator=(const node_ref&) = delete;
  19. bool is_defined() const { return m_pData->is_defined(); }
  20. const Mark& mark() const { return m_pData->mark(); }
  21. NodeType::value type() const { return m_pData->type(); }
  22. const std::string& scalar() const { return m_pData->scalar(); }
  23. const std::string& tag() const { return m_pData->tag(); }
  24. EmitterStyle::value style() const { return m_pData->style(); }
  25. void mark_defined() { m_pData->mark_defined(); }
  26. void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; }
  27. void set_mark(const Mark& mark) { m_pData->set_mark(mark); }
  28. void set_type(NodeType::value type) { m_pData->set_type(type); }
  29. void set_tag(const std::string& tag) { m_pData->set_tag(tag); }
  30. void set_null() { m_pData->set_null(); }
  31. void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); }
  32. void set_style(EmitterStyle::value style) { m_pData->set_style(style); }
  33. // size/iterator
  34. std::size_t size() const { return m_pData->size(); }
  35. const_node_iterator begin() const {
  36. return static_cast<const node_data&>(*m_pData).begin();
  37. }
  38. node_iterator begin() { return m_pData->begin(); }
  39. const_node_iterator end() const {
  40. return static_cast<const node_data&>(*m_pData).end();
  41. }
  42. node_iterator end() { return m_pData->end(); }
  43. // sequence
  44. void push_back(node& node, shared_memory_holder pMemory) {
  45. m_pData->push_back(node, pMemory);
  46. }
  47. void insert(node& key, node& value, shared_memory_holder pMemory) {
  48. m_pData->insert(key, value, pMemory);
  49. }
  50. // indexing
  51. template <typename Key>
  52. node* get(const Key& key, shared_memory_holder pMemory) const {
  53. return static_cast<const node_data&>(*m_pData).get(key, pMemory);
  54. }
  55. template <typename Key>
  56. node& get(const Key& key, shared_memory_holder pMemory) {
  57. return m_pData->get(key, pMemory);
  58. }
  59. template <typename Key>
  60. bool remove(const Key& key, shared_memory_holder pMemory) {
  61. return m_pData->remove(key, pMemory);
  62. }
  63. node* get(node& key, shared_memory_holder pMemory) const {
  64. return static_cast<const node_data&>(*m_pData).get(key, pMemory);
  65. }
  66. node& get(node& key, shared_memory_holder pMemory) {
  67. return m_pData->get(key, pMemory);
  68. }
  69. bool remove(node& key, shared_memory_holder pMemory) {
  70. return m_pData->remove(key, pMemory);
  71. }
  72. // map
  73. template <typename Key, typename Value>
  74. void force_insert(const Key& key, const Value& value,
  75. shared_memory_holder pMemory) {
  76. m_pData->force_insert(key, value, pMemory);
  77. }
  78. private:
  79. shared_node_data m_pData;
  80. };
  81. }
  82. }
  83. #endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66