1 // Copyright 2018 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CORE_FXCRT_XML_CFX_XMLDOCUMENT_H_ 6 #define CORE_FXCRT_XML_CFX_XMLDOCUMENT_H_ 7 8 #include <memory> 9 #include <utility> 10 #include <vector> 11 12 #include "core/fxcrt/unowned_ptr.h" 13 #include "core/fxcrt/xml/cfx_xmlelement.h" 14 #include "third_party/base/ptr_util.h" 15 16 class CFX_XMLNode; 17 18 class CFX_XMLDocument { 19 public: 20 CFX_XMLDocument(); 21 ~CFX_XMLDocument(); 22 GetRoot()23 CFX_XMLElement* GetRoot() const { return root_.Get(); } 24 25 template <typename T, typename... Args> CreateNode(Args &&...args)26 T* CreateNode(Args&&... args) { 27 nodes_.push_back(pdfium::MakeUnique<T>(std::forward<Args>(args)...)); 28 return static_cast<T*>(nodes_.back().get()); 29 } 30 31 // Transfers ownership of entries in |nodes_| from |other| to |this|. 32 // This is used in CJX_Node::loadXML to transfer ownership of the newly 33 // created nodes to the top-level XML doc for the PDF, after parsing an XML 34 // blob. 35 void AppendNodesFrom(CFX_XMLDocument* other); 36 37 private: 38 std::vector<std::unique_ptr<CFX_XMLNode>> nodes_; 39 UnownedPtr<CFX_XMLElement> root_; 40 }; 41 42 #endif // CORE_FXCRT_XML_CFX_XMLDOCUMENT_H_ 43