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

Public Types

enum  { bufcapacitybytes , bufcapacity = bufcapacitybytes / (sizeof(char_t) + 4) }

Public Member Functions

 xml_buffered_writer (xml_writer &writer_, xml_encoding user_encoding)
size_t flush ()
void flush (const char_t *data, size_t size)
void write_direct (const char_t *data, size_t length)
void write_buffer (const char_t *data, size_t length)
void write_string (const char_t *data)
void write (char_t d0)
void write (char_t d0, char_t d1)
void write (char_t d0, char_t d1, char_t d2)
void write (char_t d0, char_t d1, char_t d2, char_t d3)
void write (char_t d0, char_t d1, char_t d2, char_t d3, char_t d4)
void write (char_t d0, char_t d1, char_t d2, char_t d3, char_t d4, char_t d5)

Public Attributes

char_t buffer [bufcapacity]
union { 
   uint8_t   data_u8 [4 *bufcapacity
   uint16_t   data_u16 [2 *bufcapacity
   uint32_t   data_u32 [bufcapacity
   char_t   data_char [bufcapacity
scratch
xml_writer & writer
size_t bufsize
xml_encoding encoding

Detailed Description

Definition at line 3709 of file pugixml.cc.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
bufcapacitybytes 
bufcapacity 

Definition at line 3896 of file pugixml.cc.

3897 {
3899 #ifdef PUGIXML_MEMORY_OUTPUT_STACK
3900 PUGIXML_MEMORY_OUTPUT_STACK
3901 #else
3902 10240
3903 #endif
3904 ,
3905 bufcapacity = bufcapacitybytes / (sizeof(char_t) + 4)
3906 };
PUGIXML_CHAR char_t
Definition pugixml.hpp:137

Constructor & Destructor Documentation

◆ xml_buffered_writer()

xml_buffered_writer::xml_buffered_writer ( xml_writer & writer_,
xml_encoding user_encoding )
inline

Definition at line 3715 of file pugixml.cc.

3715 : writer(writer_), bufsize(0), encoding(get_write_encoding(user_encoding))
3716 {
3718 }
xml_writer & writer
Definition pugixml.cc:3918
xml_encoding encoding
Definition pugixml.cc:3920
#define PUGI__STATIC_ASSERT(cond)
Definition pugixml.cc:100
PUGI__FN xml_encoding get_write_encoding(xml_encoding encoding)
Definition pugixml.cc:3580

Member Function Documentation

◆ flush() [1/2]

size_t xml_buffered_writer::flush ( )
inline

Definition at line 3720 of file pugixml.cc.

3721 {
3723 bufsize = 0;
3724 return 0;
3725 }
char_t buffer[bufcapacity]
Definition pugixml.cc:3908

Referenced by flush(), write(), write(), write(), write(), write(), write(), and write_direct().

◆ flush() [2/2]

void xml_buffered_writer::flush ( const char_t * data,
size_t size )
inline

Definition at line 3727 of file pugixml.cc.

3728 {
3729 if (size == 0) return;
3730
3731 // fast path, just write data
3733 writer.write(data, size * sizeof(char_t));
3734 else
3735 {
3736 // convert chunk
3737 size_t result = convert_buffer_output(scratch.data_char, scratch.data_u8, scratch.data_u16, scratch.data_u32, data, size, encoding);
3738 assert(result <= sizeof(scratch));
3739
3740 // write data
3741 writer.write(scratch.data_u8, result);
3742 }
3743 }
union xml_buffered_writer::@104357024213305245331023314105133003030225137026 scratch
PUGI__FN xml_encoding get_write_native_encoding()
Definition pugixml.cc:3571
PUGI__FN size_t convert_buffer_output(char_t *, uint8_t *r_u8, uint16_t *r_u16, uint32_t *r_u32, const char_t *data, size_t length, xml_encoding encoding)
Definition pugixml.cc:3685

◆ write() [1/6]

void xml_buffered_writer::write ( char_t d0)
inline

Definition at line 3824 of file pugixml.cc.

3825 {
3826 size_t offset = bufsize;
3827 if (offset > bufcapacity - 1) offset = flush();
3828
3829 buffer[offset + 0] = d0;
3830 bufsize = offset + 1;
3831 }
G4ThreadLocal T * G4GeomSplitter< T >::offset

◆ write() [2/6]

void xml_buffered_writer::write ( char_t d0,
char_t d1 )
inline

Definition at line 3833 of file pugixml.cc.

3834 {
3835 size_t offset = bufsize;
3836 if (offset > bufcapacity - 2) offset = flush();
3837
3838 buffer[offset + 0] = d0;
3839 buffer[offset + 1] = d1;
3840 bufsize = offset + 2;
3841 }

◆ write() [3/6]

void xml_buffered_writer::write ( char_t d0,
char_t d1,
char_t d2 )
inline

Definition at line 3843 of file pugixml.cc.

3844 {
3845 size_t offset = bufsize;
3846 if (offset > bufcapacity - 3) offset = flush();
3847
3848 buffer[offset + 0] = d0;
3849 buffer[offset + 1] = d1;
3850 buffer[offset + 2] = d2;
3851 bufsize = offset + 3;
3852 }

◆ write() [4/6]

void xml_buffered_writer::write ( char_t d0,
char_t d1,
char_t d2,
char_t d3 )
inline

Definition at line 3854 of file pugixml.cc.

3855 {
3856 size_t offset = bufsize;
3857 if (offset > bufcapacity - 4) offset = flush();
3858
3859 buffer[offset + 0] = d0;
3860 buffer[offset + 1] = d1;
3861 buffer[offset + 2] = d2;
3862 buffer[offset + 3] = d3;
3863 bufsize = offset + 4;
3864 }

◆ write() [5/6]

void xml_buffered_writer::write ( char_t d0,
char_t d1,
char_t d2,
char_t d3,
char_t d4 )
inline

Definition at line 3866 of file pugixml.cc.

3867 {
3868 size_t offset = bufsize;
3869 if (offset > bufcapacity - 5) offset = flush();
3870
3871 buffer[offset + 0] = d0;
3872 buffer[offset + 1] = d1;
3873 buffer[offset + 2] = d2;
3874 buffer[offset + 3] = d3;
3875 buffer[offset + 4] = d4;
3876 bufsize = offset + 5;
3877 }

◆ write() [6/6]

void xml_buffered_writer::write ( char_t d0,
char_t d1,
char_t d2,
char_t d3,
char_t d4,
char_t d5 )
inline

Definition at line 3879 of file pugixml.cc.

3880 {
3881 size_t offset = bufsize;
3882 if (offset > bufcapacity - 6) offset = flush();
3883
3884 buffer[offset + 0] = d0;
3885 buffer[offset + 1] = d1;
3886 buffer[offset + 2] = d2;
3887 buffer[offset + 3] = d3;
3888 buffer[offset + 4] = d4;
3889 buffer[offset + 5] = d5;
3890 bufsize = offset + 6;
3891 }

◆ write_buffer()

void xml_buffered_writer::write_buffer ( const char_t * data,
size_t length )
inline

Definition at line 3784 of file pugixml.cc.

3785 {
3786 size_t offset = bufsize;
3787
3788 if (offset + length <= bufcapacity)
3789 {
3790 memcpy(buffer + offset, data, length * sizeof(char_t));
3791 bufsize = offset + length;
3792 }
3793 else
3794 {
3795 write_direct(data, length);
3796 }
3797 }
void write_direct(const char_t *data, size_t length)
Definition pugixml.cc:3745

◆ write_direct()

void xml_buffered_writer::write_direct ( const char_t * data,
size_t length )
inline

Definition at line 3745 of file pugixml.cc.

3746 {
3747 // flush the remaining buffer contents
3748 flush();
3749
3750 // handle large chunks
3751 if (length > bufcapacity)
3752 {
3754 {
3755 // fast path, can just write data chunk
3756 writer.write(data, length * sizeof(char_t));
3757 return;
3758 }
3759
3760 // need to convert in suitable chunks
3761 while (length > bufcapacity)
3762 {
3763 // get chunk size by selecting such number of characters that are guaranteed to fit into scratch buffer
3764 // and form a complete codepoint sequence (i.e. discard start of last codepoint if necessary)
3765 size_t chunk_size = get_valid_length(data, bufcapacity);
3766 assert(chunk_size);
3767
3768 // convert chunk and write
3769 flush(data, chunk_size);
3770
3771 // iterate
3772 data += chunk_size;
3773 length -= chunk_size;
3774 }
3775
3776 // small tail is copied below
3777 bufsize = 0;
3778 }
3779
3780 memcpy(buffer + bufsize, data, length * sizeof(char_t));
3781 bufsize += length;
3782 }
PUGI__FN size_t get_valid_length(const char_t *data, size_t length)
Definition pugixml.cc:3669

Referenced by write_buffer(), and write_string().

◆ write_string()

void xml_buffered_writer::write_string ( const char_t * data)
inline

Definition at line 3799 of file pugixml.cc.

3800 {
3801 // write the part of the string that fits in the buffer
3802 size_t offset = bufsize;
3803
3804 while (*data && offset < bufcapacity)
3805 buffer[offset++] = *data++;
3806
3807 // write the rest
3808 if (offset < bufcapacity)
3809 {
3810 bufsize = offset;
3811 }
3812 else
3813 {
3814 // backtrack a bit if we have split the codepoint
3815 size_t length = offset - bufsize;
3816 size_t extra = length - get_valid_length(data - length, length);
3817
3818 bufsize = offset - extra;
3819
3820 write_direct(data - extra, strlength(data) + extra);
3821 }
3822 }
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN size_t strlength(const char_t *s)
Definition pugixml.cc:214

Member Data Documentation

◆ buffer

char_t xml_buffered_writer::buffer[bufcapacity]

◆ bufsize

size_t xml_buffered_writer::bufsize

◆ data_char

char_t xml_buffered_writer::data_char[bufcapacity]

Definition at line 3915 of file pugixml.cc.

◆ data_u16

uint16_t xml_buffered_writer::data_u16[2 *bufcapacity]

Definition at line 3913 of file pugixml.cc.

◆ data_u32

uint32_t xml_buffered_writer::data_u32[bufcapacity]

Definition at line 3914 of file pugixml.cc.

◆ data_u8

uint8_t xml_buffered_writer::data_u8[4 *bufcapacity]

Definition at line 3912 of file pugixml.cc.

◆ encoding

xml_encoding xml_buffered_writer::encoding

Definition at line 3920 of file pugixml.cc.

Referenced by flush(), write_direct(), and xml_buffered_writer().

◆ [union]

union { ... } xml_buffered_writer::scratch

Referenced by flush().

◆ writer

xml_writer& xml_buffered_writer::writer

Definition at line 3918 of file pugixml.cc.

Referenced by flush(), write_direct(), and xml_buffered_writer().


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