Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
pugi::xpath_query Class Reference

#include <pugixml.hpp>

Public Member Functions

 xpath_query (const char_t *query, xpath_variable_set *variables=PUGIXML_NULL)
 xpath_query ()
 ~xpath_query ()
xpath_value_type return_type () const
bool evaluate_boolean (const xpath_node &n) const
double evaluate_number (const xpath_node &n) const
string_t evaluate_string (const xpath_node &n) const
size_t evaluate_string (char_t *buffer, size_t capacity, const xpath_node &n) const
xpath_node_set evaluate_node_set (const xpath_node &n) const
xpath_node evaluate_node (const xpath_node &n) const
const xpath_parse_resultresult () const
 operator unspecified_bool_type () const
bool operator! () const

Detailed Description

Definition at line 1216 of file pugixml.hpp.

Constructor & Destructor Documentation

◆ xpath_query() [1/2]

PUGI__FN pugi::xpath_query::xpath_query ( const char_t * query,
xpath_variable_set * variables = PUGIXML_NULL )
explicit

Definition at line 12814 of file pugixml.cc.

12814 : _impl(0)
12815 {
12816 impl::xpath_query_impl* qimpl = impl::xpath_query_impl::create();
12817
12818 if (!qimpl)
12819 {
12820 #ifdef PUGIXML_NO_EXCEPTIONS
12821 _result.error = "Out of memory";
12822 #else
12823 throw std::bad_alloc();
12824 #endif
12825 }
12826 else
12827 {
12828 using impl::auto_deleter; // MSVC7 workaround
12829 auto_deleter<impl::xpath_query_impl> impl(qimpl, impl::xpath_query_impl::destroy);
12830
12831 qimpl->root = impl::xpath_parser::parse(query, variables, &qimpl->alloc, &_result);
12832
12833 if (qimpl->root)
12834 {
12835 qimpl->root->optimize(&qimpl->alloc);
12836
12837 _impl = impl.release();
12838 _result.error = 0;
12839 }
12840 else
12841 {
12842 #ifdef PUGIXML_NO_EXCEPTIONS
12843 if (qimpl->oom) _result.error = "Out of memory";
12844 #else
12845 if (qimpl->oom) throw std::bad_alloc();
12846 throw xpath_exception(_result);
12847 #endif
12848 }
12849 }
12850 }

◆ xpath_query() [2/2]

PUGI__FN pugi::xpath_query::xpath_query ( )

Definition at line 12852 of file pugixml.cc.

12852 : _impl(0)
12853 {
12854 }

◆ ~xpath_query()

PUGI__FN pugi::xpath_query::~xpath_query ( )

Definition at line 12856 of file pugixml.cc.

12857 {
12858 if (_impl)
12859 impl::xpath_query_impl::destroy(static_cast<impl::xpath_query_impl*>(_impl));
12860 }

Member Function Documentation

◆ evaluate_boolean()

PUGI__FN bool pugi::xpath_query::evaluate_boolean ( const xpath_node & n) const

Definition at line 12894 of file pugixml.cc.

12895 {
12896 if (!_impl) return false;
12897
12898 impl::xpath_context c(n, 1, 1);
12899 impl::xpath_stack_data sd;
12900
12901 bool r = static_cast<impl::xpath_query_impl*>(_impl)->root->eval_boolean(c, sd.stack);
12902
12903 if (sd.oom)
12904 {
12905 #ifdef PUGIXML_NO_EXCEPTIONS
12906 return false;
12907 #else
12908 throw std::bad_alloc();
12909 #endif
12910 }
12911
12912 return r;
12913 }

◆ evaluate_node()

PUGI__FN xpath_node pugi::xpath_query::evaluate_node ( const xpath_node & n) const

Definition at line 13011 of file pugixml.cc.

13012 {
13013 impl::xpath_ast_node* root = impl::evaluate_node_set_prepare(static_cast<impl::xpath_query_impl*>(_impl));
13014 if (!root) return xpath_node();
13015
13016 impl::xpath_context c(n, 1, 1);
13017 impl::xpath_stack_data sd;
13018
13019 impl::xpath_node_set_raw r = root->eval_node_set(c, sd.stack, impl::nodeset_eval_first);
13020
13021 if (sd.oom)
13022 {
13023 #ifdef PUGIXML_NO_EXCEPTIONS
13024 return xpath_node();
13025 #else
13026 throw std::bad_alloc();
13027 #endif
13028 }
13029
13030 return r.first();
13031 }

Referenced by pugi::xml_node::select_node(), pugi::xml_node::select_node(), pugi::xml_node::select_single_node(), and pugi::xml_node::select_single_node().

◆ evaluate_node_set()

PUGI__FN xpath_node_set pugi::xpath_query::evaluate_node_set ( const xpath_node & n) const

Definition at line 12989 of file pugixml.cc.

