⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 closure.h

📁 一个类似STL的自动机的源代码库
💻 H
字号:
/* * ASTL - the Automaton Standard Template Library. * C++ generic components for Finite State Automata handling. * Copyright (C) 2000-2003 Vincent Le Maout (vincent.lemaout@chello.fr). *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * */#ifndef ASTL_CLOSURE_H#define ASTL_CLOSURE_H// A closure cursor is a forward cursor adapter// hiding all outgoing transitions not labelled with the user-specified// letter#include <astl.h>#include <cursor.h>ASTL_BEGIN_NAMESPACEtemplate <typename ForwardCursor>class closure_cursor : public ForwardCursor{public:  typedef ForwardCursor             super;  typedef closure_cursor            self;  typedef typename super::char_type char_type;  typedef typename super::state_type state_type;protected:  char_type x;public:  closure_cursor()    : super()  { }  closure_cursor(const ForwardCursor &c, const char_type &a)    : super(c), x(a)  { }  self& operator=(const self &c) {    super::operator=(c);    x = c.x;    return *this;  }  self& operator=(state_type q) {    super::operator=(q);    return *this;  }  bool first_transition() {    if (super::first_transition()) {      if (letter() != x)	return next_transition();      return true;    }    return false;  }      bool next_transition() {    while (super::next_transition())      if (letter() == x) return true;    return false;  }    bool forward(const char_type &a) {    if (a == x) return super::forward(a);    *this = sink_state();    return false;  }  void forward() {    super::forward();  }};template <class ForwardCursor>inlineclosure_cursor<ForwardCursor> closurec(const ForwardCursor &c, const typename ForwardCursor::char_type &a){  return closure_cursor<ForwardCursor>(c, a);}  template <typename DFirstCursor, typename OutputCursor>OutputCursor crop(OutputCursor out, DFirstCursor first, DFirstCursor last = DFirstCursor()){  while (first != last) {    do       *out++ = first.aim();    while (first.forward());    while (!first.forward());    *out++ = first.src();  }  return out;}ASTL_END_NAMESPACE#endif // ASTL_CLOSURE_CURSOR

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -