File indexing completed on 2025-05-12 09:08:10
0001 #ifndef NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0003
0004 #if defined(_MSC_VER) || \
0005 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
0006 (__GNUC__ >= 4))
0007 #pragma once
0008 #endif
0009
0010 #include <map>
0011 #include <vector>
0012
0013 #include "ATOOLS/YAML/yaml-cpp/anchor.h"
0014 #include "ATOOLS/YAML/yaml-cpp/node/ptr.h"
0015
0016 namespace SHERPA_YAML {
0017 namespace detail {
0018 class node;
0019 }
0020 }
0021
0022 namespace SHERPA_YAML {
0023 class EventHandler;
0024 class Node;
0025
0026 class NodeEvents {
0027 public:
0028 explicit NodeEvents(const Node& node);
0029 NodeEvents(const NodeEvents&) = delete;
0030 NodeEvents(NodeEvents&&) = delete;
0031 NodeEvents& operator=(const NodeEvents&) = delete;
0032 NodeEvents& operator=(NodeEvents&&) = delete;
0033
0034 void Emit(EventHandler& handler);
0035
0036 private:
0037 class AliasManager {
0038 public:
0039 AliasManager() : m_anchorByIdentity{}, m_curAnchor(0) {}
0040
0041 void RegisterReference(const detail::node& node);
0042 anchor_t LookupAnchor(const detail::node& node) const;
0043
0044 private:
0045 anchor_t _CreateNewAnchor() { return ++m_curAnchor; }
0046
0047 private:
0048 using AnchorByIdentity = std::map<const detail::node_ref*, anchor_t>;
0049 AnchorByIdentity m_anchorByIdentity;
0050
0051 anchor_t m_curAnchor;
0052 };
0053
0054 void Setup(const detail::node& node);
0055 void Emit(const detail::node& node, EventHandler& handler,
0056 AliasManager& am) const;
0057 bool IsAliased(const detail::node& node) const;
0058
0059 private:
0060 detail::shared_memory_holder m_pMemory;
0061 detail::node* m_root;
0062
0063 using RefCount = std::map<const detail::node_ref*, int>;
0064 RefCount m_refCount;
0065 };
0066 }
0067
0068 #endif