Newer
Older
arseny.kapoulkine
committed
*/
bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, encoding_t encoding = encoding_auto) const;
arseny.kapoulkine
committed
/**
* Compute document order for the whole tree
* Sometimes this makes evaluation of XPath queries faster.
*/
arseny.kapoulkine
committed
PUGIXML_DEPRECATED void precompute_document_order();
arseny.kapoulkine
committed
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
};
#ifndef PUGIXML_NO_XPATH
/**
* XPath exception class.
*/
class PUGIXML_CLASS xpath_exception: public std::exception
{
private:
const char* m_message;
public:
/**
* Construct exception from static error string
*
* \param message - error string
*/
explicit xpath_exception(const char* message);
/**
* Return error message
*
* \return error message
*/
virtual const char* what() const throw();
};
/**
* XPath node class.
*
* XPath defines node to be either xml_node or xml_attribute in pugixml terminology, so xpath_node
* is either xml_node or xml_attribute.
*/
class PUGIXML_CLASS xpath_node
{
private:
xml_node m_node;
xml_attribute m_attribute;
/// \internal Safe bool type
typedef xml_node xpath_node::*unspecified_bool_type;
public:
/**
* Construct empty XPath node
*/
xpath_node();
/**
* Construct XPath node from XML node
*
* \param node - XML node
*/
xpath_node(const xml_node& node);
/**
* Construct XPath node from XML attribute
*
* \param attribute - XML attribute
* \param parent - attribute's parent node
*/
xpath_node(const xml_attribute& attribute, const xml_node& parent);
/**
* Get XML node, if any
*
* \return contained XML node, empty node otherwise
*/
xml_node node() const;
/**
* Get XML attribute, if any
*
* \return contained XML attribute, if any, empty attribute otherwise
*/
xml_attribute attribute() const;
/**
* Get parent of contained XML attribute, if any
*
* \return parent of contained XML attribute, if any, empty node otherwise
*/
xml_node parent() const;
/**
* Safe bool conversion.
* Allows xpath_node to be used in a context where boolean variable is expected, such as 'if (node)'.
*/
operator unspecified_bool_type() const;
arseny.kapoulkine
committed
// Borland C++ workaround
bool operator!() const;
arseny.kapoulkine
committed
/**
* Compares two XPath nodes
*
* \param n - XPath node to compare to
* \return comparison result
*/
bool operator==(const xpath_node& n) const;
/**
* Compares two XPath nodes
*
* \param n - XPath node to compare to
* \return comparison result
*/
bool operator!=(const xpath_node& n) const;
};
arseny.kapoulkine
committed
#ifdef __BORLANDC__
// Borland C++ workaround
bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
#endif
arseny.kapoulkine
committed
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
/**
* Not necessarily ordered constant collection of XPath nodes
*/
class PUGIXML_CLASS xpath_node_set
{
friend class xpath_ast_node;
public:
/// Collection type
enum type_t
{
type_unsorted, ///< Not ordered
type_sorted, ///< Sorted by document order (ascending)
type_sorted_reverse ///< Sorted by document order (descending)
};
/// Constant iterator type
typedef const xpath_node* const_iterator;
private:
type_t m_type;
xpath_node m_storage;
xpath_node* m_begin;
xpath_node* m_end;
xpath_node* m_eos;
typedef xpath_node* iterator;
iterator mut_begin();
void push_back(const xpath_node& n);
void append(const_iterator begin, const_iterator end);
arseny.kapoulkine
committed
void truncate(iterator it);
void remove_duplicates();
public:
/**
arseny.kapoulkine
committed
* Constructs empty set
*/
xpath_node_set();
/**
arseny.kapoulkine
committed
*/
~xpath_node_set();
/**
arseny.kapoulkine
committed
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
*
* \param ns - set to copy
*/
xpath_node_set(const xpath_node_set& ns);
/**
* Assignment operator
*
* \param ns - set to assign
* \return self
*/
xpath_node_set& operator=(const xpath_node_set& ns);
/**
* Get collection type
*
* \return collection type
*/
type_t type() const;
/**
* Get collection size
*
* \return collection size
*/
size_t size() const;
arseny.kapoulkine
committed
/**
* Get element with the specified index
*
* \param index - requested index
* \return element
*/
xpath_node operator[](size_t index) const;
arseny.kapoulkine
committed
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
/**
* Get begin constant iterator for collection
*
* \return begin constant iterator
*/
const_iterator begin() const;
/**
* Get end iterator for collection
*
* \return end iterator
*/
const_iterator end() const;
/**
* Sort the collection in ascending/descending order by document order
*
* \param reverse - whether to sort in ascending (false) or descending (true) order
*/
void sort(bool reverse = false);
/**
* Get first node in the collection by document order
*
* \return first node by document order
arseny.kapoulkine
committed
* \note set.first() is not equal to set[0], since operator[] does not take document order into account
arseny.kapoulkine
committed
*/
xpath_node first() const;
/**
* Return true if collection is empty
*
* \return true if collection is empty, false otherwise
*/
bool empty() const;
};
#endif
#ifndef PUGIXML_NO_STL
/**
arseny.kapoulkine
committed
*
* \param str - input wide string string
arseny.kapoulkine
committed
* \return output UTF8 string
*/
std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
arseny.kapoulkine
committed
*
* \param str - input UTF8 string
* \return output wide string string
*
* \deprecated This function is deprecated and will be removed in future versions; use as_wide instead
PUGIXML_DEPRECATED std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_utf16(const char* str);
arseny.kapoulkine
committed
/**
arseny.kapoulkine
committed
*
* \param str - input UTF8 string
* \return output wide string string
arseny.kapoulkine
committed
*/
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
arseny.kapoulkine
committed
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
#endif
/**
* Memory allocation function
*
* \param size - allocation size
* \return pointer to allocated memory on success, NULL on failure
*/
typedef void* (*allocation_function)(size_t size);
/**
* Memory deallocation function
*
* \param ptr - pointer to memory previously allocated by allocation function
*/
typedef void (*deallocation_function)(void* ptr);
/**
* Override default memory management functions
*
* All subsequent allocations/deallocations will be performed via supplied functions. Take care not to
* change memory management functions if any xml_document instances are still alive - this is considered
* undefined behaviour (expect crashes/memory damages/etc.).
*
* \param allocate - allocation function
* \param deallocate - deallocation function
*
* \note XPath-related allocations, as well as allocations in functions that return std::string (xml_node::path, as_utf8, as_wide)
arseny.kapoulkine
committed
* are not performed via these functions.
* \note If you're using parse() with ownership transfer, you have to allocate the buffer you pass to parse() with allocation
* function you set via this function.
*/
void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
arseny.kapoulkine
committed
/**
* Get current memory allocation function
*
* \return memory allocation function
* \see set_memory_management_functions
*/
allocation_function PUGIXML_FUNCTION get_memory_allocation_function();
/**
* Get current memory deallocation function
*
* \return memory deallocation function
* \see set_memory_management_functions
*/
deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function();
arseny.kapoulkine
committed
}
#if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
namespace std
{
// Workarounds for (non-standard) iterator category detection for older versions (MSVC7/IC8 and earlier)
std::bidirectional_iterator_tag _Iter_cat(const pugi::xml_node_iterator&);
std::bidirectional_iterator_tag _Iter_cat(const pugi::xml_attribute_iterator&);
}
#endif
#if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
namespace std
{
// Workarounds for (non-standard) iterator category detection
std::bidirectional_iterator_tag __iterator_category(const pugi::xml_node_iterator&);
std::bidirectional_iterator_tag __iterator_category(const pugi::xml_attribute_iterator&);
}
#endif
arseny.kapoulkine
committed
#endif
arseny.kapoulkine
committed
/**
* Copyright (c) 2006-2010 Arseny Kapoulkine
arseny.kapoulkine
committed
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/