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

Public Member Functions

 xpath_string ()
void append (const xpath_string &o, xpath_allocator *alloc)
const char_t * c_str () const
size_t length () const
char_t * data (xpath_allocator *alloc)
bool empty () const
bool operator== (const xpath_string &o) const
bool operator!= (const xpath_string &o) const
bool uses_heap () const

Static Public Member Functions

static xpath_string from_const (const char_t *str)
static xpath_string from_heap_preallocated (const char_t *begin, const char_t *end)
static xpath_string from_heap (const char_t *begin, const char_t *end, xpath_allocator *alloc)

Detailed Description

Definition at line 7945 of file pugixml.cc.

Constructor & Destructor Documentation

◆ xpath_string()

xpath_string::xpath_string ( )
inline

Definition at line 7992 of file pugixml.cc.

7992 : _buffer(PUGIXML_TEXT("")), _uses_heap(false), _length_heap(0)
7993 {
7994 }
#define PUGIXML_TEXT(t)
Definition pugixml.hpp:130

Referenced by from_const(), from_heap(), and from_heap_preallocated().

Member Function Documentation

◆ append()

void xpath_string::append ( const xpath_string & o,
xpath_allocator * alloc )
inline

Definition at line 7996 of file pugixml.cc.

7997 {
7998 // skip empty sources
7999 if (!*o._buffer) return;
8000
8001 // fast append for constant empty target and constant source
8002 if (!*_buffer && !_uses_heap && !o._uses_heap)
8003 {
8004 _buffer = o._buffer;
8005 }
8006 else
8007 {
8008 // need to make heap copy
8009 size_t target_length = length();
8010 size_t source_length = o.length();
8011 size_t result_length = target_length + source_length;
8012
8013 // allocate new buffer
8014 char_t* result = static_cast<char_t*>(alloc->reallocate(_uses_heap ? const_cast<char_t*>(_buffer) : 0, (target_length + 1) * sizeof(char_t), (result_length + 1) * sizeof(char_t)));
8015 if (!result) return;
8016
8017 // append first string to the new buffer in case there was no reallocation
8018 if (!_uses_heap) memcpy(result, _buffer, target_length * sizeof(char_t));
8019
8020 // append second string to the new buffer
8021 memcpy(result + target_length, o._buffer, source_length * sizeof(char_t));
8022 result[result_length] = 0;
8023
8024 // finalize
8025 _buffer = result;
8026 _uses_heap = true;
8027 _length_heap = result_length;
8028 }
8029 }
size_t length() const
Definition pugixml.cc:8036
PUGIXML_CHAR char_t
Definition pugixml.hpp:137
void * reallocate(void *ptr, size_t old_size, size_t new_size)
Definition pugixml.cc:7815

Referenced by string_value().

◆ c_str()

const char_t * xpath_string::c_str ( ) const
inline

Definition at line 8031 of file pugixml.cc.

8032 {
8033 return _buffer;
8034 }

Referenced by xpath_ast_node::eval_boolean(), xpath_ast_node::eval_number(), and xpath_ast_node::eval_string().

◆ data()

char_t * xpath_string::data ( xpath_allocator * alloc)
inline

Definition at line 8041 of file pugixml.cc.

8042 {
8043 // make private heap copy
8044 if (!_uses_heap)
8045 {
8046 size_t length_ = strlength(_buffer);
8047 const char_t* data_ = duplicate_string(_buffer, length_, alloc);
8048
8049 if (!data_) return 0;
8050
8051 _buffer = data_;
8052 _uses_heap = true;
8053 _length_heap = length_;
8054 }
8055
8056 return const_cast<char_t*>(_buffer);
8057 }
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN size_t strlength(const char_t *s)
Definition pugixml.cc:214

Referenced by from_heap().

◆ empty()

bool xpath_string::empty ( ) const
inline

Definition at line 8059 of file pugixml.cc.

8060 {
8061 return *_buffer == 0;
8062 }

Referenced by xpath_ast_node::eval_boolean().

◆ from_const()

xpath_string xpath_string::from_const ( const char_t * str)
inlinestatic

Definition at line 7967 of file pugixml.cc.

7968 {
7969 return xpath_string(str, false, 0);
7970 }

Referenced by convert_number_to_string(), xpath_ast_node::eval_string(), and string_value().

◆ from_heap()

xpath_string xpath_string::from_heap ( const char_t * begin,
const char_t * end,
xpath_allocator * alloc )
inlinestatic

Definition at line 7979 of file pugixml.cc.

7980 {
7981 assert(begin <= end);
7982
7983 if (begin == end)
7984 return xpath_string();
7985
7986 size_t length = static_cast<size_t>(end - begin);
7987 const char_t* data = duplicate_string(begin, length, alloc);
7988
7989 return data ? xpath_string(data, true, length) : xpath_string();
7990 }
char_t * data(xpath_allocator *alloc)
Definition pugixml.cc:8041

Referenced by xpath_ast_node::eval_string().

◆ from_heap_preallocated()

xpath_string xpath_string::from_heap_preallocated ( const char_t * begin,
const char_t * end )
inlinestatic

Definition at line 7972 of file pugixml.cc.

7973 {
7974 assert(begin <= end && *end == 0);
7975
7976 return xpath_string(begin, true, static_cast<size_t>(end - begin));
7977 }

Referenced by convert_number_to_string(), xpath_ast_node::eval_string(), and xpath_ast_node::eval_string_concat().

◆ length()

size_t xpath_string::length ( ) const
inline

Definition at line 8036 of file pugixml.cc.

8037 {
8038 return _uses_heap ? _length_heap : strlength(_buffer);
8039 }

Referenced by append(), xpath_ast_node::eval_number(), xpath_ast_node::eval_string(), and from_heap().

◆ operator!=()

bool xpath_string::operator!= ( const xpath_string & o) const
inline

Definition at line 8069 of file pugixml.cc.

8070 {
8071 return !strequal(_buffer, o._buffer);
8072 }
PUGI__FN bool strequal(const char_t *src, const char_t *dst)
Definition pugixml.cc:226

◆ operator==()

bool xpath_string::operator== ( const xpath_string & o) const
inline

Definition at line 8064 of file pugixml.cc.

8065 {
8066 return strequal(_buffer, o._buffer);
8067 }

◆ uses_heap()

bool xpath_string::uses_heap ( ) const
inline

Definition at line 8074 of file pugixml.cc.

8075 {
8076 return _uses_heap;
8077 }

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