32 #include <yaml-cpp/emitter.h> 50 std::ofstream out( qPrintable( filename ));
58 message_ =
"Failed to open " + filename +
" for writing.";
61 catch( std::exception ex )
73 std::stringstream out;
77 return QString::fromStdString( out.str() );
91 YAML::Emitter emitter;
95 out << emitter.c_str() << std::endl;
116 emitter << YAML::BeginSeq;
117 for(
int i = 0; i < config.
listLength(); i++ )
121 emitter << YAML::EndSeq;
126 emitter << YAML::BeginMap;
132 emitter << YAML::Key;
133 emitter << map_iter.
currentKey().toStdString();
134 emitter << YAML::Value;
139 emitter << YAML::EndMap;
144 QString value = config.
getValue().toString();
145 if( value.size() == 0 )
147 emitter << YAML::DoubleQuoted <<
"";
151 emitter << value.toStdString();
156 emitter << YAML::Null;
Type getType() const
Return the Type of the referenced Node, or Invalid if this Config does not refer to a Node at all...
QString errorMessage()
Return an error message if the latest write call had an error, or the empty string if there was no er...
int listLength() const
Returns the length of the List in this Node, or 0 if this Node does not have type List...
Config listChildAt(int i) const
Return the i'th child in the list, if the referenced Node has type List. Returns an Invalid Config if...
QString writeString(const Config &config, const QString &filename="data string")
Write config data to a string, and return it. This potentially changes the return values of error() a...
bool isValid()
Return true if the iterator currently points to a valid entry, false if not.
bool error()
Return true if the latest write operation had an error.
Configuration data storage class.
QString currentKey()
Return the name of the current map entry.
QVariant getValue() const
If this config object is valid and is a Value type, this returns its value. Otherwise it returns an i...
Iterator class for looping over all entries in a Map type Config Node.
void writeFile(const Config &config, const QString &filename)
Write config data to a file. This potentially changes the return values of error() and statusMessage(...
MapIterator mapIterator() const
Return a new iterator for looping over key/value pairs.
YamlConfigWriter()
Constructor. Writer starts in a non-error state.
Config currentChild()
Return a Config reference to the current map entry.
void writeConfigNode(const Config &config, YAML::Emitter &emitter)
void writeStream(const Config &config, std::ostream &out, const QString &filename="data stream")
Write config data to a std::ostream. This potentially changes the return values of error() and status...
void advance()
Advance iterator to next entry.