Version: 9.15.0
xmlParserBase Class Reference

base class for xml parsers, runtime independant More...

#include <xmlParserBase.hxx>

Inheritance diagram for xmlParserBase:
Collaboration diagram for xmlParserBase:

Public Member Functions

void setAttribute (std::string key, std::string value)
 
std::string getAttribute (std::string key)
 
virtual void addData (std::string value)
 
virtual void init (const xmlChar **p, xmlParserBase *father=0)
 

Static Public Member Functions

static void XMLCALL start_document (void *userData)
 
static void XMLCALL end_document (void *userData)
 
static void XMLCALL start_element (void *userData, const xmlChar *name, const xmlChar **p)
 
static void XMLCALL end_element (void *userData, const xmlChar *name)
 
static void XMLCALL characters (void *userData, const xmlChar *ch, int len)
 
static void XMLCALL comment (void *userData, const xmlChar *value)
 
static void XMLCALL warning (void *userData, const char *fmt,...)
 
static void XMLCALL error (void *userData, const char *fmt,...)
 
static void XMLCALL fatal_error (void *userData, const char *fmt,...)
 
static void XMLCALL cdata_block (void *userData, const xmlChar *value, int len)
 
static void cleanGarbage ()
 
static int getGarbageSize ()
 
static void XML_SetUserData (_xmlParserCtxt *ctxt, xmlParserBase *parser)
 

Public Attributes

std::map< std::string, int > counts
 

Static Public Attributes

static _xmlParserCtxt * _xmlParser
 
static std::stack< xmlParserBase * > _stackParser
 

Protected Member Functions

void getAttributes (const xmlChar **p)
 
virtual void onStart (const XML_Char *elem, const xmlChar **p)
 
virtual void onEnd (const XML_Char *name)
 
virtual void charData (std::string data)
 
virtual void incrCount (const XML_Char *elem)
 
virtual void end ()
 
virtual void stopParse (std::string what)
 

Protected Attributes

std::map< std::string, std::string > _mapAttrib
 
std::string _data
 
xmlParserBase_father
 

Static Protected Attributes

static std::list< xmlParserBase * > _garbage
 

Detailed Description

base class for xml parsers, runtime independant

Definition at line 51 of file xmlParserBase.hxx.

Member Function Documentation

◆ addData()

void xmlParserBase::addData ( std::string  value)
virtual

Add data on the data attribute of the parser object dedicated to an xml tag

Reimplemented in outputParser, YACS::ENGINE::dataParser, YACS::ENGINE::arrayParser, YACS::ENGINE::valueParser, and YACS::ENGINE::portParser.

Definition at line 267 of file xmlParserBase.cxx.

268 {
269  // DEBTRACE("xmlParserBase::addData()");
270  _data += value;
271 }
std::string _data

◆ cdata_block()

void XMLCALL xmlParserBase::cdata_block ( void *  userData,
const xmlChar *  value,
int  len 
)
static

callback called for CDATA inside tags:

<tag>![CDATA[content]]></tag> 

used only by libxml2

Definition at line 204 of file xmlParserBase.cxx.

207 {
208  //DEBTRACE("xmlParserBase::cdata_block");
209  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
210  string data((char*)value,len);
211  currentParser->charData(data);
212 }
base class for xml parsers, runtime independant
virtual void charData(std::string data)

References charData().

Referenced by xmlReader::parse().

◆ characters()

void XMLCALL xmlParserBase::characters ( void *  userData,
const xmlChar *  ch,
int  len 
)
static

callback called for significant characters inside tags:

<tag>content</tag> 

or outside tags, like space or new line; get also the CDATA tags:

<tag>![CDATA[content]]></tag> 

Definition at line 108 of file xmlParserBase.cxx.

111 {
112  //DEBTRACE("xmlParserBase::characters " << len);
113  xmlParserBase *currentParser = (xmlParserBase *) (userData);
114  string data((char*)ch,len);
115  currentParser->charData(data);
116 }

References charData().

Referenced by xmlReader::parse().

