LCOV - code coverage report
Current view: top level - xml - xml_pugi.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 8 9 88.9 %
Date: 2026-11-09 02:10:49 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef __XML_PUGI_H__
       7             : #define __XML_PUGI_H__
       8             : 
       9             : #include <pugixml/pugixml.hpp>
      10             : 
      11             : class XmlPugi : public XmlBase {
      12             : public:
      13             : 
      14             :     virtual int LoadDoc(const std::string &doc);
      15             :     virtual int WriteDoc(uint8_t *buf);
      16             :     virtual int WriteRawDoc(uint8_t *buf);
      17             :     virtual void PrintDoc(std::ostream& os) const;
      18             :     virtual void PrintDocFormatted(std::ostream& os) const;
      19             :     virtual int AddNode(const std::string &key, const std::string &value);
      20             :     virtual int DeleteNode(const std::string &key);
      21             :     virtual int ModifyNode(const std::string &key, const std::string &value);
      22             :     virtual int AddChildNode(const std::string &key, const std::string &value);
      23             :     virtual int AddChildNodeAfter(const std::string &node_name,
      24             :                                   const std::string &key, const std::string &value);
      25             :     virtual int AddAttribute(const std::string &key, const std::string &value);
      26             :     virtual int DeleteAttribute(const std::string &key);
      27             :     virtual int ModifyAttribute(const std::string &key, const std::string &value);
      28             : 
      29             :     // Read methods
      30             :     virtual const char *ReadNode(const std::string &name);
      31             :     virtual const char *ReadNodeName(const std::string &name);
      32             :     virtual const char *ReadNodeValue();
      33             :     virtual const char *ReadChildNode();
      34             :     virtual const char *ReadChildNodeName();
      35             :     virtual const char *ReadNextNode();
      36             :     virtual const char *ReadNextNodeName();
      37             :     virtual void RewindNode();
      38             : 
      39             :     virtual const char *ReadAttrib(const std::string &str);
      40             :     virtual const char *ReadFirstAttrib();
      41             :     virtual const char *ReadNextAttrib();
      42             :     virtual void RewindAttrib();
      43             : 
      44             :     virtual const char *ReadParentName();
      45             : 
      46             :     // resets node and attributes
      47             :     virtual void RewindDoc();
      48             :     virtual void AppendDoc(const std::string &str, XmlBase *a_doc);
      49             : 
      50             :     pugi::xml_node RootNode();
      51             :     pugi::xml_node FindNode(const std::string &name);
      52             : 
      53             :     XmlPugi();
      54             :     virtual ~XmlPugi();
      55             : 
      56             :     struct xmpp_buf_write : pugi::xml_writer {
      57     4165214 :         xmpp_buf_write(XmlPugi *arg) : ref(arg) {}
      58             :         virtual void write(const void *data, size_t sz);
      59             :         XmlPugi *ref;
      60             :     };
      61             : 
      62             :     void SetBuf(const void *buf, size_t sz);
      63             : 
      64     3510079 :     bool IsNull(pugi::xml_node &node) { return node.type() == pugi::node_null; }
      65       84172 :     bool IsNull(pugi::xml_attribute &attr) {
      66       84172 :         return attr == NULL;
      67             :     }
      68           0 :     void LoadXmlDoc(const pugi::xml_document &doc) {doc_.reset(doc);}
      69         541 :     const pugi::xml_document &doc() {return doc_;}
      70             : 
      71             : private:
      72             :     uint8_t *buf_tmp_;
      73             :     size_t ts_; //temp size
      74             :     struct xmpp_buf_write writer_;
      75             : 
      76             :     pugi::xml_document    doc_;
      77             : 
      78             :     // Foll maintains traversal context
      79             :     pugi::xml_node        node_;
      80             :     pugi::xml_attribute   attrib_;
      81             : 
      82             :     struct PugiPredicate {
      83             :         bool operator()(pugi::xml_attribute attr) const {
      84             :             return (strcmp(attr.name(), tmp_.c_str()) == 0);
      85             :         }
      86    89893944 :         bool operator()(pugi::xml_node node) const {
      87    89893944 :             return (strcmp(node.name(), tmp_.c_str()) == 0);
      88             :         }
      89     5118382 :         PugiPredicate(const std::string &name) : tmp_(name) { }
      90             :         std::string tmp_;
      91             :     };
      92             : 
      93             :     static pugi::xml_attribute GAttr;
      94             :     static pugi::xml_node GNode;
      95             :     void SetContext(pugi::xml_node node = GNode,
      96             :                     pugi::xml_attribute atrib = GAttr);
      97             : 
      98             : };
      99             : 
     100             : #endif //  __XML_PUGI_H__

Generated by: LCOV version 1.14