NCBI C++ ToolKit
libxml2_xmlwrapp.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: libxml2_xmlwrapp.cpp 79080 2017-08-09 18:22:55Z satskyse $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Sergey Satskiy, NCBI
27  * Credits: Denis Vakatov, NCBI (API design)
28  *
29  */
30 
31 
32 /** @file
33  * Extension to work with raw libxml2 objects
34 **/
35 
38 #include "document_impl.hpp"
39 
40 
41 // libxml2 includes
42 #include <libxml/parser.h>
43 
44 
45 namespace xml {
46 
47 
49  ownership_type ownership)
50 {
51  if (raw_doc == NULL)
52  throw xml::exception("invalid raw libxml2 document (NULL)");
53 
54  set_doc_data(raw_doc);
55  set_ownership(ownership);
56 }
57 
58 
60 {
62 }
63 
64 
65 libxml2_document::libxml2_document(const char * filename,
66  error_messages * messages,
68  document(filename, messages, how)
69 {
71 }
72 
73 
75  error_messages* messages,
77  document(data, size, messages, how)
78 {
80 }
81 
82 
83 libxml2_document::libxml2_document(const char *root_name) :
84  document(root_name)
85 {
87 }
88 
89 
91  document(n)
92 {
94 }
95 
96 
98  document(doc_proxy)
99 {
101 }
102 
103 
105  error_messages * messages,
107  document(stream, messages, how)
108 {
110 }
111 
112 
114  document(std::move(other))
115 {}
116 
117 
120 {
121  if (this != &other) {
122  document::operator=(std::move(other));
123  }
124  return *this;
125 }
126 
128 {
129  return static_cast<xmlDoc *>(get_doc_data());
130 }
131 
132 
133 void libxml2_document::set_raw_doc(xmlDoc * raw_doc,
134  ownership_type ownership)
135 {
136  if (raw_doc == NULL)
137  throw xml::exception("invalid raw libxml2 document (NULL)");
138 
139  if (raw_doc == get_raw_doc()) {
140  set_ownership(ownership);
141  return;
142  }
143 
144  // set_doc_data(...) will free the document if we owe it.
145  set_doc_data(raw_doc);
146  set_ownership(ownership);
147 }
148 
149 
151 {
152  if (pimpl_->get_ownership())
153  return type_own;
154  return type_not_own;
155 }
156 
157 
159 {
160  pimpl_->set_ownership(ownership == type_own);
161 }
162 
163 } // namespace xml
164 
The xml::document_proxy class to be a relay between XSLT results and the document.
The xml::document class is used to hold the XML tree and various bits of information about it.
Definition: document.hpp:80
impl::doc_impl * pimpl_
Definition: document.hpp:770
void set_doc_data(void *data)
Definition: document.cpp:998
document & operator=(const document &other)
Copy another document object into this one using the assignment operator.
Definition: document.cpp:501
std::size_t size_type
size type
Definition: document.hpp:83
void * get_doc_data(void)
Definition: document.cpp:1020
The xml::error_messages class is used to store all the error message which are collected while parsin...
Definition: errors.hpp:137
This exception class is thrown by xmlwrapp for all runtime XML-related errors along with the xml::par...
Definition: exception.hpp:64
Extension to the xml::document class which allows working with raw libxml2 documents.
xmlDoc * get_raw_doc(void)
Provides a raw libxml2 document.
void set_raw_doc(xmlDoc *raw_doc, ownership_type ownership)
Set a raw libxml2 document.
ownership_type get_ownership(void) const
Provides the document ownership type.
void set_ownership(ownership_type ownership)
Set the document ownership.
libxml2_document(void)
Create a new XML document with the default settings.
libxml2_document & operator=(libxml2_document &&other)
Moving assignment.
The xml::node class is used to hold information about one XML node.
Definition: node.hpp:106
char data[12]
Definition: iconv.c:80
#define NULL
Definition: ncbistd.hpp:225
yy_size_t n
Extension to work with raw libxml2 objects.
This file contains the definition of the xml::exception class.
const struct ncbi::grid::netcache::search::fields::SIZE size
XML library namespace.
Definition: attributes.hpp:57
ownership_type
Used to specify if xmlwrapp should grab the ownership of various objects.
Definition: ownership.hpp:43
@ type_not_own
Do not grab the ownership, i.e.
Definition: ownership.hpp:46
@ type_own
Grab the ownership, i.e.
Definition: ownership.hpp:44
warnings_as_errors_type
A type for different approaches to process warnings.
Definition: errors.hpp:259
void set_ownership(bool owe)
bool get_ownership(void) const
Modified on Wed Sep 04 14:58:29 2024 by modify_doxy.py rev. 669887