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)
| ~xml_buffered_writer ()
void | flush ()
void | flush (const char_t *data, size_t size)
void | write (const char_t *data, size_t length)
void | write (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

## Private Member Functions

| xml_buffered_writer (const xml_buffered_writer &)
xml_buffered_writer & | operator= (const xml_buffered_writer &)

## Detailed Description

Definition at line 3022 of file pugixml.cpp.

## Member Enumeration Documentation

## anonymous enum

anonymous enum

Enumerator
bufcapacitybytes |
bufcapacity |

Definition at line 3174 of file pugixml.cpp.

{
bufcapacitybytes =
#ifdef PUGIXML_MEMORY_OUTPUT_STACK
PUGIXML_MEMORY_OUTPUT_STACK
#else
10240
#endif
,
bufcapacity = bufcapacitybytes / (sizeof(char_t) + 4)
};
xml_buffered_writer::bufcapacitybytes
@ bufcapacitybytes
Definition pugixml.cpp:3176
xml_buffered_writer::bufcapacity
@ bufcapacity
Definition pugixml.cpp:3183

## Constructor & Destructor Documentation

## xml_buffered_writer() [1/2]

xml_buffered_writer::xml_buffered_writer | ( | const xml_buffered_writer & |  | ) |

private

## xml_buffered_writer() [2/2]

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

inline

Definition at line 3028 of file pugixml.cpp.

: writer(writer_), bufsize(0), encoding(get_write_encoding(user_encoding))
{
PUGI__STATIC_ASSERT(bufcapacity >= 8);
}
xml_buffered_writer::writer
xml_writer & writer
Definition pugixml.cpp:3196
xml_buffered_writer::bufsize
size_t bufsize
Definition pugixml.cpp:3197
xml_buffered_writer::encoding
xml_encoding encoding
Definition pugixml.cpp:3198
PUGI__STATIC_ASSERT
#define PUGI__STATIC_ASSERT(cond)
Definition pugixml.cpp:95
get_write_encoding
PUGI__FN xml_encoding get_write_encoding(xml_encoding encoding)
Definition pugixml.cpp:2870

References bufcapacity, and PUGI__STATIC_ASSERT.

## ~xml_buffered_writer()

xml_buffered_writer::~xml_buffered_writer | ( |  | ) |

inline

Definition at line 3033 of file pugixml.cpp.

{
flush();
}
xml_buffered_writer::flush
void flush()
Definition pugixml.cpp:3038

References flush().

## Member Function Documentation

## flush() [1/2]

void xml_buffered_writer::flush | ( |  | ) |

inline

Definition at line 3038 of file pugixml.cpp.

{
flush(buffer, bufsize);
bufsize = 0;
}
xml_buffered_writer::buffer
char_t buffer[bufcapacity]
Definition pugixml.cpp:3186

References buffer, bufsize, and flush().

Referenced by flush(), write(), write(), write(), write(), write(), write(), write(), and ~xml_buffered_writer().

## flush() [2/2]

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

inline

Definition at line 3044 of file pugixml.cpp.

{
if (size == 0) return;
// fast path, just write data
if (encoding == get_write_native_encoding())
writer.write(data, size * sizeof(char_t));
else
{
// convert chunk
size_t result = convert_buffer_output(scratch.data_char, scratch.data_u8, scratch.data_u16, scratch.data_u32, data, size, encoding);
assert(result <= sizeof(scratch));
// write data
writer.write(scratch.data_u8, result);
}
}
xml_buffered_writer::scratch
union xml_buffered_writer::@6 scratch
get_write_native_encoding
PUGI__FN xml_encoding get_write_native_encoding()
Definition pugixml.cpp:2861
convert_buffer_output
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.cpp:2977

References convert_buffer_output(), encoding, get_write_native_encoding(), scratch, and writer.

## operator=()

xml_buffered_writer & xml_buffered_writer::operator= | ( | const xml_buffered_writer & |  | ) |

private

## write() [1/8]

void xml_buffered_writer::write | ( | char_t | d0 | ) |

inline

Definition at line 3108 of file pugixml.cpp.

{
if (bufsize + 1 > bufcapacity) flush();
buffer[bufsize + 0] = d0;
bufsize += 1;
}

References bufcapacity, buffer, bufsize, and flush().

## write() [2/8]

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

inline

Definition at line 3116 of file pugixml.cpp.

{
if (bufsize + 2 > bufcapacity) flush();
buffer[bufsize + 0] = d0;
buffer[bufsize + 1] = d1;
bufsize += 2;
}

References bufcapacity, buffer, bufsize, and flush().

## write() [3/8]

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

inline

Definition at line 3125 of file pugixml.cpp.

{
if (bufsize + 3 > bufcapacity) flush();
buffer[bufsize + 0] = d0;
buffer[bufsize + 1] = d1;
buffer[bufsize + 2] = d2;
bufsize += 3;
}

References bufcapacity, buffer, bufsize, and flush().

## write() [4/8]

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

inline

Definition at line 3135 of file pugixml.cpp.

{
if (bufsize + 4 > bufcapacity) flush();
buffer[bufsize + 0] = d0;
buffer[bufsize + 1] = d1;
buffer[bufsize + 2] = d2;
buffer[bufsize + 3] = d3;
bufsize += 4;
}

References bufcapacity, buffer, bufsize, and flush().

## write() [5/8]

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

inline

Definition at line 3146 of file pugixml.cpp.

{
if (bufsize + 5 > bufcapacity) flush();
buffer[bufsize + 0] = d0;
buffer[bufsize + 1] = d1;
buffer[bufsize + 2] = d2;
buffer[bufsize + 3] = d3;
buffer[bufsize + 4] = d4;
bufsize += 5;
}

References bufcapacity, buffer, bufsize, and flush().

## write() [6/8]

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 3158 of file pugixml.cpp.

{
if (bufsize + 6 > bufcapacity) flush();
buffer[bufsize + 0] = d0;
buffer[bufsize + 1] = d1;
buffer[bufsize + 2] = d2;
buffer[bufsize + 3] = d3;
buffer[bufsize + 4] = d4;
buffer[bufsize + 5] = d5;
bufsize += 6;
}

References bufcapacity, buffer, bufsize, and flush().

## write() [7/8]

void xml_buffered_writer::write | ( | const char_t * | data | ) |

inline

Definition at line 3103 of file pugixml.cpp.

{
write(data, strlength(data));
}
xml_buffered_writer::write
void write(const char_t *data, size_t length)
Definition pugixml.cpp:3062
strlength
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN size_t strlength(const char_t *s)
Definition pugixml.cpp:176

References strlength(), and write().

## write() [8/8]

void xml_buffered_writer::write | ( | const char_t * | data,
|  | size_t | length
| ) |  |

inline

Definition at line 3062 of file pugixml.cpp.

{
if (bufsize + length > bufcapacity)
{
// flush the remaining buffer contents
flush();
// handle large chunks
if (length > bufcapacity)
{
if (encoding == get_write_native_encoding())
{
// fast path, can just write data chunk
writer.write(data, length * sizeof(char_t));
return;
}
// need to convert in suitable chunks
while (length > bufcapacity)
{
// get chunk size by selecting such number of characters that are guaranteed to fit into scratch buffer
// and form a complete codepoint sequence (i.e. discard start of last codepoint if necessary)
size_t chunk_size = get_valid_length(data, bufcapacity);
// convert chunk and write
flush(data, chunk_size);
// iterate
data += chunk_size;
length -= chunk_size;
}
// small tail is copied below
bufsize = 0;
}
}
memcpy(buffer + bufsize, data, length * sizeof(char_t));
bufsize += length;
}
get_valid_length
PUGI__FN size_t get_valid_length(const char_t *data, size_t length)
Definition pugixml.cpp:2961

References bufcapacity, buffer, bufsize, encoding, flush(), get_valid_length(), get_write_native_encoding(), and writer.

Referenced by node_output(), node_output_attributes(), text_output(), text_output_cdata(), text_output_escaped(), and write().

## Member Data Documentation

## buffer

char_t xml_buffered_writer::buffer[bufcapacity]

Definition at line 3186 of file pugixml.cpp.

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

## bufsize

size_t xml_buffered_writer::bufsize

Definition at line 3197 of file pugixml.cpp.

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

## data_char

char_t xml_buffered_writer::data_char[bufcapacity]

Definition at line 3193 of file pugixml.cpp.

## data_u16

uint16_t xml_buffered_writer::data_u16[2 *bufcapacity]

Definition at line 3191 of file pugixml.cpp.

## data_u32

uint32_t xml_buffered_writer::data_u32[bufcapacity]

Definition at line 3192 of file pugixml.cpp.

## data_u8

uint8_t xml_buffered_writer::data_u8[4 *bufcapacity]

Definition at line 3190 of file pugixml.cpp.

## encoding

xml_encoding xml_buffered_writer::encoding

Definition at line 3198 of file pugixml.cpp.

Referenced by flush(), and write().

## [union]

union { ... } xml_buffered_writer::scratch

Referenced by flush().

## writer

xml_writer& xml_buffered_writer::writer

Definition at line 3196 of file pugixml.cpp.

Referenced by flush(), and write().

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

- pugixml.cpp