33 #include <yaml-cpp/yaml.h> 44 std::ifstream in(qPrintable(filename));
50 std::stringstream ss(data.toStdString());
59 yaml_node = YAML::Load(in);
64 catch (YAML::ParserException& ex)
73 switch (yaml_node.Type())
75 case YAML::NodeType::Map:
77 for (YAML::const_iterator it = yaml_node.begin(); it != yaml_node.end(); ++it)
80 key = it->first.as<std::string>();
86 case YAML::NodeType::Sequence:
88 for (YAML::const_iterator it = yaml_node.begin(); it != yaml_node.end(); ++it)
95 case YAML::NodeType::Scalar:
98 s = yaml_node.as<std::string>();
99 config.
setValue(QString::fromStdString(s));
102 case YAML::NodeType::Null:
void readYamlNode(Config &config, const YAML::Node &yaml_node)
void setValue(const QVariant &value)
Ensures this is a valid Config object, sets the type to Value then sets the value.
QString errorMessage()
Return an error message if the latest read call had an error, or the empty string if not...
void readStream(Config &config, std::istream &in, const QString &filename="data stream")
Read config data from a std::istream. This potentially changes the return value sof error()...
YamlConfigReader()
Constructor. Object begins in a no-error state.
Configuration data storage class.
void readFile(Config &config, const QString &filename)
Read config data from a file. This potentially changes the return value sof error(), statusMessage(), and config().
Config mapMakeChild(const QString &key)
Create a child node stored with the given key, and return the child.
bool error()
Return true if the latest readFile() or readString() call had an error.
Config listAppendNew()
Ensure the referenced Node is of type List, append a new Empty Node to the end of the list...
void readString(Config &config, const QString &data, const QString &filename="data string")
Read config data from a string. This potentially changes the return value sof error(), statusMessage(), and config().