Public Member Functions | Static Private Member Functions | Private Attributes
xpath_string Class Reference

List of all members.

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

Definition at line 6424 of file pugixml.cpp.

                              : _buffer(PUGIXML_TEXT("")), _uses_heap(false)
                {
                }
xpath_string::xpath_string ( const char_t *  str,
xpath_allocator alloc 
) [inline, explicit]

Definition at line 6428 of file pugixml.cpp.

References _buffer, _uses_heap, and duplicate_string().

                {
                        bool empty_ = (*str == 0);

                        _buffer = empty_ ? PUGIXML_TEXT("") : duplicate_string(str, alloc);
                        _uses_heap = !empty_;
                }
xpath_string::xpath_string ( const char_t *  str,
bool  use_heap 
) [inline, explicit]

Definition at line 6436 of file pugixml.cpp.

                                                                       : _buffer(str), _uses_heap(use_heap)
                {
                }
xpath_string::xpath_string ( const char_t *  begin,
const char_t *  end,
xpath_allocator alloc 
) [inline]

Definition at line 6440 of file pugixml.cpp.

References _buffer, _uses_heap, and duplicate_string().

                {
                        assert(begin <= end);

                        bool empty_ = (begin == end);

                        _buffer = empty_ ? PUGIXML_TEXT("") : duplicate_string(begin, static_cast<size_t>(end - begin), alloc);
                        _uses_heap = !empty_;
                }

Member Function Documentation

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

Definition at line 6450 of file pugixml.cpp.

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

Referenced by string_value().

                {
                        // skip empty sources
                        if (!*o._buffer) return;

                        // fast append for constant empty target and constant source
                        if (!*_buffer && !_uses_heap && !o._uses_heap)
                        {
                                _buffer = o._buffer;
                        }
                        else
                        {
                                // need to make heap copy
                                size_t target_length = strlength(_buffer);
                                size_t source_length = strlength(o._buffer);
                                size_t result_length = target_length + source_length;

                                // allocate new buffer
                                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)));
                                assert(result);

                                // append first string to the new buffer in case there was no reallocation
                                if (!_uses_heap) memcpy(result, _buffer, target_length * sizeof(char_t));

                                // append second string to the new buffer
                                memcpy(result + target_length, o._buffer, source_length * sizeof(char_t));
                                result[result_length] = 0;

                                // finalize
                                _buffer = result;
                                _uses_heap = true;
                        }
                }
const char_t* xpath_string::c_str ( ) const [inline]
char_t* xpath_string::data ( xpath_allocator alloc) [inline]

Definition at line 6494 of file pugixml.cpp.

References _buffer, _uses_heap, and duplicate_string().

Referenced by xpath_ast_node::eval_string().

                {
                        // make private heap copy
                        if (!_uses_heap)
                        {
                                _buffer = duplicate_string(_buffer, alloc);
                                _uses_heap = true;
                        }

                        return const_cast<char_t*>(_buffer);
                }
static char_t* xpath_string::duplicate_string ( const char_t *  string,
size_t  length,
xpath_allocator alloc 
) [inline, static, private]

Definition at line 6407 of file pugixml.cpp.

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

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

                {
                        char_t* result = static_cast<char_t*>(alloc->allocate((length + 1) * sizeof(char_t)));
                        assert(result);

                        memcpy(result, string, length * sizeof(char_t));
                        result[length] = 0;

                        return result;
                }
static char_t* xpath_string::duplicate_string ( const char_t *  string,
xpath_allocator alloc 
) [inline, static, private]

Definition at line 6418 of file pugixml.cpp.

References duplicate_string(), and strlength().

                {
                        return duplicate_string(string, strlength(string), alloc);
                }
bool xpath_string::empty ( ) const [inline]

Definition at line 6506 of file pugixml.cpp.

References _buffer.

Referenced by xpath_ast_node::eval_boolean().

                {
                        return *_buffer == 0;
                }
size_t xpath_string::length ( ) const [inline]

Definition at line 6489 of file pugixml.cpp.

References _buffer, and strlength().

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

                {
                        return strlength(_buffer);
                }
bool xpath_string::operator!= ( const xpath_string o) const [inline]

Definition at line 6516 of file pugixml.cpp.

References _buffer, and strequal().

                {
                        return !strequal(_buffer, o._buffer);
                }
bool xpath_string::operator== ( const xpath_string o) const [inline]

Definition at line 6511 of file pugixml.cpp.

References _buffer, and strequal().

                {
                        return strequal(_buffer, o._buffer);
                }
bool xpath_string::uses_heap ( ) const [inline]

Definition at line 6521 of file pugixml.cpp.

References _uses_heap.

Referenced by xpath_ast_node::eval_string().

                {
                        return _uses_heap;
                }

Member Data Documentation

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().

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:

Generated on Mon Sep 15 2014 01:23:56 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001