/** ** Copyright (c) 2007-2009 Illumina, Inc. ** ** This software is covered by the "Illumina Genome Analyzer Software ** License Agreement" and the "Illumina Source Code License Agreement", ** and certain third party copyright/licenses, and any user of this ** source file is bound by the terms therein (see accompanying files ** Illumina_Genome_Analyzer_Software_License_Agreement.pdf and ** Illumina_Source_Code_License_Agreement.pdf and third party ** copyright/license notices). ** ** This file is part of the Consensus Assessment of Sequence And VAriation ** (CASAVA) software package. ** ** \file XMLContentHandler.hh ** ** \brief Rudimentary XML content handler class similar to the Java org.xml.sax ** ContentHandler interface. An XML writer class based on this interface. ** ** \author Klaus Maisinger **/ #ifndef XMLCONTENTHANDLER_H_ #define XMLCONTENTHANDLER_H_ #if defined(__BORLANDC__) #include #else #include #endif #include #include class Attributes { public: Attributes() : item_list(0) {}; virtual ~Attributes() { item_list.clear(); }; virtual int getLength() const; virtual int getIndex(const std::string &name) const; virtual std::string getName(const int index) const; virtual std::string getValue(const int index) const; virtual std::string getValue(const std::string &name) const; virtual void addAttribute(const std::string &name, const std::string &value); private: struct Item { std::string name; std::string value; Item() : name(""), value("") {} Item(const std::string &n, const std::string &v) : name(n), value(v) {} }; std::vector item_list; }; class XMLContentHandler { public: XMLContentHandler() {}; virtual ~XMLContentHandler() {}; virtual void startDocument() {}; virtual void endDocument() {}; virtual void startElement(const char name[], const Attributes *attr = 0) = 0; virtual void endElement(const char name[]) = 0; virtual void characters(const char ch[], int start, int length) = 0; virtual void ignorableWhitespace(const char [], int , int ) {}; }; class XMLFileWriter : public XMLContentHandler { char *iws; protected: FILE *fp; virtual void writeWhitespace(); char *iobuffer; int iobuffer_len; int iobuffer_ptr; virtual void output(const char ch[]); virtual void flush(); public: XMLFileWriter(); XMLFileWriter(FILE *filehandle); virtual ~XMLFileWriter(); virtual void setFileHandle(FILE *filehandle); virtual void startDocument() {}; virtual void endDocument() {}; virtual void startElement(const char name[], const Attributes *attr = 0); virtual void endElement(const char name[]); virtual void characters(const char ch[], int start, int length); virtual void ignorableWhitespace(const char ch[], int start, int length); }; #endif /*XMLCONTENTHANDLER_H_*/