◆ charData()

void xmlParserBase::charData ( std::string  data)
protectedvirtual

to be specialized following the kind of xml tag

Reimplemented in YACS::ENGINE::sampleParser, YACS::ENGINE::loopPortParser, YACS::ENGINE::simpleTypeParser, YACS::ENGINE::attrParser, and YACS::ENGINE::stateParser.

Definition at line 299 of file xmlParserBase.cxx.

300 {
301 }

Referenced by cdata_block(), and characters().

◆ cleanGarbage()

void xmlParserBase::cleanGarbage ( )
static

Definition at line 214 of file xmlParserBase.cxx.

215 {
216  while (!_garbage.empty())
217  {
218  delete (_garbage.front());
219  _garbage.pop_front();
220  }
221 }
static std::list< xmlParserBase * > _garbage

Referenced by xmlReader::parse().

◆ comment()

void XMLCALL xmlParserBase::comment ( void *  userData,
const xmlChar *  value 
)
static

callback usable only with libxml2

Definition at line 122 of file xmlParserBase.cxx.

124 {
125  //DEBTRACE("xmlParserBase::comment");
126  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
127 }

Referenced by xmlReader::parse().

◆ end()

void xmlParserBase::end ( )
protectedvirtual

to be specialized for each kind of xml tag

Definition at line 318 of file xmlParserBase.cxx.

319 {
320 }

Referenced by end_element().

◆ end_document()

void XMLCALL xmlParserBase::end_document ( void *  userData)
static

callback usable only with libxml2

Definition at line 63 of file xmlParserBase.cxx.

64 {
65  //DEBTRACE("xmlParserBase::end_document");
66  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
67 }

Referenced by xmlReader::parse().

◆ end_element()

void XMLCALL xmlParserBase::end_element ( void *  userData,
const xmlChar *  name 
)
static

callback called on end of an xml element:

</name> 

Definition at line 88 of file xmlParserBase.cxx.

90 {
91  //DEBTRACE("xmlParserBase::end_element");
92  const XML_Char *aName = tochar(name);
93  xmlParserBase *childParser = static_cast<xmlParserBase *> (userData);
94  _garbage.push_back(_stackParser.top());
95  DEBTRACE("xmlParserBase::end_element " << _garbage.size());
96  _stackParser.pop();
98  childParser->onEnd(aName);
99  childParser->end();
100  }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
static void XML_SetUserData(_xmlParserCtxt *ctxt, xmlParserBase *parser)
virtual void end()
static _xmlParserCtxt * _xmlParser
virtual void onEnd(const XML_Char *name)
static std::stack< xmlParserBase * > _stackParser
XML_Char * tochar(const xmlChar *c)
#define XML_Char

References DEBTRACE, end(), onEnd(), tochar(), and XML_Char.

Referenced by xmlReader::parse().

◆ error()

void XMLCALL xmlParserBase::error ( void *  userData,
const char *  fmt,
  ... 
)
static

callback usable only with libxml2

Definition at line 156 of file xmlParserBase.cxx.

158 {
159  DEBTRACE("xmlParserBase::error");
160  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
161  va_list args;
162  va_start(args, fmt);
163  string format = "%s";
164  if (format == fmt)
165  {
166  char* parv;
167  parv = va_arg(args, char*);
168  cerr << parv ;
169  xmlParserBase *currentParser = (xmlParserBase *) userData;
170  //cerr << currentParser->element << endl;
171  }
172  else cerr << __FILE__ << " [" << __LINE__ << "] : "
173  << "error format not taken into account: " << fmt << endl;
174  va_end(args);
175 }

References driver_internal::args, and DEBTRACE.

Referenced by xmlReader::parse().

◆ fatal_error()

void XMLCALL xmlParserBase::fatal_error ( void *  userData,
const char *  fmt,
  ... 
)
static

callback usable only with libxml2

Definition at line 181 of file xmlParserBase.cxx.

