xmlLexer.h

00001 /***************************************************************
00002  *
00003  * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
00004  * University of Wisconsin-Madison, WI.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you
00007  * may not use this file except in compliance with the License.  You may
00008  * obtain a copy of the License at
00009  * 
00010  *    http://www.apache.org/licenses/LICENSE-2.0
00011  * 
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
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 // the lexical analyzer class
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, // This is for tags like <foo>
00046         tagType_End,   // This is for tags like </foo>
00047         tagType_Empty, // This is for tags like <foo/>
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     // the 'extract token' functions
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     // The copy constructor and assignment operator are defined
00107     // to be private so we don't have to write them, or worry about
00108     // them being inappropriately used. The day we want them, we can 
00109     // write them. 
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 // classad
00125 
00126 #endif //__CLASSAD_XMLLEXER_H__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends