FST  openfst-1.7.1
OpenFst Library
stateiterator-class.h
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 
4 #ifndef FST_SCRIPT_STATEITERATOR_CLASS_H_
5 #define FST_SCRIPT_STATEITERATOR_CLASS_H_
6 
7 #include <memory>
8 
9 #include <fst/fstlib.h>
10 #include <fst/script/fst-class.h>
11 
12 // Scripting API support for StateIterator.
13 
14 namespace fst {
15 namespace script {
16 
17 // Virtual interface implemented by each concrete StateIteratorImpl<F>.
19  public:
20  virtual bool Done() const = 0;
21  virtual int64 Value() const = 0;
22  virtual void Next() = 0;
23  virtual void Reset() = 0;
25 };
26 
27 // Templated implementation.
28 template <class Arc>
30  public:
31  explicit StateIteratorClassImpl(const Fst<Arc> &fst) : siter_(fst) {}
32 
33  bool Done() const final { return siter_.Done(); }
34 
35  int64 Value() const final { return siter_.Value(); }
36 
37  void Next() final { siter_.Next(); }
38 
39  void Reset() final { siter_.Reset(); }
40 
42 
43  private:
44  StateIterator<Fst<Arc>> siter_;
45 };
46 
47 class StateIteratorClass;
48 
50  std::pair<const FstClass &, StateIteratorClass *>;
51 
52 // Untemplated user-facing class holding a templated pimpl.
54  public:
55  explicit StateIteratorClass(const FstClass &fst);
56 
57  template <class Arc>
58  explicit StateIteratorClass(const Fst<Arc> &fst)
59  : impl_(new StateIteratorClassImpl<Arc>(fst)) {}
60 
61  bool Done() const { return impl_->Done(); }
62 
63  int64 Value() const { return impl_->Value(); }
64 
65  void Next() { impl_->Next(); }
66 
67  void Reset() { impl_->Reset(); }
68 
69  template <class Arc>
71 
72  private:
73  std::unique_ptr<StateIteratorImplBase> impl_;
74 };
75 
76 template <class Arc>
78  const Fst<Arc> &fst = *(std::get<0>(*args).GetFst<Arc>());
79  std::get<1>(*args)->impl_.reset(new StateIteratorClassImpl<Arc>(fst));
80 }
81 
82 } // namespace script
83 } // namespace fst
84 
85 #endif // FST_SCRIPT_STATEITERATOR_CLASS_H_
StateIteratorClassImpl(const Fst< Arc > &fst)
StateIteratorClass(const Fst< Arc > &fst)
virtual int64 Value() const =0
std::pair< const FstClass &, StateIteratorClass * > InitStateIteratorClassArgs
int64_t int64
Definition: types.h:27
virtual bool Done() const =0
void InitStateIteratorClass(InitStateIteratorClassArgs *args)