12990 {
12991 impl::xpath_ast_node* root = impl::evaluate_node_set_prepare(static_cast<impl::xpath_query_impl*>(_impl));
12992 if (!root) return xpath_node_set();
12993
12994 impl::xpath_context c(n, 1, 1);
12995 impl::xpath_stack_data sd;
12996
12997 impl::xpath_node_set_raw r = root->eval_node_set(c, sd.stack, impl::nodeset_eval_all);
12998
12999 if (sd.oom)
13000 {
13001 #ifdef PUGIXML_NO_EXCEPTIONS
13002 return xpath_node_set();
13003 #else
13004 throw std::bad_alloc();
13005 #endif
13006 }
13007
13008 return xpath_node_set(r.begin(), r.end(), r.type());
13009 }

Referenced by pugi::xml_node::select_nodes(), and pugi::xml_node::select_nodes().

◆ evaluate_number()

PUGI__FN double pugi::xpath_query::evaluate_number ( const xpath_node & n) const

Definition at line 12915 of file pugixml.cc.

12916 {
12917 if (!_impl) return impl::gen_nan();
12918
12919 impl::xpath_context c(n, 1, 1);
12920 impl::xpath_stack_data sd;
12921
12922 double r = static_cast<impl::xpath_query_impl*>(_impl)->root->eval_number(c, sd.stack);
12923
12924 if (sd.oom)
12925 {
12926 #ifdef PUGIXML_NO_EXCEPTIONS
12927 return impl::gen_nan();
12928 #else
12929 throw std::bad_alloc();
12930 #endif
12931 }
12932
12933 return r;
12934 }

◆ evaluate_string() [1/2]

PUGI__FN size_t pugi::xpath_query::evaluate_string ( char_t * buffer,
size_t capacity,
const xpath_node & n ) const

Definition at line 12959 of file pugixml.cc.

12960 {
12961 impl::xpath_context c(n, 1, 1);
12962 impl::xpath_stack_data sd;
12963
12964 impl::xpath_string r = _impl ? static_cast<impl::xpath_query_impl*>(_impl)->root->eval_string(c, sd.stack) : impl::xpath_string();
12965
12966 if (sd.oom)
12967 {
12968 #ifdef PUGIXML_NO_EXCEPTIONS
12969 r = impl::xpath_string();
12970 #else
12971 throw std::bad_alloc();
12972 #endif
12973 }
12974
12975 size_t full_size = r.length() + 1;
12976
12977 if (capacity > 0)
12978 {
12979 size_t size = (full_size < capacity) ? full_size : capacity;
12980 assert(size > 0);
12981
12982 memcpy(buffer, r.c_str(), (size - 1) * sizeof(char_t));
12983 buffer[size - 1] = 0;
12984 }
12985
12986 return full_size;
12987 }
PUGIXML_CHAR char_t
Definition pugixml.hpp:137

◆ evaluate_string() [2/2]

PUGI__FN string_t pugi::xpath_query::evaluate_string ( const xpath_node & n) const

Definition at line 12937 of file pugixml.cc.

12938 {
12939 if (!_impl) return string_t();
12940
12941 impl::xpath_context c(n, 1, 1);
12942 impl::xpath_stack_data sd;
12943
12944 impl::xpath_string r = static_cast<impl::xpath_query_impl*>(_impl)->root->eval_string(c, sd.stack);
12945
12946 if (sd.oom)
12947 {
12948 #ifdef PUGIXML_NO_EXCEPTIONS
12949 return string_t();
12950 #else
12951 throw std::bad_alloc();
12952 #endif
12953 }
12954
12955 return string_t(r.c_str(), r.length());
12956 }
std::basic_string< PUGIXML_CHAR, std::char_traits< PUGIXML_CHAR >, std::allocator< PUGIXML_CHAR > > string_t
Definition pugixml.hpp:141

◆ operator unspecified_bool_type()

PUGI__FN pugi::xpath_query::operator xpath_query::unspecified_bool_type ( ) const

Definition at line 13042 of file pugixml.cc.

13043 {
13044 return _impl ? unspecified_bool_xpath_query : 0;
13045 }

◆ operator!()

PUGI__FN bool pugi::xpath_query::operator! ( ) const

Definition at line 13047 of file pugixml.cc.

13048 {
13049 return !_impl;
13050 }

◆ result()

PUGI__FN const xpath_parse_result & pugi::xpath_query::result ( ) const

Definition at line 13033 of file pugixml.cc.

13034 {
13035 return _result;
13036 }

◆ return_type()

PUGI__FN xpath_value_type pugi::xpath_query::return_type ( ) const

Definition at line 12887 of file pugixml.cc.

12888 {
12889 if (!_impl) return xpath_type_none;
12890
12891 return static_cast<impl::xpath_query_impl*>(_impl)->root->rettype();
12892 }
@ xpath_type_none
Definition pugixml.hpp:1111

The documentation for this class was generated from the following files: