NCBI C++ ToolKit
xml_init.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org)
3  * All Rights Reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name of the Author nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
23  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 /*
34  * $Id: xml_init.hpp 69205 2015-10-09 13:38:47Z satskyse $
35  * NOTE: This file was modified from its original version 0.6.0
36  * to fit the NCBI C++ Toolkit build framework and
37  * API and functionality requirements.
38  */
39 
40 /** @file
41  * This file contains the definition of the xml::init class.
42 **/
43 
44 #ifndef _xmlwrapp_init_h_
45 #define _xmlwrapp_init_h_
46 
47 /// XML library namespace
48 namespace xml {
49 
50 /**
51  * The xml::init class is used to configure the XML parser.
52  *
53  * If you want to use and of the xml::init member functions, do so before
54  * you start any threads or use any other part of xmlwrapp. The member
55  * functions may alter global and/or static variables and affect the behavior
56  * of subsequently created classes (and the parser in particular).
57  * In other words, this class is not thread safe.
58  *
59  * @note In xmlwrapp versions prior to 0.6.0, this class was used to initialize
60  * the library and exactly one instance had to be created before first
61  * use. This is no longer true: user code doesn't have to create any
62  * instances, but it @em can create as many instances as it wants.
63 **/
64 class init {
65 public:
66  init (void);
67  virtual ~init (void);
68 
69  //####################################################################
70  /**
71  * This member function controls whether or not the XML parser should
72  * add text nodes for indenting when generating XML text output from a
73  * node tree. The default is true.
74  *
75  * @param flag True to turn on indenting, false to turn it off.
76  * @author Peter Jones
77  **/
78  //####################################################################
79  static void indent_output (bool flag);
80 
81  //####################################################################
82  /**
83  * This member function controls whether or not the XML parser should
84  * remove ignorable whitespace around XML elements. The default
85  * is false.
86  * The setting is per thread.
87  *
88  * @param flag True to remove whitespace, false to leave alone.
89  * @sa xml::init::get_remove_whitespace()
90  * @author Peter Jones
91  **/
92  //####################################################################
93  static void remove_whitespace (bool flag);
94 
95  //####################################################################
96  /**
97  * This member function provides the current setting of the XML parser
98  * which tells whether it should remove ignorable whitespace around XML
99  * elements.
100  *
101  * @return True if the parser will remove whitespace, false to leave alone.
102  * @sa xml::init::remove_whitespace()
103  **/
104  //####################################################################
105  static bool get_remove_whitespace (void);
106 
107  //####################################################################
108  /**
109  * This member function controls whether or not the XML parser should
110  * substitute entities while parsing. The default is true.
111  *
112  * @note see the xml::event_parser::text(...) and
113  * xml::event_parser::entity_reference(...) callback notes as they
114  * are affected by this flag.
115  * @param flag True to turn on substitution, false to turn off.
116  * @author Peter Jones
117  **/
118  //####################################################################
119  static void substitute_entities (bool flag);
120 
121  //####################################################################
122  /**
123  * This member function controls whether or not the XML parser should
124  * load external (DTD) subsets while parsing. This will only affect the
125  * loading of the subsets, it does not cause files to be validated. The
126  * default is true.
127  *
128  * @param flag True to turn on loading, false to turn it off.
129  * @author Peter Jones
130  **/
131  //####################################################################
132  static void load_external_subsets (bool flag);
133 
134  //####################################################################
135  /**
136  * This member function controls whether or not the XML parser should
137  * validate every XML document that is parses with its DTD. The default
138  * is false.
139  *
140  * @param flag True to turn on validation, false to turn it off.
141  * @author Peter Jones
142  **/
143  //####################################################################
144  static void validate_xml (bool flag);
145 
146  //####################################################################
147  /**
148  * This member function controls whether or not the libxml2 library data
149  * will be cleaned up at exit. The default is true.
150  *
151  * @note By default the library clears all the libxml2 data at exit.
152  * However it is possible that some parts of an application interact
153  * with libxml2 directly and might call the libxml2 library cleanup
154  * too. In mutithreaded applications double cleaning of the libxml2
155  * data may lead to a crash.
156  * This member provides a workaround for the cases when multiple
157  * parties cleanup libxml2 data at exit in multithreaded applications.
158  * It is supposed that at the beginning of the application there is
159  * a call similar to the following:
160  * xml::init::library_cleanup_on_exit(false);
161  * and it is the application responsibility to make sure that
162  * XmlWrapp finishes data handling before the other part of the
163  * application calls xmlCleanupParser().
164  *
165  * @param flag True to turn on libxml2 cleanup at exit, false to turn it
166  * off.
167  * @author Denis Vakatov
168  **/
169  //####################################################################
170  static void library_cleanup_on_exit (bool flag);
171 
172 private:
173  init (const init&);
174  init& operator= (const init&);
175 
176  void init_library();
177  void shutdown_library();
178 
179  static int ms_counter;
180  static bool do_cleanup_at_exit;
181 }; // end xml::init class
182 
183 } // end xml namespace
184 
185 // use a "nifty counter" to ensure that any source file that uses xmlwrapp
186 // will initialize the library prior to its first use
187 namespace {
188  xml::init g_xmlwrapp_initializer;
189 }
190 
191 #endif
The xml::init class is used to configure the XML parser.
Definition: xml_init.hpp:64
virtual ~init(void)
Definition: xml_init.cpp:67
void shutdown_library()
Definition: xml_init.cpp:93
static void validate_xml(bool flag)
This member function controls whether or not the XML parser should validate every XML document that i...
Definition: xml_init.cpp:118
static void substitute_entities(bool flag)
This member function controls whether or not the XML parser should substitute entities while parsing.
Definition: xml_init.cpp:110
static void library_cleanup_on_exit(bool flag)
This member function controls whether or not the libxml2 library data will be cleaned up at exit.
Definition: xml_init.cpp:122
static bool get_remove_whitespace(void)
This member function provides the current setting of the XML parser which tells whether it should rem...
Definition: xml_init.cpp:106
static void remove_whitespace(bool flag)
This member function controls whether or not the XML parser should remove ignorable whitespace around...
Definition: xml_init.cpp:102
init(void)
Definition: xml_init.cpp:62
void init_library()
Definition: xml_init.cpp:72
init(const init &)
static int ms_counter
Definition: xml_init.hpp:179
init & operator=(const init &)
static bool do_cleanup_at_exit
Definition: xml_init.hpp:180
static void load_external_subsets(bool flag)
This member function controls whether or not the XML parser should load external (DTD) subsets while ...
Definition: xml_init.cpp:114
static void indent_output(bool flag)
This member function controls whether or not the XML parser should add text nodes for indenting when ...
Definition: xml_init.cpp:98
XML library namespace.
Definition: attributes.hpp:57
Modified on Wed Apr 17 13:08:28 2024 by modify_doxy.py rev. 669887