DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::OksXmlOutputStream Class Reference

#include <xml.hpp>

Public Member Functions

 OksXmlOutputStream (std::ostream &p)
std::ostream & get_stream () const
void put (char c)
void put (const char *s)
void put_raw (char c)
void put_raw (const char *s, long len)
template<class T>
void put_value (T value)
void put_quoted (const char *)
void put_start_tag (const char *, size_t len)
void put_end_tag ()
void put_last_tag (const char *, size_t len)
void put_attribute (const char *, size_t len, const char *)
void put_attribute (const char *, size_t len, uint32_t)
void put_attribute (const char *, size_t len, const OksData &)
void put_eol ()

Static Private Member Functions

static void __throw_write_failed ()

Private Attributes

std::ostream & f

Detailed Description

Definition at line 125 of file xml.hpp.

Constructor & Destructor Documentation

◆ OksXmlOutputStream()

dunedaq::oks::OksXmlOutputStream::OksXmlOutputStream ( std::ostream & p)
inline

Definition at line 129 of file xml.hpp.

130 : f(p)
131 {
132 ;
133 }

Member Function Documentation

◆ __throw_write_failed()

void dunedaq::oks::OksXmlOutputStream::__throw_write_failed ( )
staticprivate

Definition at line 120 of file xml.cpp.

121{
122 throw std::runtime_error("write to file failed");
123}

◆ get_stream()

std::ostream & dunedaq::oks::OksXmlOutputStream::get_stream ( ) const
inline

Definition at line 135 of file xml.hpp.

135{ return f; }

◆ put() [1/2]

void dunedaq::oks::OksXmlOutputStream::put ( char c)

Write char to xml output stream. Convert special symbols.

Exceptions
std::exceptionif failed

Definition at line 131 of file xml.cpp.

132{
133 if (c == '<')
135 else if (c == '>')
137 else if (c == '&')
139 else if (c == '\'')
141 else if (c == '\"')
143 else if (c == '\r')
145 else if (c == '\n')
147 else if (c == '\t')
149 else
150 put_raw(c);
151}
const char left_angle_bracket[]
Definition xml.cpp:30
const char new_line[]
Definition xml.cpp:34
const char tabulation[]
Definition xml.cpp:35
const char single_quote[]
Definition xml.cpp:36
const char ampersand[]
Definition xml.cpp:32
const char right_angle_bracket[]
Definition xml.cpp:31
const char carriage_return[]
Definition xml.cpp:33
const char double_quote[]
Definition xml.cpp:37

◆ put() [2/2]

void dunedaq::oks::OksXmlOutputStream::put ( const char * s)

Write string to xml output stream. Convert special symbols.

Exceptions
std::exceptionif failed

Definition at line 159 of file xml.cpp.

160{
161 while (*str)
162 put(*str++);
163}

◆ put_attribute() [1/3]

void dunedaq::oks::OksXmlOutputStream::put_attribute ( const char * name,
size_t len,
const char * value )

Definition at line 230 of file xml.cpp.

231{
232 put_raw(' ');
233 put_raw(name, len);
234 put_raw('=');
235 put_raw('\"');
236 put(value);
237 put_raw('\"');
238}

◆ put_attribute() [2/3]

void dunedaq::oks::OksXmlOutputStream::put_attribute ( const char * name,
size_t len,
const OksData & value )

Definition at line 259 of file xml.cpp.

260{
261 put_raw(' ');
262 put_raw(name, len);
263 put_raw('=');
264 put_raw('\"');
265 value.WriteTo(*this);
266 put_raw('\"');
267}

◆ put_attribute() [3/3]

void dunedaq::oks::OksXmlOutputStream::put_attribute ( const char * name,
size_t len,
uint32_t value )

Definition at line 241 of file xml.cpp.

242{
243 put_raw(' ');
244 put_raw(name, len);
245 put_raw('=');
246 put_raw('\"');
247 if (value == 0) {
248 put_raw('0');
249 } else {
250 char buf[12];
251 char* ptr = buf;
252 boost::spirit::karma::generate(ptr, boost::spirit::uint_, (unsigned int)value);
253 put_raw(buf, ptr - buf);
254 }
255 put_raw('\"');
256}

◆ put_end_tag()

void dunedaq::oks::OksXmlOutputStream::put_end_tag ( )

Definition at line 196 of file xml.cpp.

197{
198 static const char __end_tag[] = "/>\n";
199 put_raw(__end_tag, sizeof(__end_tag) - 1);
200}

◆ put_eol()

void dunedaq::oks::OksXmlOutputStream::put_eol ( )

Definition at line 203 of file xml.cpp.

204{
205 static const char __eol_tag[] = ">\n";
206 put_raw(__eol_tag, sizeof(__eol_tag) - 1);
207}

◆ put_last_tag()

void dunedaq::oks::OksXmlOutputStream::put_last_tag ( const char * name,
size_t len )

Definition at line 215 of file xml.cpp.

216{
217 put_raw('<');
218 put_raw('/');
219 put_raw(name, len);
220 put_raw('>');
221 put_raw('\n');
222}

◆ put_quoted()

void dunedaq::oks::OksXmlOutputStream::put_quoted ( const char * str)

Definition at line 171 of file xml.cpp.

172{
173 put_raw('\"');
174 put(str);
175 put_raw('\"');
176}

◆ put_raw() [1/2]

void dunedaq::oks::OksXmlOutputStream::put_raw ( char c)
inline

Write char to xml output stream without check for special symbols.

Exceptions
std::exceptionif failed

Definition at line 153 of file xml.hpp.

154 {
155 if (__builtin_expect((f.rdbuf()->sputc(c) != c), 0))
157 }
static void __throw_write_failed()
Definition xml.cpp:120

◆ put_raw() [2/2]

void dunedaq::oks::OksXmlOutputStream::put_raw ( const char * s,
long len )
inline

Definition at line 159 of file xml.hpp.

160 {
161 if (__builtin_expect((f.rdbuf()->sputn(s, len) != len), 0))
163 }

◆ put_start_tag()

void dunedaq::oks::OksXmlOutputStream::put_start_tag ( const char * name,
size_t len )

Definition at line 184 of file xml.cpp.

185{
186 put_raw('<');
187 put_raw(name, len);
188}

◆ put_value()

template<class T>
void dunedaq::oks::OksXmlOutputStream::put_value ( T value)
inline

Definition at line 166 of file xml.hpp.

167 {
168 f << value;
169 }

Member Data Documentation

◆ f

std::ostream& dunedaq::oks::OksXmlOutputStream::f
private

Definition at line 188 of file xml.hpp.


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