5 #ifndef CNOID_UTIL_YAML_WRITER_H_INCLUDED
6 #define CNOID_UTIL_YAML_WRITER_H_INCLUDED
12 #include <boost/lexical_cast.hpp>
13 #include <boost/intrusive_ptr.hpp>
27 void setIndentWidth(
int n);
28 void setKeyOrderPreservationMode(
bool on);
32 void putComment(
const std::string& comment,
bool doNewLine =
true);
34 void putString(
const std::string& value);
35 void putSingleQuotedString(
const std::string& value);
36 void putDoubleQuotedString(
const std::string& value);
37 void putBlockStyleString(
const std::string& value,
bool isLiteral);
38 inline void putLiteralString(
const std::string& value) { putBlockStyleString(value,
true); }
39 inline void putFoldedString(
const std::string& value) { putBlockStyleString(value,
false); }
41 template <
class DataType>
inline void putScalar(
const DataType& value){
42 putString(boost::lexical_cast<std::string>(value));
45 void putScalar(
const double& value);
46 void setDoubleFormat(
const char* format);
49 void startFlowStyleMapping();
53 template <
class DataType>
inline void putKeyValue(
const std::string& key,
const DataType& value){
58 inline void putKeyValue(
const std::string& key,
const std::string& value){
60 putDoubleQuotedString(value);
66 void startFlowStyleSequence();
75 bool isCurrentNewLine;
77 bool isKeyOrderPreservationMode;
78 bool doInsertLineFeed;
80 const char* doubleFormat;
82 enum {
TOP, MAPPING, SEQUENCE };
88 bool hasValuesBeenPut;
89 std::string indentString;
92 std::stack<State> states;
97 State& pushState(
int type,
bool isFlowStyle);
101 bool makeValuePutReady();
102 bool startValuePut();
104 void putString_(
const std::string& value);
105 void putSingleQuotedString_(
const std::string& value);
106 void putDoubleQuotedString_(
const std::string& value);
108 void startMappingSub(
bool isFlowStyle);
109 void startSequenceSub(
bool isFlowStyle);
110 void putMappingNode(
const YamlMapping* mapping);
111 void putSequenceNode(
const YamlSequence* sequence);