| 1 | /* |
| 2 | www.sourceforge.net/projects/tinyxpath |
| 3 | Copyright (c) 2002-2004 Yves Berquin ([email protected]) |
| 4 | |
| 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the authors be held liable for any |
| 7 | damages arising from the use of this software. |
| 8 | |
| 9 | Permission is granted to anyone to use this software for any |
| 10 | purpose, including commercial applications, and to alter it and |
| 11 | redistribute it freely, subject to the following restrictions: |
| 12 | |
| 13 | 1. The origin of this software must not be misrepresented; you must |
| 14 | not claim that you wrote the original software. If you use this |
| 15 | software in a product, an acknowledgment in the product documentation |
| 16 | would be appreciated but is not required. |
| 17 | |
| 18 | 2. Altered source versions must be plainly marked as such, and |
| 19 | must not be misrepresented as being the original software. |
| 20 | |
| 21 | 3. This notice may not be removed or altered from any source |
| 22 | distribution. |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | \file xpath_static.cpp |
| 27 | \author Yves Berquin |
| 28 | */ |
| 29 | |
| 30 | #include "xpath_static.h" |
| 31 | |
| 32 | namespace TinyXPath |
| 33 | { |
| 34 | /// Static function to compute an integer XPath expression, without an error check |
| 35 | int i_xpath_int (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr) |
| 36 | { |
| 37 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 38 | return xp_proc . i_compute_xpath (); |
| 39 | } |
| 40 | |
| 41 | /// Static function to compute a double XPath expression, without an error check |
| 42 | double d_xpath_double (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr) |
| 43 | { |
| 44 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 45 | return xp_proc . d_compute_xpath (); |
| 46 | } |
| 47 | |
| 48 | /// Static function to compute a bool XPath expression, without an error check |
| 49 | bool o_xpath_bool (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr) |
| 50 | { |
| 51 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 52 | return xp_proc . o_compute_xpath (); |
| 53 | } |
| 54 | |
| 55 | /// Static function to compute a string XPath expression, without an error check |
| 56 | TIXML_STRING S_xpath_string (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr) |
| 57 | { |
| 58 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 59 | return xp_proc . S_compute_xpath (); |
| 60 | } |
| 61 | |
| 62 | /// Static function to compute a node XPath expression, without an error check |
| 63 | TiXmlNode * XNp_xpath_node (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr) |
| 64 | { |
| 65 | unsigned u_nb; |
| 66 | |
| 67 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 68 | u_nb = xp_proc . u_compute_xpath_node_set (); |
| 69 | if (! u_nb) |
| 70 | return NULL; |
| 71 | return xp_proc . XNp_get_xpath_node (0); |
| 72 | } |
| 73 | |
| 74 | /// Static function to compute an attribute XPath expression, without an error check |
| 75 | TiXmlAttribute * XAp_xpath_attribute (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr) |
| 76 | { |
| 77 | unsigned u_nb; |
| 78 | |
| 79 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 80 | u_nb = xp_proc . u_compute_xpath_node_set (); |
| 81 | if (! u_nb) |
| 82 | return NULL; |
| 83 | return xp_proc . XAp_get_xpath_attribute (0); |
| 84 | } |
| 85 | |
| 86 | /// Static function to compute an integer XPath expression, with an error check |
| 87 | bool o_xpath_int (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr, int & i_res) |
| 88 | { |
| 89 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 90 | i_res = xp_proc . i_compute_xpath (); |
| 91 | return xp_proc . e_error == TinyXPath::xpath_processor::e_no_error; |
| 92 | } |
| 93 | |
| 94 | /// Static function to compute a double XPath expression, without an error check |
| 95 | bool o_xpath_double (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr, double & d_res) |
| 96 | { |
| 97 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 98 | d_res = xp_proc . d_compute_xpath (); |
| 99 | return xp_proc . e_error == TinyXPath::xpath_processor::e_no_error; |
| 100 | } |
| 101 | |
| 102 | /// Static function to compute a bool XPath expression, without an error check |
| 103 | bool o_xpath_bool (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr, bool & o_res) |
| 104 | { |
| 105 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 106 | o_res = xp_proc . o_compute_xpath (); |
| 107 | return xp_proc . e_error == TinyXPath::xpath_processor::e_no_error; |
| 108 | } |
| 109 | |
| 110 | /// Static function to compute a string XPath expression, without an error check |
| 111 | bool o_xpath_string (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr, TIXML_STRING & S_res) |
| 112 | { |
| 113 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 114 | S_res = xp_proc . S_compute_xpath (); |
| 115 | return xp_proc . e_error == TinyXPath::xpath_processor::e_no_error; |
| 116 | } |
| 117 | |
| 118 | /// Static function to compute a node XPath expression, without an error check |
| 119 | bool o_xpath_node (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr, const TiXmlNode * & XNp_node) |
| 120 | { |
| 121 | unsigned u_nb; |
| 122 | |
| 123 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 124 | u_nb = xp_proc . u_compute_xpath_node_set (); |
| 125 | if (! u_nb) |
| 126 | return false; |
| 127 | XNp_node = xp_proc . XNp_get_xpath_node (0); |
| 128 | return xp_proc . e_error == TinyXPath::xpath_processor::e_no_error; |
| 129 | } |
| 130 | |
| 131 | /// Static function to compute an attribute XPath expression, without an error check |
| 132 | bool o_xpath_attribute (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr, const TiXmlAttribute * & XAp_attrib) |
| 133 | { |
| 134 | unsigned u_nb; |
| 135 | |
| 136 | xpath_processor xp_proc (XNp_source_tree, cp_xpath_expr); |
| 137 | u_nb = xp_proc . u_compute_xpath_node_set (); |
| 138 | if (! u_nb) |
| 139 | return false; |
| 140 | XAp_attrib = xp_proc . XAp_get_xpath_attribute (0); |
| 141 | return xp_proc . e_error == TinyXPath::xpath_processor::e_no_error; |
| 142 | } |
| 143 | } |