27 #include <QTextStream> 46 GAIA_DEFINE_EXCEPTION(YamlException);
60 typedef QString Scalar;
61 typedef QList<Node> Sequence;
62 typedef GaiaMap<Node, Node, YamlException> Mapping;
75 #define yamlCheckType(input_type) if (type() != input_type##Type) throw YamlException("Type is not a "#input_type) 87 Node() : _type(ScalarType), _scalar(
"") {}
88 Node(
const QString& str) : _type(ScalarType), _scalar(str) {}
89 Node(
const char* str) : _type(ScalarType), _scalar(QString::fromUtf8(str)) {}
90 Node(
const std::string& str) : _type(ScalarType), _scalar(QString::fromUtf8(str.c_str(), (int)str.size())) {}
91 Node(
const Sequence& seq) : _type(SequenceType), _sequence(seq) {}
92 Node(
const Mapping& mapping) : _type(MappingType), _mapping(mapping) {}
94 Node(
const Node& n) : _type(n._type),
96 _sequence(n._sequence),
97 _mapping(n._mapping) {}
100 QString toString()
const {
111 operator QString()
const {
115 bool operator==(
const Node& rhs)
const {
116 if (_type != rhs._type)
return false;
119 case ScalarType:
return _scalar == rhs._scalar;
120 case SequenceType:
return _sequence == rhs._sequence;
121 case MappingType:
return _mapping == rhs._mapping;
132 if (_type != rhs._type)
return _type < rhs._type;
135 case ScalarType:
return _scalar < rhs._scalar;
137 return std::lexicographical_compare(_sequence.begin(), _sequence.end(),
138 rhs._sequence.begin(), rhs._sequence.end());
140 return std::lexicographical_compare(_mapping.begin(), _mapping.end(),
141 rhs._mapping.begin(), rhs._mapping.end());
148 NodeType type()
const {
return _type; }
152 const Scalar& scalar()
const {
153 yamlCheckType(Scalar);
158 yamlCheckType(Scalar);
162 const Sequence& sequence()
const {
163 yamlCheckType(Sequence);
167 Sequence& sequence() {
168 yamlCheckType(Sequence);
172 const Mapping& mapping()
const {
173 yamlCheckType(Mapping);
178 yamlCheckType(Mapping);
184 const Node& operator[](
int i)
const {
185 return sequence()[i];
188 Node& operator[](
int i) {
189 return sequence()[i];
192 const Node& operator[](
const Node& node)
const {
193 return mapping()[node];
196 Node& operator[](
const Node& node) {
197 return mapping()[node];
201 friend std::ostream& operator<<(std::ostream& out,
const gaia2::yaml::Node& node);
212 Node loadFromString(
const std::string& str,
bool markQuotedScalars =
false);
214 Node load(
const char* str, uint size,
bool markQuotedScalars =
false);
216 Node load(
const QString& str);
218 QByteArray dump(
const Node& node);
225 Node loadFromFile(
const QString& filename,
bool markQuotedScalars =
false);
229 switch (node.type()) {
230 case yaml::ScalarType:
return out << node.scalar();
231 case yaml::MappingType:
return out << node.mapping();
232 case yaml::SequenceType:
return out << node.sequence();
235 return out <<
"Unknown Type";
Definition: debugging.h:82
bool operator<(const Node &rhs) const
Definition: yamlcpp.h:131
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22