BRE12
iterator.h
1 #ifndef VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3 
4 #if defined(_MSC_VER) || \
5  (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6  (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7 #pragma once
8 #endif
9 
10 #include "yaml-cpp/dll.h"
11 #include "yaml-cpp/node/ptr.h"
12 #include "yaml-cpp/node/detail/node_iterator.h"
13 #include <cstddef>
14 #include <iterator>
15 
16 namespace YAML {
17 namespace detail {
18 struct iterator_value;
19 
20 template <typename V>
21 class iterator_base : public std::iterator<std::forward_iterator_tag, V,
22  std::ptrdiff_t, V*, V> {
23 
24  private:
25  template <typename>
26  friend class iterator_base;
27  struct enabler {};
28  typedef node_iterator base_type;
29 
30  struct proxy {
31  explicit proxy(const V& x) : m_ref(x) {}
32  V* operator->() { return std::addressof(m_ref); }
33  operator V*() { return std::addressof(m_ref); }
34 
35  V m_ref;
36  };
37 
38  public:
39  typedef typename iterator_base::value_type value_type;
40 
41  public:
42  iterator_base() : m_iterator(), m_pMemory() {}
43  explicit iterator_base(base_type rhs, shared_memory_holder pMemory)
44  : m_iterator(rhs), m_pMemory(pMemory) {}
45 
46  template <class W>
48  typename std::enable_if<std::is_convertible<W*, V*>::value,
49  enabler>::type = enabler())
50  : m_iterator(rhs.m_iterator), m_pMemory(rhs.m_pMemory) {}
51 
52  iterator_base<V>& operator++() {
53  ++m_iterator;
54  return *this;
55  }
56 
57  iterator_base<V> operator++(int) {
58  iterator_base<V> iterator_pre(*this);
59  ++(*this);
60  return iterator_pre;
61  }
62 
63  template <typename W>
64  bool operator==(const iterator_base<W>& rhs) const {
65  return m_iterator == rhs.m_iterator;
66  }
67 
68  template <typename W>
69  bool operator!=(const iterator_base<W>& rhs) const {
70  return m_iterator != rhs.m_iterator;
71  }
72 
73  value_type operator*() const {
74  const typename base_type::value_type& v = *m_iterator;
75  if (v.pNode)
76  return value_type(Node(*v, m_pMemory));
77  if (v.first && v.second)
78  return value_type(Node(*v.first, m_pMemory), Node(*v.second, m_pMemory));
79  return value_type();
80  }
81 
82  proxy operator->() const { return proxy(**this); }
83 
84  private:
85  base_type m_iterator;
86  shared_memory_holder m_pMemory;
87 };
88 }
89 }
90 
91 #endif // VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
Definition: node_iterator.h:26
Definition: node_iterator.h:55
Definition: iterator.h:21
Definition: DrawableObjectLoader.h:10
Definition: node.h:29