From cf06b9ae171a967c6b98ae13c054dd759347cc11 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Thu, 12 Apr 2012 14:27:42 -0400 Subject: [PATCH] * #9782: yamlnode: fixed iterator usage --- daemon/src/config/yamlnode.cpp | 46 ++++++++++++---------------------- daemon/src/config/yamlnode.h | 45 +++++++++++++++++---------------- 2 files changed, 39 insertions(+), 52 deletions(-) diff --git a/daemon/src/config/yamlnode.cpp b/daemon/src/config/yamlnode.cpp index 50adef83d9..f4590a3611 100644 --- a/daemon/src/config/yamlnode.cpp +++ b/daemon/src/config/yamlnode.cpp @@ -34,28 +34,25 @@ namespace Conf { - void YamlDocument::addNode(YamlNode *node) { - Sequence::iterator it = doc.end(); - doc.insert(it, node); + Sequence::iterator it = doc_.end(); + doc_.insert(it, node); } YamlNode *YamlDocument::popNode() { - YamlNode *node = doc.front(); + YamlNode *node = doc_.front(); //removed element's destructor is called - doc.pop_front(); + doc_.pop_front(); return node; } void YamlDocument::deleteChildNodes() { - Sequence::iterator it = doc.begin(); - - while (it != doc.end()) { + for (Sequence::iterator it = doc_.begin(); it != doc_.end(); ++it) { YamlNode *yamlNode = static_cast<YamlNode *>(*it); switch (yamlNode->getType()) { @@ -84,36 +81,31 @@ void YamlDocument::deleteChildNodes() default: break; } - - it++; } } void MappingNode::addNode(YamlNode *node) { - Mapping::iterator it = map.end(); - map.insert(it, std::pair<std::string, YamlNode *> (tmpKey, node)); + setKeyValue(tmpKey_, node); } void MappingNode::setKeyValue(const std::string &key, YamlNode *value) { - Mapping::iterator it = map.end(); - map.insert(it, std::pair<std::string, YamlNode *> (key, value)); + Mapping::iterator it = map_.end(); + map_.insert(it, std::pair<std::string, YamlNode *>(key, value)); } void MappingNode::removeKeyValue(const std::string &key) { - - Mapping::iterator it = map.find(key); - map.erase(it); + Mapping::iterator it = map_.find(key); + map_.erase(it); } - YamlNode *MappingNode::getValue(const std::string &key) const { - Mapping::const_iterator it = map.find(key); + Mapping::const_iterator it = map_.find(key); - if (it != map.end()) { + if (it != map_.end()) { return it->second; } else { DEBUG("MappingNode: Could not find %s", key.c_str()); @@ -124,7 +116,6 @@ YamlNode *MappingNode::getValue(const std::string &key) const void MappingNode::getValue(const std::string &key, bool *b) const { ScalarNode *node = static_cast<ScalarNode*>(getValue(key)); - if (!node) return; @@ -154,9 +145,7 @@ void MappingNode::getValue(const std::string &key, std::string *v) const void MappingNode::deleteChildNodes() { - Mapping::iterator it; - - for (it = map.begin(); it != map.end(); ++it) { + for (Mapping::iterator it = map_.begin(); it != map_.end(); ++it) { YamlNode *yamlNode = static_cast<YamlNode *>(it->second); if (!yamlNode) @@ -193,16 +182,13 @@ void MappingNode::deleteChildNodes() void SequenceNode::addNode(YamlNode *node) { - Sequence::iterator it = seq.end(); - seq.insert(it, node); + Sequence::iterator it = seq_.end(); + seq_.insert(it, node); } - void SequenceNode::deleteChildNodes() { - Sequence::iterator it; - - for (it = seq.begin(); it != seq.end(); ++it) { + for (Sequence::iterator it = seq_.begin(); it != seq_.end(); ++it) { YamlNode *yamlNode = static_cast<YamlNode *>(*it); switch (yamlNode->getType()) { diff --git a/daemon/src/config/yamlnode.h b/daemon/src/config/yamlnode.h index 58f829d7b0..36ca8d6e7f 100644 --- a/daemon/src/config/yamlnode.h +++ b/daemon/src/config/yamlnode.h @@ -48,51 +48,51 @@ enum NodeType { DOCUMENT, SCALAR, MAPPING, SEQUENCE }; class YamlNode { public: - YamlNode(NodeType t, YamlNode *top = NULL) : type(t), topNode(top) {} + YamlNode(NodeType t, YamlNode *top = NULL) : type_(t), topNode_(top) {} virtual ~YamlNode() {} NodeType getType() const { - return type; + return type_; } YamlNode *getTopNode() { - return topNode; + return topNode_; } virtual void deleteChildNodes() = 0; private: NON_COPYABLE(YamlNode); - NodeType type; - YamlNode *topNode; + NodeType type_; + YamlNode *topNode_; }; class YamlDocument : public YamlNode { public: - YamlDocument(YamlNode* top=NULL) : YamlNode(DOCUMENT, top), doc() {} + YamlDocument(YamlNode* top = NULL) : YamlNode(DOCUMENT, top), doc_() {} void addNode(YamlNode *node); YamlNode *popNode(); Sequence *getSequence() { - return &doc; + return &doc_; } virtual void deleteChildNodes(); private: - Sequence doc; + Sequence doc_; }; class SequenceNode : public YamlNode { public: - SequenceNode(YamlNode *top) : YamlNode(SEQUENCE, top), seq() {} + SequenceNode(YamlNode *top) : YamlNode(SEQUENCE, top), seq_() {} Sequence *getSequence() { - return &seq; + return &seq_; } void addNode(YamlNode *node); @@ -100,25 +100,26 @@ class SequenceNode : public YamlNode { virtual void deleteChildNodes(); private: - Sequence seq; + Sequence seq_; }; class MappingNode : public YamlNode { public: - MappingNode(YamlNode *top) : YamlNode(MAPPING, top), map(), tmpKey() {} + MappingNode(YamlNode *top) : + YamlNode(MAPPING, top), map_(), tmpKey_() {} Mapping *getMapping() { - return ↦ + return &map_; } void addNode(YamlNode *node); void setTmpKey(std::string key) { - tmpKey = key; + tmpKey_ = key; } - void setKeyValue(const std::string &key, YamlNode *value); + void setKeyValue(const std::string &key, YamlNode *value); void removeKeyValue(const std::string &key); @@ -130,27 +131,27 @@ class MappingNode : public YamlNode { virtual void deleteChildNodes(); private: - Mapping map; - std::string tmpKey; + Mapping map_; + std::string tmpKey_; }; class ScalarNode : public YamlNode { public: - ScalarNode(std::string s="", YamlNode *top=NULL) : YamlNode(SCALAR, top), str(s) {} - ScalarNode(bool b, YamlNode *top=NULL) : YamlNode(SCALAR, top), str(b ? "true" : "false") {} + ScalarNode(std::string s="", YamlNode *top=NULL) : YamlNode(SCALAR, top), str_(s) {} + ScalarNode(bool b, YamlNode *top=NULL) : YamlNode(SCALAR, top), str_(b ? "true" : "false") {} const std::string &getValue() const { - return str; + return str_; } void setValue(const std::string &s) { - str = s; + str_ = s; } virtual void deleteChildNodes() {} private: - std::string str; + std::string str_; }; } -- GitLab