00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef __CLASSAD_XMLLEXER_H__
00022 #define __CLASSAD_XMLLEXER_H__
00023 
00024 #include "classad/common.h"
00025 #include "classad/lexerSource.h"
00026 #include <map>
00027 
00028 BEGIN_NAMESPACE( classad )
00029 
00030 typedef std::map<std::string, std::string> XMLAttributes;
00031 typedef std::map<std::string, std::string>::iterator XMLAttributesIterator;
00032 
00033 
00034 class XMLLexer
00035 {
00036  public:
00037     enum TokenType
00038     {
00039         tokenType_Tag,
00040         tokenType_Text,
00041         tokenType_Invalid
00042     };
00043     enum TagType
00044     {
00045         tagType_Start, 
00046         tagType_End,   
00047         tagType_Empty, 
00048         tagType_Invalid
00049     };
00050     enum TagID
00051     {
00052         tagID_ClassAds,
00053         tagID_ClassAd,
00054         tagID_Attribute,
00055         tagID_Integer,
00056         tagID_Real,
00057         tagID_String,
00058         tagID_Bool,
00059         tagID_Undefined,
00060         tagID_Error,
00061         tagID_AbsoluteTime,
00062         tagID_RelativeTime,
00063         tagID_List,
00064         tagID_Expr,
00065         tagID_XML,
00066         tagID_XMLStylesheet,
00067         tagID_Doctype,
00068         tagID_NoTag
00069     };
00070     
00071     class Token
00072     {
00073     public:
00074         Token();
00075         ~Token();
00076         void ClearToken(void);
00077         void DumpToken(void);
00078 
00079         TokenType      token_type;
00080         TagType        tag_type;
00081         TagID          tag_id;
00082         std::string    text;
00083         XMLAttributes  attributes;
00084     };
00085 
00086     XMLLexer ();
00087     ~XMLLexer ();
00088 
00089     void SetLexerSource(LexerSource *source);
00090 
00091     
00092     bool PeekToken(Token* token);
00093     bool ConsumeToken(Token *token);
00094 
00095  private:
00096     Token       current_token;
00097     bool        token_is_valid;
00098     LexerSource *lexer_source;
00099 
00100     bool GrabToken(void);
00101     bool GrabTag(void);
00102     void BreakdownTag(const char *complete_tag);
00103     bool GrabText(void);
00104  private:
00105     
00106     
00107     
00108     
00109     
00110     XMLLexer(const XMLLexer &)            { return;       }
00111     XMLLexer &operator=(const XMLLexer &) { return *this; }
00112 };
00113 
00114 struct xml_tag_mapping
00115 {
00116     const char      *tag_name;
00117     XMLLexer::TagID  id;
00118 };
00119 
00120 #define NUMBER_OF_TAG_MAPPINGS (sizeof(tag_mappings)/sizeof(struct xml_tag_mapping))
00121 extern struct xml_tag_mapping tag_mappings[];
00122 
00123 
00124 END_NAMESPACE 
00125 
00126 #endif //__CLASSAD_XMLLEXER_H__