anchordict.h 1009 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. void Register(anchor_t anchor, T value) {
  22. if (anchor > m_data.size()) {
  23. m_data.resize(anchor);
  24. }
  25. m_data[anchor - 1] = value;
  26. }
  27. T Get(anchor_t anchor) const { return m_data[anchor - 1]; }
  28. private:
  29. std::vector<T> m_data;
  30. };
  31. }
  32. #endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66