00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ASTL_DEFAULT_H
00023 #define ASTL_DEFAULT_H
00024
00025
00026
00027 namespace astl {
00028
00029
00030
00031
00032 template <typename Cursor>
00033 class def_trans_cursor : public Cursor
00034 {
00035 public:
00036 typedef Cursor super;
00037 typedef def_trans_cursor self;
00038 typedef typename super::char_type char_type;
00039 typedef typename super::state_type state_type;
00040
00041 def_trans_cursor()
00042 { }
00043
00044 def_trans_cursor(const Cursor &x, const char_type& default_letter)
00045 : super(x), def_letter(default_letter)
00046 { }
00047
00048 bool forward(const char_type &a) {
00049 if (exists(a)) {
00050 super::forward(a);
00051 return true;
00052 }
00053 return super::forward(def_letter);
00054 }
00055
00056 self& operator=(const state_type &p) {
00057 super::operator=(p);
00058 return *this;
00059 }
00060
00061 protected:
00062 typename Cursor::char_type def_letter;
00063 };
00064
00065
00066
00067
00068
00069
00070
00071 template <class ForwardC>
00072 class def_state_cursor : public ForwardC
00073 {
00074 public:
00075 typedef typename ForwardC::state_type state_type;
00076 typedef typename ForwardC::char_type char_type;
00077 typedef typename ForwardC::char_traits char_traits;
00078 typedef ForwardC super;
00079 typedef def_state_cursor self;
00080
00081 def_state_cursor()
00082 { }
00083
00084 def_state_cursor(const ForwardC &x, const state_type &default_state)
00085 : super(x), def_state(default_state)
00086 { }
00087
00088 void forward() { super::forward(); }
00089
00090 bool forward(const char_type &letter) {
00091 if (!super::forward(letter))
00092 *this = def_state;
00093 return true;
00094 }
00095
00096 self& operator=(const state_type &x) {
00097 super::operator=(x);
00098 return *this;
00099 }
00100
00101 protected:
00102 state_type def_state;
00103 };
00104
00105
00106
00107
00108 template <typename ForwardC>
00109 class substitute_cursor : public ForwardC
00110 {
00111 public:
00112 typedef ForwardC super;
00113 typedef substitute_cursor self;
00114 typedef typename super::char_type char_type;
00115 typedef typename super::state_type state_type;
00116 typedef typename super::tag_type tag_type;
00117 typedef typename super::char_traits char_traits;
00118
00119 substitute_cursor()
00120 { }
00121
00122 substitute_cursor(const ForwardC &x, const char_type &c)
00123 : super(x), a(c)
00124 { }
00125
00126 void forward() { super::forward(); }
00127
00128 bool forward(const char_type& letter) {
00129 do {
00130 if (super::find(letter)) {
00131 forward();
00132 return true;
00133 }
00134 if (super::find(a) && super::aim() == super::src())
00135 return true;
00136 } while (super::forward(a));
00137 return false;
00138 }
00139
00140 self& operator=(const state_type &x) {
00141 super::operator=(x);
00142 return *this;
00143 }
00144
00145 protected:
00146 typename super::char_type a;
00147 };
00148
00149 template <typename Cursor>
00150 inline
00151 def_trans_cursor<Cursor>
00152 def_transc(const Cursor &x, const typename Cursor::char_type& def_letter) {
00153 return def_trans_cursor<Cursor>(x, def_letter);
00154 }
00155
00156 template <class ForwardC>
00157 inline
00158 def_state_cursor<ForwardC>
00159 def_statec(const ForwardC &x, const typename ForwardC::state_type& p) {
00160 return def_state_cursor<ForwardC>(x, p);
00161 }
00162
00163 template <class ForwardC>
00164 inline
00165 substitute_cursor<ForwardC>
00166 substitutec(const ForwardC &x, const typename ForwardC::char_type &c) {
00167 return substitute_cursor<ForwardC>(x, c);
00168 }
00169
00170 }
00171
00172 #endif // ASTL_DEFAULT_H
00173