00001 
00002 
00003 
00004 
00005 
00006 
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;  
00022   
00023   
00024 
00025   string prevId;        
00026   string prevFeature;   
00027   string prevValue;     
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   
00035   
00036   
00037   
00038   typedef void (SAX_AIFHandlers::*StartFP)(const XMLCh* const, AttributeList&);
00039   typedef void (SAX_AIFHandlers::*EndFP)(const XMLCh* const);
00040 
00041   
00042   
00043   
00044   template<class T>
00045   class stack
00046   {
00047   private:
00048     int itop;
00049     T array[8];  
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   
00077   stack<StartFP> StartStack;
00078   stack<EndFP>   EndStack;
00079 
00080   
00081   void dummyStart(const XMLCh* const name, AttributeList& attr);
00082   void dummyEnd(const XMLCh* const name);
00083   
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