📄 debug.h
字号:
dereferenceable = true; cerr << " Found " << endl ; return true; } cerr << "not Found " << endl ; return false; } bool forward(const char_type &letter) { cerr << "\t forward("<< letter <<") " << endl; if (singular) { cerr << "forward_cursor::forward(letter) : CRITICAL" << endl; cerr << "\t trying to move along transition through a singular cursor" << endl; } else if (q == dfa->null_state) { cerr << "forward_cursor::forward(letter) : CRITICAL" << endl; cerr << "\t trying to move along outgoing transition of sink state" << endl; } dereferenceable = false; q = dfa->delta1(q, letter); return q != dfa->null_state; } state_type src() const { cerr << "\t src( "<< q <<") " <<endl; if (singular) { cerr << "forward_cursor::src() : WARNING" << endl; cerr << "\t trying to access source state of a singular cursor" << endl; } return q; } state_type aim() const { cerr << "\t aim( " <<(*transition).second <<") " << endl; if (singular) { cerr << "forward_cursor::aim() : CRITICAL" << endl; cerr << "\t trying to access aim state of a singular cursor" << endl; } else if (!dereferenceable) { cerr << "forward_cursor::aim() : CRITICAL" << endl; cerr << "\t trying to access aim state of a non dereferenceable cursor" << endl; } return (*transition).second; } bool src_final() const { if (singular) { cerr << "forward_cursor::src_final() : WARNING" << endl; cerr << "\t trying to access source state of a singular cursor" << endl; } else if (q == dfa->null_state) { cerr << "forward_cursor::src_final() : WARNING" << endl; cerr << "\t trying to access sink state" << endl; } return dfa->final(q); } bool aim_final() const { if (singular) { cerr << "forward_cursor::aim_final() : CRITICAL" << endl; cerr << "\t trying to access aim state of a singular cursor" << endl; } else if (!dereferenceable) { cerr << "forward_cursor::aim_final() : CRITICAL" << endl; cerr << "\t trying to access aim state of a non dereferenceable cursor" << endl; } return dfa->final((*transition).second); } bool exists(const char_type &letter) const { // transition exists ? cerr << "\t exist " << endl; if (singular) { cerr << "forward_cursor::exist() : CRITICAL" << endl; cerr << "\t testing for a transition through a singular cursor" << endl; } else if (!dereferenceable) { cerr << "forward_cursor::exist() : CRITICAL" << endl; cerr << "\t testing for a transition through a non dereferenceable cursor" << endl; } else if (q == dfa->null_state) { cerr << "forward_cursor::exist() : CRITICAL" << endl; cerr << "\t testing for a transition from sink state" << endl; } return dfa->delta1(q, letter) != dfa->null_state; } const tag_type& src_tag() const { if (singular) { cerr << "forward_cursor::src_tag() : CRITICAL" << endl; cerr << "\t trying to access source tag of a singular cursor" << endl; } else if (q == dfa->null_state) { cerr << "forward_cursor::src_tag() : WARNING" << endl; cerr << "\t trying to access tag of sink state" << endl; } return dfa->tag(q); } const tag_type& aim_tag() const { if (singular) { cerr << "forward_cursor::aim_tag() : CRITICAL" << endl; cerr << "\t trying to access aim tag of a singular cursor" << endl; } else if (!dereferenceable) { cerr << "forward_cursor::aim_tag() : CRITICAL" << endl; cerr << "\t trying to access aim tag of a non dereferenceable cursor"; } return dfa->tag((*transition).second); } // Not a standard requirement: friend ostream& operator << (ostream &out, const self &x) { out << x.q << " , '"; if (x.singular) out << "singular'"; else if (!x.dereferenceable) { if (x.transition == x.dfa->delta2(x.q).end()) out << "end of range'"; else out << "not dereferenceable'"; } else out << (*(x.transition)).first << "', " << (*(x.transition)).second; return out; } // Not a standard requirement: bool operator < (const self &x) const { // STL containers need operator < on // their value_type (to define < on themselves) if (singular) cerr << "forward_cursor::operator< (forward_cursor) : caution" << endl << "\t comparing singular left cursor with" << (x.singular ? " singular " : " ") << "right cursor" << endl; else if (x.singular) cerr << "forward_cursor::operator< (forward_cursor) : caution" << endl << "\t comparing left cursor with singular right cursor" << endl; return q < x.q || (q == x.q && transition < x.transition); }};// Helper functions:// Build a debug plain cursor from a DFA:template <class DFA>cursor_debug<DFA> debugplainc(const DFA &a) { return cursor_debug<DFA>(a, a.initial());}// Build a debug forward cursor from a DFA:template <class DFA>forward_cursor_debug<DFA> debugc(const DFA &a) { return forward_cursor_debug<DFA>(a, a.initial());}template <class Cursor>class cursor_trace : public cursor_concept{public: typedef cursor_trace self; typedef typename Cursor::state_type state_type; typedef typename Cursor::tag_type tag_type; typedef typename Cursor::char_type char_type; typedef typename Cursor::char_traits char_traits; static int id; // Backward compatibility typedefs: typedef state_type State; typedef tag_type Tag; typedef char_type Alphabet; typedef char_traits Sigma;protected: Cursor c; int ID;public: cursor_trace() : c(), ID(++id) { cerr << "cursor[" << ID << "]::cursor()" << endl; } cursor_trace(const Cursor &x) : c(x), ID(++id) { cerr << "cursor[" << ID << "]::cursor(Cursor " << &x << ")" << endl; } cursor_trace(const self &x) : c(x.c), ID(x.ID) { cerr << "cursor[" << ID << "]::cursor(self)" << endl; } ~cursor_trace() { cerr << "cursor[" << ID << "]::~cursor()" << endl; } state_type src() const { cerr << "cursor[" << ID << "]::src() == " << c.src() << endl; return c.src(); } state_type sink_state() const { cerr << "cursor[" << ID << "]::sink_state() == " << c.sink_state() << endl; return c.sink_state(); } self& operator= (state_type p) { cerr << "cursor[" << ID << "]::operator=(state_type " << p << ")" << endl; c = p; return *this; } self& operator= (const self &x) { cerr << "cursor[" << ID << "]::operator=(self [" << x.ID << "])" << endl; c = x.c; return *this; } bool operator== (const self &x) const { cerr << "cursor[" << ID << "]::operator==(self [" << x.ID << "]) == " << (c == x.c) << endl; return c == x.c; } bool sink() const { cerr << "cursor[" << ID << "]::sink() == " << c.sink() << endl; return c.sink(); } bool forward(const char_type &letter) { cerr << "cursor[" << ID << "]::forward('" << letter << "') == "; cerr << c.forward(letter) << endl; return !c.sink(); } bool src_final() const { cerr << "cursor[" << ID << "]::src_final() == " << c.src_final() << endl; return c.src_final(); } const tag_type& src_tag() const { cerr << "cursor[" << ID << "]::src_tag()" << endl; return c.src_tag(); } bool exists(const char_type &letter) const { // transition exists ? cerr << "cursor[" << ID << "]::exists(int " << letter << ") == " << c.exists(letter) << endl; return c.exists(letter); }};template <class Cursor> int cursor_trace<Cursor>::id = 0;template <class ForwardCursor>class forward_cursor_trace : public forward_cursor_concept{public: typedef forward_cursor_trace self; typedef typename ForwardCursor::state_type state_type; typedef typename ForwardCursor::tag_type tag_type; typedef typename ForwardCursor::char_type char_type; typedef typename ForwardCursor::char_traits char_traits; // Backward compatibility typedefs: typedef state_type State; typedef tag_type Tag; typedef char_type Alphabet; typedef char_traits Sigma;protected: ForwardCursor c; static int id; int ID;public: forward_cursor_trace(const ForwardCursor &x) : c(x), ID(++id) { cerr << "fcursor[" << ID << "]::fcursor(forward_cursor " << &x << ")" << endl; } forward_cursor_trace() : c(), ID(++id) { cerr << "fcursor[" << ID << "]::fcursor()"; } forward_cursor_trace(const self &x) : c(x.c), ID(++id) { cerr << "fcursor[" << ID << "](self[" << x.ID << "])" << endl; } ~forward_cursor_trace() { cerr << "fcursor[" << ID << "]::~fcursor()" << endl; } self& operator= (state_type p) { cerr << "fcursor[" << ID << "]::operator=(state_type " << p << ")" << endl; c = p; return *this; } self& operator= (const self &x) { cerr << "fcursor[" << ID << "]::operator=(self [" << x.ID << "])" << endl; c = x.c; return *this; } bool operator== (const self &x) const { cerr << "fcursor[" << ID << "]::operator==(self [" << x.ID << "]) == " << (c == x.c) << endl; return (c == x.c); } char_type letter() const { cerr << "fcursor[" << ID << "]::letter() == '" << c.letter() << "'" << endl; return c.letter(); } bool first_transition() { cerr << "fcursor[" << ID << "]::first_transition() == "; if (c.first_transition()) cerr << "(" << c.src() << ", '" << c.letter() << "', " << c.aim() << ")" << endl; else cerr << "0" << endl; return c.first_transition(); } bool next_transition() { bool r = c.next_transition(); cerr << "fcursor[" << ID << "]::next_transition() == "; if (r) cerr << "(" << c.src() << ", '" << c.letter() << "', " << c.aim() << ")" << endl; else cerr << "0" << endl; return r; } bool forward(const char_type &letter) { cerr << "fcursor[" << ID << "]::forward('" << letter << "') == "; if (c.forward(letter)) cerr << c.src() << endl; else cerr << "0" << endl; return !c.sink(); } void forward() { c.forward(); cerr << "fcursor[" << ID << "]::forward() == " << c.src() << endl; } bool find(const char_type &letter) { cerr << "fcursor[" << ID << "]::find('" << letter << "') == "; if (c.find(letter)) cerr << "(" << c.src() << ", '" << c.letter() << "', " << c.aim() << ")" << endl; else cerr << "0" << endl; return c.find(letter); } state_type src() const { cerr << "fcursor[" << ID << "]::src() == " << c.src() << endl; return c.src(); } bool src_final() const { cerr << "fcursor[" << ID << "]::src_final() == " << c.src_final() << endl; return c.src_final(); } state_type aim() const { cerr << "fcursor[" << ID << "]::aim() == " << c.aim() << endl; return c.aim(); } bool aim_final() const { cerr << "fcursor[" << ID << "]::aim_final() == " << c.aim_final() << endl; return c.aim_final(); } const tag_type& aim_tag() const { cerr << "fcursor[" << ID << "]::aim_tag()" << endl; return c.aim_tag(); } const tag_type& src_tag() const { cerr << "fcursor[" << ID << "]::src_tag()" << endl; return c.src_tag(); } bool sink() const { cerr << "fcursor[" << ID << "]::sink() == " << c.sink() << endl; return c.sink(); } state_type sink_state() const { cerr << "fcursor[" << ID << "]::sink_state() == " << c.sink_state() << endl; return c.sink_state(); } bool exists(const char_type &letter) const { // transition exists ? cerr << "fcursor[" << ID << "]::exists(" << letter << ") == " << c.exists(letter) << endl; return c.exists(letter); }};template <class ForwardCursor> int forward_cursor_trace<ForwardCursor>::id = 0;template <class ForwardCursor>forward_cursor_trace<ForwardCursor> tracec(const ForwardCursor &x) { return forward_cursor_trace<ForwardCursor>(x);}ASTL_END_NAMESPACE#endif // ASTL_CURSOR_DEBUG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -