00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ASTL_STATS_H
00023 #define ASTL_STATS_H
00024
00025 #include <astl.h>
00026
00027 namespace astl {
00028
00029 struct DFA_stats
00030 {
00031 typedef unsigned long state_type;
00032 typedef empty tag_type;
00033 unsigned long _state_count, _trans_count, _final_states;
00034 static const state_type null_state = 0;
00035 tag_type dummy;
00036
00037 DFA_stats()
00038 : _state_count(0), _trans_count(0), _final_states(0)
00039 { }
00040
00041 state_type new_state() { return ++_state_count; }
00042
00043 template <typename CharType>
00044 void set_trans(state_type from, const CharType&, state_type to) {
00045 ++_trans_count;
00046 }
00047
00048 struct bool_reference
00049 {
00050 state_type q;
00051 DFA_stats &dfa;
00052
00053 bool_reference(state_type p, DFA_stats &a)
00054 : q(p), dfa(a)
00055 { }
00056
00057 bool_reference& operator= (bool b) {
00058 if (b == true)
00059 ++dfa._final_states;
00060 return *this;
00061 }
00062 };
00063
00064 tag_type& tag(state_type q) { return dummy; }
00065 const tag_type& tag(state_type q) const { return dummy; }
00066
00067 bool_reference final(state_type q) { return bool_reference(q, *this); }
00068
00069 unsigned long state_count() const { return _state_count; }
00070
00071 unsigned long trans_count() const { return _trans_count; }
00072
00073 unsigned long final_count() const { return _final_states; }
00074 };
00075
00076 template <typename DFirstCursor>
00077 int word_count(DFirstCursor first, DFirstCursor last = DFirstCursor())
00078 {
00079 int count = 0;
00080 if (first != last && first.src_final()) ++count;
00081
00082 while (first != last) {
00083 do if (first.aim_final()) ++count;
00084 while (first.forward());
00085 while (!first.forward());
00086 }
00087 return count;
00088 }
00089
00090 }
00091
00092 #endif // ASTL_STATS_H
00093
00094
00095
00096
00097
00098
00099