|
| loader (const loader &a_from) |
|
loader & | operator= (const loader &a_from) |
|
void | clear () |
|
bool | parse_buffer (size_t aSize, const char *aBuffer, XML_StartElementHandler a_start, XML_EndElementHandler a_end, void *a_tag) |
|
bool | parse_file (const std::string &a_file, XML_StartElementHandler a_start, XML_EndElementHandler a_end, void *a_tag, bool a_compressed) |
|
|
static void | character_data_handler (void *aUserData, const XML_Char *a_string, int aLength) |
|
static void | start_element (void *aUserData, const XML_Char *a_name, const XML_Char **a_atbs) |
|
static void | end_element (void *aUserData, const XML_Char *a_name) |
|
Definition at line 42 of file loader.
◆ loader() [1/2]
tools::xml::loader::loader |
( |
tools::xml::factory & |
a_factory, |
|
|
std::ostream & |
a_out, |
|
|
bool |
a_verbose = false |
|
) |
| |
|
inline |
Definition at line 47 of file loader.
62 tools::mem::increment(s_class().c_str());
◆ ~loader()
virtual tools::xml::loader::~loader |
( |
| ) |
|
|
inlinevirtual |
Definition at line 66 of file loader.
70 tools::mem::decrement(s_class().c_str());
◆ loader() [2/2]
tools::xml::loader::loader |
( |
const loader & |
a_from | ) |
|
|
inlineprotected |
Definition at line 75 of file loader.
89 tools::mem::increment(s_class().c_str());
◆ add_tag()
void tools::xml::loader::add_tag |
( |
const std::string & |
a_tag | ) |
|
|
inline |
◆ character_data_handler()
static void tools::xml::loader::character_data_handler |
( |
void * |
aUserData, |
|
|
const XML_Char * |
a_string, |
|
|
int |
aLength |
|
) |
| |
|
inlinestaticprotected |
Definition at line 355 of file loader.
360 char* p = (
char*)a_string;
361 for (
int i = 0; i < aLength; i++, p++) {
362 if(This->m_take_cntrl || (!iscntrl(*p))) {
◆ clear()
void tools::xml::loader::clear |
( |
| ) |
|
|
inlineprotected |
◆ empty()
void tools::xml::loader::empty |
( |
| ) |
|
|
inline |
◆ end_element()
static void tools::xml::loader::end_element |
( |
void * |
aUserData, |
|
|
const XML_Char * |
a_name |
|
) |
| |
|
inlinestaticprotected |
Definition at line 490 of file loader.
492 if(This->m_abort)
return;
494 if(This->m_current) {
503 bool cont = This->visit_end_element(*tr,keep);
514 This->m_current = parent;
518 if(This->m_top==tr) This->m_top = 0;
535 This->m_current = parent;
538 if(!cont) This->m_abort =
true;
540 }
else if(delta==1) {
543 tr->
add_element(std::string(a_name),This->m_atbs,This->m_value);
548 This->m_out <<
"end_element :"
549 <<
" problem for element " <<
tools::sout(std::string(a_name))
550 <<
" : delta depth of " << delta
552 This->m_abort =
true;
◆ errors()
unsigned int tools::xml::loader::errors |
( |
| ) |
const |
|
inline |
◆ is_tag()
bool tools::xml::loader::is_tag |
( |
const std::string & |
a_string | ) |
const |
|
inline |
Definition at line 171 of file loader.
172 size_t number =
m_tags.size();
173 for(
size_t index=0;index<number;index++) {
174 if(a_string==
m_tags[index])
return true;
◆ load_buffer()
bool tools::xml::loader::load_buffer |
( |
size_t |
aSize, |
|
|
const char * |
aBuffer |
|
) |
| |
|
inline |
◆ load_file()
bool tools::xml::loader::load_file |
( |
const std::string & |
a_file, |
|
|
bool |
a_compressed |
|
) |
| |
|
inline |
Definition at line 128 of file loader.
133 this,a_compressed)) {
◆ load_string()
bool tools::xml::loader::load_string |
( |
const std::string & |
a_string | ) |
|
|
inline |
◆ operator=()
loader& tools::xml::loader::operator= |
( |
const loader & |
a_from | ) |
|
|
inlineprotected |
Definition at line 92 of file loader.
93 if(&a_from==
this)
return *
this;
◆ out()
std::ostream& tools::xml::loader::out |
( |
| ) |
const |
|
inline |
◆ parse_buffer()
bool tools::xml::loader::parse_buffer |
( |
size_t |
aSize, |
|
|
const char * |
aBuffer, |
|
|
XML_StartElementHandler |
a_start, |
|
|
XML_EndElementHandler |
a_end, |
|
|
void * |
a_tag |
|
) |
| |
|
inlineprotected |
Definition at line 187 of file loader.
191 if(!aSize)
return true;
196 XML_Memory_Handling_Suite mem;
197 mem.malloc_fcn = xml_malloc;
198 mem.realloc_fcn = xml_realloc;
199 mem.free_fcn = xml_free;
200 XML_Parser _parser = XML_ParserCreate_MM(NULL,&mem,NULL);
202 XML_Parser _parser = XML_ParserCreate(NULL);
205 XML_SetUserData(_parser,a_tag);
206 XML_SetElementHandler(_parser,a_start,a_end);
209 char* buf = (
char*)aBuffer;
213 size_t len = tools::mn<size_t>(l,BUFSIZ);
214 done = len < BUFSIZ ? 1 : 0;
215 if(XML_Parse(_parser, buf, (
int)len, done)==XML_STATUS_ERROR) {
216 m_out <<
"parse_buffer :"
217 <<
" " << XML_ErrorString(XML_GetErrorCode(_parser))
218 <<
" at line " << (int)XML_GetCurrentLineNumber(_parser)
219 <<
" at byte index " << (int)XML_GetCurrentByteIndex(_parser)
221 {XML_Index pos = XML_GetCurrentByteIndex(_parser);
222 XML_Index pmn = tools::mx<XML_Index>(pos-10,0);
223 XML_Index pmx = tools::mn<XML_Index>(pos+10,XML_Index(aSize)-1);
225 {
for(XML_Index p=pmn;p<=pmx;p++) {c[0] = *(aBuffer+p);
m_out << c;}
227 {
for(XML_Index p=pmn;p<pos;p++)
m_out <<
" ";
228 m_out <<
"^" << std::endl;}}
229 XML_ParserFree(_parser);
233 XML_ParserFree(_parser);
239 XML_ParserFree(_parser);
◆ parse_file()
bool tools::xml::loader::parse_file |
( |
const std::string & |
a_file, |
|
|
XML_StartElementHandler |
a_start, |
|
|
XML_EndElementHandler |
a_end, |
|
|
void * |
a_tag, |
|
|
bool |
a_compressed |
|
) |
| |
|
inlineprotected |
Definition at line 243 of file loader.
247 m_out <<
"parse_file :"
248 <<
" parse file " <<
tools::sout(a_file) <<
"..." << std::endl;
252 bool use_zlib =
false;
255 m_out <<
"parse_file :"
256 <<
" uncompress requested for file "
265 m_out <<
"parse_file :"
266 <<
" tools::file::is_gzip() failed for " << a_file <<
"."
270 if(compressed) use_zlib =
true;
274 bool delete_freader =
false;
277 m_out <<
"parse_file :"
278 <<
" no compressed reader given."
285 delete_freader =
true;
287 if(!freader->
open(a_file)) {
288 m_out <<
"parse_file :"
289 <<
" can't open file " << a_file << std::endl;
290 if(delete_freader)
delete freader;
298 XML_Memory_Handling_Suite mem;
299 mem.malloc_fcn = xml_malloc;
300 mem.realloc_fcn = xml_realloc;
301 mem.free_fcn = xml_free;
302 XML_Parser _parser = XML_ParserCreate_MM(NULL,&mem,NULL);
304 XML_Parser _parser = XML_ParserCreate(NULL);
307 XML_SetUserData(_parser,a_tag);
308 XML_SetElementHandler(_parser,a_start,a_end);
319 if(!freader->
read(buf,
sizeof(buf),len)) {
320 XML_ParserFree(_parser);
322 if(delete_freader)
delete freader;
325 done = len <
sizeof(buf) ? 1 : 0;
326 if(XML_Parse(_parser, buf, (
int)len, done)==XML_STATUS_ERROR) {
327 m_out <<
"parse_file :"
329 <<
" " << XML_ErrorString(XML_GetErrorCode(_parser))
330 <<
" at line " << (int)XML_GetCurrentLineNumber(_parser)
332 XML_ParserFree(_parser);
334 if(delete_freader)
delete freader;
338 XML_ParserFree(_parser);
340 if(delete_freader)
delete freader;
344 XML_ParserFree(_parser);
347 m_out <<
"parse_file :"
348 <<
" parse file " <<
tools::sout(a_file) <<
" done." << std::endl;
350 if(delete_freader)
delete freader;
◆ set_compressed_reader()
◆ set_tags()
void tools::xml::loader::set_tags |
( |
const std::vector< std::string > & |
a_tags | ) |
|
|
inline |
◆ set_take_cntrl_chars()
void tools::xml::loader::set_take_cntrl_chars |
( |
bool |
a_value | ) |
|
|
inline |
◆ start_element()
static void tools::xml::loader::start_element |
( |
void * |
aUserData, |
|
|
const XML_Char * |
a_name, |
|
|
const XML_Char ** |
a_atbs |
|
) |
| |
|
inlinestaticprotected |
Definition at line 373 of file loader.
375 if(This->m_abort)
return;
380 std::string name = a_name;
381 if(This->is_tag(name)) {
383 if(!This->m_current) {
384 if(This->m_depth==1) {
387 This->m_out <<
"start_element :"
388 <<
" no tag with a depth of " << This->m_depth
390 This->m_abort =
true;
394 int delta = This->m_current->depth() - This->m_depth;
396 This->m_out <<
"start_element :"
398 <<
" tag with a delta depth of " << delta
400 This->m_abort =
true;
405 std::vector<tools::xml::tree::atb> atbs;
406 {
const XML_Char** a_atts = a_atbs;
407 while((*a_atts)&&(*(a_atts+1))) {
415 This->m_out <<
"start_element :"
416 <<
" can't create a tree for tag " <<
tools::sout(name)
418 This->m_abort =
true;
436 This->m_current = _tree;
439 if(!This->m_top) This->m_top = _tree;
443 if(!This->m_current) {
446 This->m_out <<
"start_element :"
448 <<
" non-tag without some parent tag."
450 This->m_abort =
true;
455 int delta = This->m_depth - This->m_current->depth();
458 This->m_out <<
"start_element :"
460 <<
" grand child of a tag."
462 This->m_abort =
true;
465 }
else if(delta==1) {
467 This->m_atbs.clear();
468 {
const XML_Char** a_atts = a_atbs;
469 while((*a_atts)&&(*(a_atts+1))) {
476 This->m_out <<
"start_element :"
478 <<
" non-tag with a delta depth of " << delta
480 This->m_abort =
true;
◆ top_item() [1/2]
◆ top_item() [2/2]
◆ visit_end_element()
virtual bool tools::xml::loader::visit_end_element |
( |
tools::xml::tree & |
, |
|
|
bool & |
a_keep |
|
) |
| |
|
inlinevirtual |
◆ m_abort
bool tools::xml::loader::m_abort |
|
protected |
◆ m_atbs
std::vector< std::pair<std::string,std::string> > tools::xml::loader::m_atbs |
|
protected |
◆ m_compressed_reader
◆ m_current
◆ m_depth
unsigned int tools::xml::loader::m_depth |
|
protected |
◆ m_errors
unsigned int tools::xml::loader::m_errors |
|
protected |
◆ m_factory
◆ m_out
std::ostream& tools::xml::loader::m_out |
|
protected |
◆ m_tags
std::vector<std::string> tools::xml::loader::m_tags |
|
protected |
◆ m_take_cntrl
bool tools::xml::loader::m_take_cntrl |
|
protected |
◆ m_top
◆ m_value
std::string tools::xml::loader::m_value |
|
protected |
◆ m_verbose
bool tools::xml::loader::m_verbose |
|
protected |
The documentation for this class was generated from the following file:
- /Users/barrand/private/dev/softinex/g4tools/g4tools/tools/xml/loader