yaml-cpp

FORK: A YAML parser and emitter in C++
git clone https://git.neptards.moe/neptards/yaml-cpp.git
Log | Files | Refs | README | LICENSE

nodeevents.h (1776B)


      1 #ifndef NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
      2 #define NODE_NODEEVENTS_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 <map>
     11 #include <vector>
     12 
     13 #include "yaml-cpp/anchor.h"
     14 #include "yaml-cpp/node/ptr.h"
     15 
     16 namespace YAML {
     17 namespace detail {
     18 class node;
     19 }  // namespace detail
     20 }  // namespace YAML
     21 
     22 namespace YAML {
     23 class EventHandler;
     24 class Node;
     25 
     26 class NodeEvents {
     27  public:
     28   explicit NodeEvents(const Node& node);
     29   NodeEvents(const NodeEvents&) = delete;
     30   NodeEvents(NodeEvents&&) = delete;
     31   NodeEvents& operator=(const NodeEvents&) = delete;
     32   NodeEvents& operator=(NodeEvents&&) = delete;
     33 
     34   void Emit(EventHandler& handler);
     35 
     36  private:
     37   class AliasManager {
     38    public:
     39     AliasManager() : m_anchorByIdentity{}, m_curAnchor(0) {}
     40 
     41     void RegisterReference(const detail::node& node);
     42     anchor_t LookupAnchor(const detail::node& node) const;
     43 
     44    private:
     45     anchor_t _CreateNewAnchor() { return ++m_curAnchor; }
     46 
     47    private:
     48     using AnchorByIdentity = std::map<const detail::node_ref*, anchor_t>;
     49     AnchorByIdentity m_anchorByIdentity;
     50 
     51     anchor_t m_curAnchor;
     52   };
     53 
     54   void Setup(const detail::node& node);
     55   void Emit(const detail::node& node, EventHandler& handler,
     56             AliasManager& am) const;
     57   bool IsAliased(const detail::node& node) const;
     58 
     59  private:
     60   detail::shared_memory_holder m_pMemory;
     61   detail::node* m_root;
     62 
     63   using RefCount = std::map<const detail::node_ref*, int>;
     64   RefCount m_refCount;
     65 };
     66 }  // namespace YAML
     67 
     68 #endif  // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66