Skip to content
Snippets Groups Projects
Commit 24f4cdd8 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#3648] Add document class in yaml nodes

parent 50b3798b
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,23 @@ ...@@ -33,6 +33,23 @@
namespace Conf { 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) void MappingNode::setKeyValue(Key key, YamlNode *value)
{ {
Mapping::iterator it = map.end(); Mapping::iterator it = map.end();
...@@ -50,7 +67,6 @@ void MappingNode::removeKeyValue(Key key) ...@@ -50,7 +67,6 @@ void MappingNode::removeKeyValue(Key key)
YamlNode *MappingNode::getValue(Key key) YamlNode *MappingNode::getValue(Key key)
{ {
Mapping::iterator it = map.find(key); Mapping::iterator it = map.find(key);
return it->second; return it->second;
} }
...@@ -58,11 +74,8 @@ YamlNode *MappingNode::getValue(Key key) ...@@ -58,11 +74,8 @@ YamlNode *MappingNode::getValue(Key key)
void SequenceNode::addNode(YamlNode *node) void SequenceNode::addNode(YamlNode *node)
{ {
Sequence::iterator it = seq.end(); Sequence::iterator it = seq.end();
seq.insert(it, node); seq.insert(it, node);
} }
} }
...@@ -46,7 +46,6 @@ typedef std::string Value; ...@@ -46,7 +46,6 @@ typedef std::string Value;
typedef std::list<YamlNode *> Sequence; typedef std::list<YamlNode *> Sequence;
typedef std::map<Key, YamlNode *> Mapping; typedef std::map<Key, YamlNode *> Mapping;
class YamlNodeException : public std::exception class YamlNodeException : public std::exception
{ {
...@@ -66,10 +65,8 @@ class YamlNodeException : public std::exception ...@@ -66,10 +65,8 @@ class YamlNodeException : public std::exception
}; };
enum NodeType { DOCUMENT, SCALAR, MAPPING, SEQUENCE }; enum NodeType { DOCUMENT, SCALAR, MAPPING, SEQUENCE };
class YamlNode { class YamlNode {
public: public:
...@@ -87,6 +84,24 @@ class YamlNode { ...@@ -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 { class SequenceNode : public YamlNode {
public: public:
...@@ -147,6 +162,7 @@ class ScalarNode : public YamlNode { ...@@ -147,6 +162,7 @@ class ScalarNode : public YamlNode {
}; };
} }
......
...@@ -218,4 +218,6 @@ void ConfigurationTest::testYamlComposition() ...@@ -218,4 +218,6 @@ void ConfigurationTest::testYamlComposition()
delete map; delete map;
delete sclr; delete sclr;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment