emittermanip.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #ifndef EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  2. #define EMITTERMANIP_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 <string>
  9. namespace YAML {
  10. enum EMITTER_MANIP {
  11. // general manipulators
  12. Auto,
  13. TagByKind,
  14. Newline,
  15. // output character set
  16. EmitNonAscii,
  17. EscapeNonAscii,
  18. // string manipulators
  19. // Auto, // duplicate
  20. SingleQuoted,
  21. DoubleQuoted,
  22. Literal,
  23. // bool manipulators
  24. YesNoBool, // yes, no
  25. TrueFalseBool, // true, false
  26. OnOffBool, // on, off
  27. UpperCase, // TRUE, N
  28. LowerCase, // f, yes
  29. CamelCase, // No, Off
  30. LongBool, // yes, On
  31. ShortBool, // y, t
  32. // int manipulators
  33. Dec,
  34. Hex,
  35. Oct,
  36. // document manipulators
  37. BeginDoc,
  38. EndDoc,
  39. // sequence manipulators
  40. BeginSeq,
  41. EndSeq,
  42. Flow,
  43. Block,
  44. // map manipulators
  45. BeginMap,
  46. EndMap,
  47. Key,
  48. Value,
  49. // Flow, // duplicate
  50. // Block, // duplicate
  51. // Auto, // duplicate
  52. LongKey
  53. };
  54. struct _Indent {
  55. _Indent(int value_) : value(value_) {}
  56. int value;
  57. };
  58. inline _Indent Indent(int value) { return _Indent(value); }
  59. struct _Alias {
  60. _Alias(const std::string& content_) : content(content_) {}
  61. std::string content;
  62. };
  63. inline _Alias Alias(const std::string& content) { return _Alias(content); }
  64. struct _Anchor {
  65. _Anchor(const std::string& content_) : content(content_) {}
  66. std::string content;
  67. };
  68. inline _Anchor Anchor(const std::string& content) { return _Anchor(content); }
  69. struct _Tag {
  70. struct Type {
  71. enum value { Verbatim, PrimaryHandle, NamedHandle };
  72. };
  73. explicit _Tag(const std::string& prefix_, const std::string& content_,
  74. Type::value type_)
  75. : prefix(prefix_), content(content_), type(type_) {}
  76. std::string prefix;
  77. std::string content;
  78. Type::value type;
  79. };
  80. inline _Tag VerbatimTag(const std::string& content) {
  81. return _Tag("", content, _Tag::Type::Verbatim);
  82. }
  83. inline _Tag LocalTag(const std::string& content) {
  84. return _Tag("", content, _Tag::Type::PrimaryHandle);
  85. }
  86. inline _Tag LocalTag(const std::string& prefix, const std::string content) {
  87. return _Tag(prefix, content, _Tag::Type::NamedHandle);
  88. }
  89. inline _Tag SecondaryTag(const std::string& content) {
  90. return _Tag("", content, _Tag::Type::NamedHandle);
  91. }
  92. struct _Comment {
  93. _Comment(const std::string& content_) : content(content_) {}
  94. std::string content;
  95. };
  96. inline _Comment Comment(const std::string& content) { return _Comment(content); }
  97. struct _Precision {
  98. _Precision(int floatPrecision_, int doublePrecision_)
  99. : floatPrecision(floatPrecision_), doublePrecision(doublePrecision_) {}
  100. int floatPrecision;
  101. int doublePrecision;
  102. };
  103. inline _Precision FloatPrecision(int n) { return _Precision(n, -1); }
  104. inline _Precision DoublePrecision(int n) { return _Precision(-1, n); }
  105. inline _Precision Precision(int n) { return _Precision(n, n); }
  106. }
  107. #endif // EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66