anchordict.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  2. #define ANCHORDICT_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 <vector>
  9. #include "../anchor.h"
  10. namespace YAML {
  11. /**
  12. * An object that stores and retrieves values correlating to {@link anchor_t}
  13. * values.
  14. *
  15. * <p>Efficient implementation that can make assumptions about how
  16. * {@code anchor_t} values are assigned by the {@link Parser} class.
  17. */
  18. template <class T>
  19. class AnchorDict {
  20. public:
  21. AnchorDict() : m_data{} {}
  22. void Register(anchor_t anchor, T value) {
  23. if (anchor > m_data.size()) {
  24. m_data.resize(anchor);
  25. }
  26. m_data[anchor - 1] = value;
  27. }
  28. T Get(anchor_t anchor) const { return m_data[anchor - 1]; }
  29. private:
  30. std::vector<T> m_data;
  31. };
  32. } // namespace YAML
  33. #endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66