Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
xpath_string Class Reference

Public Member Functions

 xpath_string ()
 
 xpath_string (const char_t *str, xpath_allocator *alloc)
 
 xpath_string (const char_t *str, bool use_heap)
 
 xpath_string (const char_t *begin, const char_t *end, xpath_allocator *alloc)
 
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 Private Member Functions

static char_t * duplicate_string (const char_t *string, size_t length, xpath_allocator *alloc)
 
static char_t * duplicate_string (const char_t *string, xpath_allocator *alloc)
 

Private Attributes

const char_t * _buffer
 
bool _uses_heap
 

Detailed Description

Definition at line 6402 of file pugixml.cpp.

Constructor & Destructor Documentation

◆ xpath_string() [1/4]

xpath_string::xpath_string ( )
inline

Definition at line 6424 of file pugixml.cpp.

6424  : _buffer(PUGIXML_TEXT("")), _uses_heap(false)
6425  {
6426  }

◆ xpath_string() [2/4]

xpath_string::xpath_string ( const char_t *  str,
xpath_allocator alloc 
)
inlineexplicit

Definition at line 6428 of file pugixml.cpp.

6429  {
6430  bool empty_ = (*str == 0);
6431 
6432  _buffer = empty_ ? PUGIXML_TEXT("") : duplicate_string(str, alloc);
6433  _uses_heap = !empty_;
6434  }

References _buffer, _uses_heap, and duplicate_string().

◆ xpath_string() [3/4]

xpath_string::xpath_string ( const char_t *  str,
bool  use_heap 
)
inlineexplicit

Definition at line 6436 of file pugixml.cpp.

6436  : _buffer(str), _uses_heap(use_heap)
6437  {
6438  }

◆ xpath_string() [4/4]

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

Definition at line 6440 of file pugixml.cpp.

6441  {
6442  assert(begin <= end);
6443 
6444  bool empty_ = (begin == end);
6445 
6446  _buffer = empty_ ? PUGIXML_TEXT("") : duplicate_string(begin, static_cast<size_t>(end - begin), alloc);
6447  _uses_heap = !empty_;
6448  }

References _buffer, _uses_heap, and duplicate_string().

Member Function Documentation

◆ append()

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

Definition at line 6450 of file pugixml.cpp.

6451  {
6452  // skip empty sources
6453  if (!*o._buffer) return;
6454 
6455  // fast append for constant empty target and constant source
6456  if (!*_buffer && !_uses_heap && !o._uses_heap)
6457  {
6458  _buffer = o._buffer;
6459  }
6460  else
6461  {
6462  // need to make heap copy
6463  size_t target_length = strlength(_buffer);
6464  size_t source_length = strlength(o._buffer);
6465  size_t result_length = target_length + source_length;
6466 
6467  // allocate new buffer
6468  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)));
6469  assert(result);
6470 
6471  // append first string to the new buffer in case there was no reallocation
6472  if (!_uses_heap) memcpy(result, _buffer, target_length * sizeof(char_t));
6473 
6474  // append second string to the new buffer
6475  memcpy(result + target_length, o._buffer, source_length * sizeof(char_t));
6476  result[result_length] = 0;
6477 
6478  // finalize
6479  _buffer = result;
6480  _uses_heap = true;
6481  }
6482  }

References _buffer, _uses_heap, xpath_allocator::reallocate(), and strlength().

Referenced by string_value().

◆ c_str()

const char_t* xpath_string::c_str ( ) const
inline

◆ data()

char_t* xpath_string::data ( xpath_allocator alloc)
inline

Definition at line 6494 of file pugixml.cpp.

6495  {
6496  // make private heap copy
6497  if (!_uses_heap)
6498  {
6499  _buffer = duplicate_string(_buffer, alloc);
6500  _uses_heap = true;
6501  }
6502 
6503  return const_cast<char_t*>(_buffer);
6504  }

References _buffer, _uses_heap, and duplicate_string().

Referenced by xpath_ast_node::eval_string().

◆ duplicate_string() [1/2]

static char_t* xpath_string::duplicate_string ( const char_t *  string,
size_t  length,
xpath_allocator alloc 
)
inlinestaticprivate

Definition at line 6407 of file pugixml.cpp.

6408  {
6409  char_t* result = static_cast<char_t*>(alloc->allocate((length + 1) * sizeof(char_t)));
6410  assert(result);
6411 
6412  memcpy(result, string, length * sizeof(char_t));
6413  result[length] = 0;
6414 
6415  return result;
6416  }

References xpath_allocator::allocate(), and length().

Referenced by data(), duplicate_string(), and xpath_string().

◆ duplicate_string() [2/2]

static char_t* xpath_string::duplicate_string ( const char_t *  string,
xpath_allocator alloc 
)
inlinestaticprivate

Definition at line 6418 of file pugixml.cpp.

6419  {
6420  return duplicate_string(string, strlength(string), alloc);
6421  }

References duplicate_string(), and strlength().

◆ empty()

bool xpath_string::empty ( ) const
inline

Definition at line 6506 of file pugixml.cpp.

6507  {
6508  return *_buffer == 0;
6509  }

References _buffer.

Referenced by xpath_ast_node::eval_boolean().

◆ length()

size_t xpath_string::length ( ) const
inline

Definition at line 6489 of file pugixml.cpp.

6490  {
6491  return strlength(_buffer);
6492  }

References _buffer, and strlength().

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

◆ operator!=()

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

Definition at line 6516 of file pugixml.cpp.

6517  {
6518  return !strequal(_buffer, o._buffer);
6519  }

References _buffer, and strequal().

◆ operator==()

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

Definition at line 6511 of file pugixml.cpp.

6512  {
6513  return strequal(_buffer, o._buffer);
6514  }

References _buffer, and strequal().

◆ uses_heap()

bool xpath_string::uses_heap ( ) const
inline

Definition at line 6521 of file pugixml.cpp.

6522  {
6523  return _uses_heap;
6524  }

References _uses_heap.

Referenced by xpath_ast_node::eval_string().

Member Data Documentation

◆ _buffer

const char_t* xpath_string::_buffer
private

Definition at line 6404 of file pugixml.cpp.

Referenced by append(), c_str(), data(), empty(), length(), operator!=(), operator==(), and xpath_string().

◆ _uses_heap

bool xpath_string::_uses_heap
private

Definition at line 6405 of file pugixml.cpp.

Referenced by append(), data(), uses_heap(), and xpath_string().


The documentation for this class was generated from the following file:
strlength
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN size_t strlength(const char_t *s)
Definition: pugixml.cpp:176
xpath_string::_buffer
const char_t * _buffer
Definition: pugixml.cpp:6404
xpath_string::duplicate_string
static char_t * duplicate_string(const char_t *string, size_t length, xpath_allocator *alloc)
Definition: pugixml.cpp:6407
xpath_allocator::reallocate
void * reallocate(void *ptr, size_t old_size, size_t new_size)
Definition: pugixml.cpp:6267
strequal
PUGI__FN bool strequal(const char_t *src, const char_t *dst)
Definition: pugixml.cpp:188
xpath_string::length
size_t length() const
Definition: pugixml.cpp:6489
xpath_allocator::allocate
void * allocate(size_t size)
Definition: pugixml.cpp:6250
xpath_string::_uses_heap
bool _uses_heap
Definition: pugixml.cpp:6405

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001