Commit 24f4cdd8 authored by Alexandre Savard's avatar Alexandre Savard

[#3648] Add document class in yaml nodes

parent 50b3798b
......@@ -33,6 +33,23 @@
namespace Conf {
void YamlDocument::addNode(YamlNode *node)
{
Sequence::iterator it = doc.end();
doc.insert(it, node);
}
YamlNode *YamlDocument::popNode()
{
Sequence::iterator it = doc.begin();
YamlNode *node = doc.front();
//removed element's destructor is called
doc.pop_front();
return node;
}
void MappingNode::setKeyValue(Key key, YamlNode *value)
{
Mapping::iterator it = map.end();
......@@ -50,7 +67,6 @@ void MappingNode::removeKeyValue(Key key)
YamlNode *MappingNode::getValue(Key key)
{
Mapping::iterator it = map.find(key);
return it->second;
}
......@@ -58,11 +74,8 @@ YamlNode *MappingNode::getValue(Key key)
void SequenceNode::addNode(YamlNode *node)
{
Sequence::iterator it = seq.end();
seq.insert(it, node);
}
}
......@@ -46,7 +46,6 @@ typedef std::string Value;
typedef std::list<YamlNode *> Sequence;
typedef std::map<Key, YamlNode *> Mapping;
class YamlNodeException : public std::exception
{
......@@ -66,10 +65,8 @@ class YamlNodeException : public std::exception
};
enum NodeType { DOCUMENT, SCALAR, MAPPING, SEQUENCE };
class YamlNode {
public:
......@@ -87,6 +84,24 @@ class YamlNode {
};
class YamlDocument : YamlNode {
public:
YamlDocument() : YamlNode(DOCUMENT) {}
~YamlDocument() {}
void addNode(YamlNode *node);
YamlNode *popNode();
private:
Sequence doc;
};
class SequenceNode : public YamlNode {
public:
......@@ -147,6 +162,7 @@ class ScalarNode : public YamlNode {
};
}
......
......@@ -191,7 +191,7 @@ void ConfigurationTest::testYamlParser()
void ConfigurationTest::testYamlComposition()
{
Conf::SequenceNode *seq = new Conf::SequenceNode();
Conf::MappingNode *map = new Conf::MappingNode();
Conf::ScalarNode *sclr = new Conf::ScalarNode();
......@@ -218,4 +218,6 @@ void ConfigurationTest::testYamlComposition()
delete map;
delete sclr;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment