CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
SimpleSAXParser Class Reference

#include <SimpleSAXParser.h>

Inheritance diagram for SimpleSAXParser:
FWXMLConfigParser

Classes

struct  Attribute
 
class  ParserError
 

Public Types

typedef std::vector< AttributeAttributes
 
enum  PARSER_STATES {
  IN_DOCUMENT, IN_BEGIN_TAG, IN_DONE, IN_BEGIN_ELEMENT,
  IN_ELEMENT_WHITESPACE, IN_END_ELEMENT, IN_ATTRIBUTE_KEY, IN_END_TAG,
  IN_DATA, IN_BEGIN_ATTRIBUTE_VALUE, IN_STRING, IN_END_ATTRIBUTE_VALUE,
  IN_STRING_ENTITY, IN_DATA_ENTITY
}
 

Public Member Functions

virtual void data (const std::string &)
 
virtual void endElement (const std::string &)
 
void parse (void)
 
 SimpleSAXParser (std::istream &f)
 
virtual void startElement (const std::string &, Attributes &)
 
virtual ~SimpleSAXParser ()
 

Private Member Functions

std::string getToken (const char *delim)
 
std::string getToken (const char delim)
 
int nextChar (void)
 
const SimpleSAXParseroperator= (const SimpleSAXParser &)
 
std::string parseEntity (const std::string &entity)
 
 SimpleSAXParser (const SimpleSAXParser &)
 
bool skipChar (int c)
 

Private Attributes

Attributes m_attributes
 
char * m_buffer
 
size_t m_bufferSize
 
std::vector< std::string > m_elementTags
 
std::istream & m_in
 
int m_nextChar
 

Detailed Description

A simple SAX parser which is able to parse the configuration.

State machine for the parser can be drawn by cut and pasting the following to graphviz:

