Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SAX_AIFHandlers.h

Go to the documentation of this file.
00001 // SAX_AIFHandlers.h: AIF document handler class
00002 // Haejoong Lee, Xiaoyi Ma, Steven Bird
00003 // Copyright (C) 2001 Linguistic Data Consortium, U Penn.
00004 // Web: http://www.ldc.upenn.edu/; Email: ldc@ldc.upenn.edu
00005 // For license information, see the file `LICENSE' included
00006 // with the distribution.
00007 
00008 
00009 #ifndef _SAX_AIFHANDLERS_H_
00010 #define _SAX_AIFHANDLERS_H_
00011 
00012 #include <sax/HandlerBase.hpp>
00013 #include <util/XMLString.hpp>
00014 #include <sax/AttributeList.hpp>
00015 #include <framework/XMLFormatter.hpp>
00016 
00018 class SAX_AIFHandlers : public HandlerBase, private XMLFormatTarget
00019 {
00020 private:
00021   AGIds agIds;  // contains id's of loaded AG's
00022   // they are needed by AIF::load(),
00023   // because it needs to return id's of AG's it has loaded
00024 
00025   string prevId;        // These are need to set features or medatada for
00026   string prevFeature;   // objects such as AGSet, Timeline, Signal and AG.
00027   string prevValue;     // They provide temporary storage.
00028 
00029   XMLFormatter* formatter;
00030   string targetString;
00031   void writeChars(const XMLByte* const, const unsigned int, XMLFormatter* const);
00032   void set_string(string&, const XMLCh* const);
00033 
00034   // StartFP: a type for function pointers to element handlers which are
00035   //     invoked when the start tag is detected
00036   // EndFP: a type for function pointers to element handlers which are
00037   //     invoked when the end tag is detected
00038   typedef void (SAX_AIFHandlers::*StartFP)(const XMLCh* const, AttributeList&);
00039   typedef void (SAX_AIFHandlers::*EndFP)(const XMLCh* const);
00040 
00041   // stack class
00042   // The reason why we don't use STL stack class is that
00043   // STL stack didn't work with function pointers
00044   template<class T>
00045   class stack
00046   {
00047   private:
00048     int itop;
00049     T array[8];  // the depth of AIF is 5, so 8 is enough
00050 
00051   public:
00052     stack(): itop(0) {}
00053 
00054     T top()
00055     {
00056       return array[itop];
00057     }
00058 
00059     void push(T f)
00060     {
00061       if (itop < 8)
00062         array[++itop] = f;
00063       else
00064         throw ("stack overflow");
00065     }
00066 
00067     void pop()
00068     {
00069       if (itop > 0)
00070         itop--;
00071       else
00072         throw ("stack underflow");
00073     }
00074   };
00075 
00076   // stacks for element handlers
00077   stack<StartFP> StartStack;
00078   stack<EndFP>   EndStack;
00079 
00080   // do-nothing handlers
00081   void dummyStart(const XMLCh* const name, AttributeList& attr);
00082   void dummyEnd(const XMLCh* const name);
00083   // element handlers
00084   void AGSetStart(const XMLCh* const name, AttributeList& attr);
00085   void AGSetEnd(const XMLCh* const name);
00086   void AGSetSubStart(const XMLCh* const name, AttributeList& attr);
00087   void MetadataSubStart(const XMLCh* const name, AttributeList& attr);
00088   void MetadataSubEnd(const XMLCh* const name);
00089   void TimelineSubStart(const XMLCh* const name, AttributeList& attr);
00090   void SignalSubStart(const XMLCh* const name, AttributeList& attr);
00091   void AGSubStart(const XMLCh* const name, AttributeList& attr);
00092   void AnnotationSubStart(const XMLCh* const name, AttributeList& attr);
00093   void FeatureEnd(const XMLCh* const name);
00094   
00095 public:
00096   SAX_AIFHandlers(const string& outEncoding);
00097   ~SAX_AIFHandlers();
00098 
00099   void set_encoding(const string&);
00100   AGIds get_agids() { return agIds.substr(1); }
00101 
00102   void startElement(const XMLCh* const name, AttributeList& attr);
00103   void endElement(const XMLCh* const name);
00104   void characters(const XMLCh* const chars, const unsigned int length);
00105 
00106   void warning(const SAXParseException& exception);
00107   void error(const SAXParseException& exception);
00108   void fatalError(const SAXParseException& exception);
00109 };
00110 
00111 #endif

Generated at Wed Jul 3 14:54:04 2002 for Annotation Graph API by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001