00001
00002
00003 #ifndef MIX_TOKENIZER_H_
00004 #define MIX_TOKENIZER_H_
00005
00006
00007 #include "classes.h"
00008 #include "misc.h"
00009 #include "XMLToken.h"
00010
00011 #include <stack>
00012 #include <string>
00013
00014 namespace MiX{
00015
00016 template <class charT,class char_traits,class xml_traits>
00017 class Tokenizer{
00018 public:
00019 MiX_Template_Typedef(charT,char_traits,xml_traits);
00020 typedef Tokenizer<charT,char_traits,xml_traits> this_type;
00021 typedef XMLToken<charT,char_traits,xml_traits> token_type;
00022 private:
00023 const charT* data_;
00024 const charT* start_;
00025 const charT* current_;
00031 charT* line_;
00032 long len_;
00033 static const charT tokens_[15];
00034 std::stack<token_type> stack_;
00035 static TokenType isToken(charT);
00036
00037 std::basic_istream<charT, char_traits>* is_;
00038
00039 bool injectStringFromBuffer(const charT* text)
00040 { current_ = start_ = data_ = text; return true; }
00041
00042 bool fillUpBuffer();
00043 public:
00045 Tokenizer() : is_(0),line_(0) { }
00047 ~Tokenizer(){ if(line_) delete line_; }
00049 bool injectString(const charT* text)
00050 { current_ = start_ = data_ = text; return true; }
00052 bool ejectToken(token_type& dest);
00054 void pushToken(const token_type& tok){
00055 stack_.push(tok);
00056 }
00057
00058 bool injectStream(std::basic_istream<charT, char_traits>& is)
00059 { is_ = &is; fillUpBuffer(); return true; }
00060
00061 };
00062
00063 }
00064
00065 #ifndef MIX_TOKENIZER_CPP_
00066 #include "Tokenizer.cpp"
00067 #endif
00068
00069 #endif