digraph { IN_DOCUMENT->IN_BEGIN_TAG [label="nextChar == '<'"]; IN_DOCUMENT->IN_DATA [label="nextChar != '<'"];

IN_BEGIN_TAG->IN_BEGIN_ELEMENT [label="nextChar >= 'a' && nextChar < 'Z'"]; IN_BEGIN_TAG->IN_END_ELEMENT [label= "nextChar == '/'"];

IN_BEGIN_ELEMENT->IN_END_ELEMENT [label="nextChar == '/'"]; IN_BEGIN_ELEMENT->IN_ELEMENT_WHITESPACE [label="nextChar == ' '"]; IN_BEGIN_ELEMENT->IN_END_TAG [label="nextChar == '>'"];

IN_ELEMENT_WHITESPACE->IN_ELEMENT_WHITESPACE [ label = "nextChar == \"\ \t\n""] IN_ELEMENT_WHITESPACE->IN_ATTRIBUTE_KEY [ label = "nextChar >= 'a' && nextChar < 'Z'"] IN_ELEMENT_WHITESPACE->IN_END_ELEMENT [label="nextChar == '/'"]

IN_END_ELEMENT->IN_END_TAG [label = "nextChar == '>'"];

IN_END_TAG->IN_BEGIN_TAG [label="nextChar == '<'"]; IN_END_TAG->IN_DATA [label="nextChar != '<'"]

IN_DATA->IN_BEGIN_TAG [label="nextChar == '<'"]; IN_DATA->IN_DATA_ENTITY [label="nextChar == '&'"]; IN_DATA->IN_DONE [label = "nextChar == EOF"];

IN_DATA_ENTITY->IN_DATA [label="nextChar == ';'"];

IN_ATTRIBUTE_KEY->IN_BEGIN_ATTRIBUTE_VALUE [label = "nextChar == '='"]

IN_BEGIN_ATTRIBUTE_VALUE->IN_STRING [label = "nextChar == '\"' || nextChar == '\'' "]

IN_STRING->IN_END_ATTRIBUTE_VALUE [label = "nextChar == quote"] IN_STRING->IN_STRING_ENTITY [label = "nextChar == '&'"]

IN_END_ATTRIBUTE_VALUE->IN_ELEMENT_WHITESPACE [label = "nextChar == ' '"] IN_END_ATTRIBUTE_VALUE->IN_END_ELEMENT [label = "nextChar == '/'"] IN_END_ATTRIBUTE_VALUE->IN_END_TAG [label = "nextChar == '>'"]

IN_STRING_ENTITY->IN_STRING [label = "nextChar == ';'"] }

Definition at line 71 of file SimpleSAXParser.h.

Member Typedef Documentation

typedef std::vector<Attribute> SimpleSAXParser::Attributes

Definition at line 93 of file SimpleSAXParser.h.

Member Enumeration Documentation

Enumerator
IN_DOCUMENT 
IN_BEGIN_TAG 
IN_DONE 
IN_BEGIN_ELEMENT 
IN_ELEMENT_WHITESPACE 
IN_END_ELEMENT 
IN_ATTRIBUTE_KEY 
IN_END_TAG 
IN_DATA 
IN_BEGIN_ATTRIBUTE_VALUE 
IN_STRING 
IN_END_ATTRIBUTE_VALUE 
IN_STRING_ENTITY 
IN_DATA_ENTITY 

Definition at line 106 of file SimpleSAXParser.h.

Constructor & Destructor Documentation

SimpleSAXParser::SimpleSAXParser ( std::istream &  f)
inline

Definition at line 123 of file SimpleSAXParser.h.

124  : m_in(f),
125  m_bufferSize(1024),
126  m_buffer(new char[m_bufferSize]),
127  m_nextChar(m_in.get())
128  {}
std::istream & m_in
double f[11][100]
SimpleSAXParser::~SimpleSAXParser ( )
virtual

Definition at line 223 of file SimpleSAXParser.cc.

SimpleSAXParser::SimpleSAXParser ( const SimpleSAXParser )
private

Member Function Documentation

virtual void SimpleSAXParser::data ( const std::string &  )
inlinevirtual

Reimplemented in FWXMLConfigParser.

Definition at line 137 of file SimpleSAXParser.h.

137 {}
virtual void SimpleSAXParser::endElement ( const std::string &  )
inlinevirtual

Reimplemented in FWXMLConfigParser.

Definition at line 136 of file SimpleSAXParser.h.

136 {}
std::string SimpleSAXParser::getToken ( const char *  delim)
inlineprivate

Definition at line 144 of file SimpleSAXParser.h.

References fgettoken(), m_buffer, m_bufferSize, m_in, and m_nextChar.

145  {
147  return m_buffer;
148  }
std::istream & m_in
bool fgettoken(std::istream &in, char **buffer, size_t *maxSize, const char *separators, int *firstChar)
std::string SimpleSAXParser::getToken ( const char  delim)
inlineprivate

Definition at line 150 of file SimpleSAXParser.h.

References fgettoken(), m_buffer, m_bufferSize, m_in, and m_nextChar.

151  {
152  char buf[2] = {delim, 0};
154  m_nextChar = m_in.get();
155  return m_buffer;
156  }
std::istream & m_in
bool fgettoken(std::istream &in, char **buffer, size_t *maxSize, const char *separators, int *firstChar)
int SimpleSAXParser::nextChar ( void  )
inlineprivate

Definition at line 166 of file SimpleSAXParser.h.

References m_nextChar.

166 { return m_nextChar; }
const SimpleSAXParser& SimpleSAXParser::operator= ( const SimpleSAXParser )
private
void SimpleSAXParser::parse ( void  )

Runs the state machine of the parser, invoking startElement(), setAttribute(), endElement(), data() virtual methods as approppriate. In order have the parser doing something usefull you need to derive from it and specialize the above mentioned virtual methods.

Default implementation is in any case useful to check syntax.

Definition at line 53 of file SimpleSAXParser.cc.

std::string SimpleSAXParser::parseEntity ( const std::string &  entity)
private

Helper function to handle entities, i.e. characters specified with the "&label;" syntax.

Definition at line 7 of file SimpleSAXParser.cc.

bool SimpleSAXParser::skipChar ( int  c)
inlineprivate

Definition at line 158 of file SimpleSAXParser.h.

References m_in, and m_nextChar.

159  {
160  if (m_nextChar != c)
161  return false;
162  m_nextChar = m_in.get();
163  return true;
164  }
std::istream & m_in
virtual void SimpleSAXParser::startElement ( const std::string &  ,
Attributes  
)
inlinevirtual

Reimplemented in FWXMLConfigParser.

Definition at line 134 of file SimpleSAXParser.h.

135  {}

Member Data Documentation

Attributes SimpleSAXParser::m_attributes
private

Definition at line 173 of file SimpleSAXParser.h.

char* SimpleSAXParser::m_buffer
private

Definition at line 170 of file SimpleSAXParser.h.

Referenced by getToken().

size_t SimpleSAXParser::m_bufferSize
private

Definition at line 169 of file SimpleSAXParser.h.

Referenced by getToken().

std::vector<std::string> SimpleSAXParser::m_elementTags
private

Definition at line 172 of file SimpleSAXParser.h.

std::istream& SimpleSAXParser::m_in
private

Definition at line 168 of file SimpleSAXParser.h.

Referenced by getToken(), and skipChar().

int SimpleSAXParser::m_nextChar
private

Definition at line 171 of file SimpleSAXParser.h.

Referenced by getToken(), nextChar(), and skipChar().