stlemitter.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 (typename Seq::const_iterator it = seq.begin(); it != seq.end(); ++it)
  17. emitter << *it;
  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. typedef typename std::map<K, V> map;
  36. emitter << BeginMap;
  37. for (typename map::const_iterator it = m.begin(); it != m.end(); ++it)
  38. emitter << Key << it->first << Value << it->second;
  39. emitter << EndMap;
  40. return emitter;
  41. }
  42. }
  43. #endif // STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66