nodeevents.h 1.5 KB

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