stlemitter.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  2. #define STLEMITTER_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 <list>
  10. #include <set>
  11. #include <map>
  12. namespace YAML {
  13. template <typename Seq>
  14. inline Emitter& EmitSeq(Emitter& emitter, const Seq& seq) {
  15. emitter << BeginSeq;
  16. for (const auto& v : seq)
  17. emitter << v;
  18. emitter << EndSeq;
  19. return emitter;
  20. }
  21. template <typename T>
  22. inline Emitter& operator<<(Emitter& emitter, const std::vector<T>& v) {
  23. return EmitSeq(emitter, v);
  24. }
  25. template <typename T>
  26. inline Emitter& operator<<(Emitter& emitter, const std::list<T>& v) {
  27. return EmitSeq(emitter, v);
  28. }
  29. template <typename T>
  30. inline Emitter& operator<<(Emitter& emitter, const std::set<T>& v) {
  31. return EmitSeq(emitter, v);
  32. }
  33. template <typename K, typename V>
  34. inline Emitter& operator<<(Emitter& emitter, const std::map<K, V>& m) {
  35. emitter << BeginMap;
  36. for (const auto& v : m)
  37. emitter << Key << v.first << Value << v.second;
  38. emitter << EndMap;
  39. return emitter;
  40. }
  41. }
  42. #endif // STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66