183 {
184  DEBTRACE("xmlParserBase::fatal_error");
185  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
186  va_list args;
187  va_start(args, fmt);
188  string format = "%s";
189  if (format == fmt)
190  {
191  char* parv;
192  parv = va_arg(args, char*);
193  cerr << parv ;
194  }
195  else cerr << __FILE__ << " [" << __LINE__ << "] : "
196  << "error format not taken into account: " << fmt << endl;
197  va_end(args);
198 }

References driver_internal::args, and DEBTRACE.

Referenced by xmlReader::parse().

◆ getAttribute()

std::string xmlParserBase::getAttribute ( std::string  key)

Gets an attribute value given a string key. If the key does not exist, throws an Exception.

Definition at line 254 of file xmlParserBase.cxx.

255 {
256  if (_mapAttrib.find(key) == _mapAttrib.end())
257  {
258  string what = "Attribute does not exist: " + key;
259  throw Exception(what);
260  }
261  return _mapAttrib[key];
262 }
std::map< std::string, std::string > _mapAttrib

◆ getAttributes()

void xmlParserBase::getAttributes ( const xmlChar **  p)
protected

Stores the tag attributes on a map. The map is an attribute of the parser object dedicated to the current xml tag

Definition at line 227 of file xmlParserBase.cxx.

228 {
229  if (p) while (*p)
230  {
231  string attributeName = (char*)*p;
232  //cerr << "attribute name " << attributeName << endl;
233  p++;
234  string attributeValue = (char*)*p;
235  //cerr << "attribute value " << attributeValue << endl;
236  p++;
237  _mapAttrib[attributeName] = attributeValue;
238  }
239 }
Proc * p
Definition: driver.cxx:216

References p.

Referenced by YACS::ENGINE::sampleParser::init().

◆ getGarbageSize()

static int xmlParserBase::getGarbageSize ( )
inlinestatic

Definition at line 78 of file xmlParserBase.hxx.

78 {return _garbage.size(); };

References _garbage.

Referenced by xmlReader::parse().

◆ incrCount()

void xmlParserBase::incrCount ( const XML_Char elem)
protectedvirtual

May be specialized for each kind of xml tag. Counts the number of tag occurences of a given type inside a context.

Definition at line 307 of file xmlParserBase.cxx.

308 {
309  if(counts.find(elem)==counts.end())
310  counts[elem]=1;
311  else
312  counts[elem]=counts[elem]+1;
313 }
std::map< std::string, int > counts

Referenced by start_element().

◆ init()

void xmlParserBase::init ( const xmlChar **  p,
xmlParserBase father = 0 
)
virtual

all parsers must know their father parser (father tag), in order to set values or attributes in father.

Reimplemented in YACS::ENGINE::sampleParser, YACS::ENGINE::loopPortParser, YACS::ENGINE::simpleTypeParser, YACS::ENGINE::dataParser, YACS::ENGINE::arrayParser, YACS::ENGINE::valueParser, YACS::ENGINE::portParser, YACS::ENGINE::attrParser, YACS::ENGINE::nodeParser, YACS::ENGINE::graphParser, YACS::ENGINE::stateParser, and outputParser.

Definition at line 277 of file xmlParserBase.cxx.

278 {
279  _father = father;
280 }
xmlParserBase * _father

Referenced by xmlReader::parse().

◆ onEnd()

void xmlParserBase::onEnd ( const XML_Char name)
protectedvirtual

to be specialized for each kind of xml tag

Reimplemented in outputParser.

Definition at line 292 of file xmlParserBase.cxx.

293 {
294 }

Referenced by end_element().

◆ onStart()

void xmlParserBase::onStart ( const XML_Char elem,
const xmlChar **  p 
)
protectedvirtual

to be specialized for each kind of xml tag

Reimplemented in outputParser.

Definition at line 285 of file xmlParserBase.cxx.

286 {
287 }

Referenced by start_element().

◆ setAttribute()

void xmlParserBase::setAttribute ( std::string  key,
std::string  value 
)

Stores an attribute (key, value) on the map attribute. used for attributes defined at another tag level (child tags).

Definition at line 245 of file xmlParserBase.cxx.

246 {
247  _mapAttrib[key] = value;
248 }

◆ start_document()

void XMLCALL xmlParserBase::start_document ( void *  userData)
static

callback usable only with libxml2

Definition at line 54 of file xmlParserBase.cxx.

55 {
56  //DEBTRACE("xmlParserBase::start_document");
57  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
58 }

Referenced by xmlReader::parse().

◆ start_element()

void XMLCALL xmlParserBase::start_element ( void *  userData,
const xmlChar *  name,
const xmlChar **  p 
)
static

callback called on start of an xml element:

<name> 

Definition at line 72 of file xmlParserBase.cxx.

75 {
76  //DEBTRACE("xmlParserBase::start_element " << name);
77  cleanGarbage();
78  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
79  const XML_Char *aName = tochar(name);
80  currentParser->incrCount(aName);
81  currentParser->onStart(aName, p);
82 }
virtual void onStart(const XML_Char *elem, const xmlChar **p)
static void cleanGarbage()
virtual void incrCount(const XML_Char *elem)

References incrCount(), onStart(), p, tochar(), and XML_Char.

Referenced by xmlReader::parse().

◆ stopParse()

void xmlParserBase::stopParse ( std::string  what)
protectedvirtual

Throws an exception.

Definition at line 325 of file xmlParserBase.cxx.

326 {
327  xmlStopParser(_xmlParser);
328 }

Referenced by YACS::ENGINE::sampleParser::onEnd(), and YACS::ENGINE::sampleParser::onStart().

◆ warning()

void XMLCALL xmlParserBase::warning ( void *  userData,
const char *  fmt,
  ... 
)
static

callback usable only with libxml2

Definition at line 133 of file xmlParserBase.cxx.

135 {
136  DEBTRACE("xmlParserBase::warning");
137  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
138  va_list args;
139  va_start(args, fmt);
140  string format = "%s";
141  if (format == fmt)
142  {
143  char* parv;
144  parv = va_arg(args, char*);
145  cerr << parv ;
146  }
147  else cerr << __FILE__ << " [" << __LINE__ << "] : "
148  << "error format not taken into account: " << fmt << endl;
149  va_end(args);
150 }

References driver_internal::args, and DEBTRACE.

Referenced by xmlReader::parse().

◆ XML_SetUserData()

void xmlParserBase::XML_SetUserData ( _xmlParserCtxt *  ctxt,
xmlParserBase parser 
)
static

Definition at line 37 of file xmlParserBase.cxx.

39 {
40  ctxt->userData = parser;
41 }

Referenced by YACS::ENGINE::sampleParser::onStart().

Member Data Documentation

◆ _data

std::string xmlParserBase::_data
protected

◆ _father

xmlParserBase* xmlParserBase::_father
protected

Definition at line 107 of file xmlParserBase.hxx.

Referenced by YACS::ENGINE::sampleParser::init().

◆ _garbage

std::list< xmlParserBase * > xmlParserBase::_garbage
staticprotected

Definition at line 105 of file xmlParserBase.hxx.

Referenced by getGarbageSize().

◆ _mapAttrib

std::map<std::string, std::string> xmlParserBase::_mapAttrib
protected

Definition at line 104 of file xmlParserBase.hxx.

Referenced by YACS::ENGINE::sampleParser::onEnd().

◆ _stackParser

std::stack< xmlParserBase * > xmlParserBase::_stackParser
static

Definition at line 91 of file xmlParserBase.hxx.

Referenced by YACS::ENGINE::sampleParser::onStart(), and xmlReader::parse().

◆ _xmlParser

_xmlParserCtxt * xmlParserBase::_xmlParser
static

Definition at line 87 of file xmlParserBase.hxx.

Referenced by YACS::ENGINE::sampleParser::onStart(), and xmlReader::parse().

◆ counts

std::map< std::string, int > xmlParserBase::counts

Definition at line 85 of file xmlParserBase.hxx.


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