LatticeHolder Class Reference

#include <kaldi-lattice.h>

Collaboration diagram for LatticeHolder:

Public Types

typedef Lattice T
 

Public Member Functions

 LatticeHolder ()
 
bool Read (std::istream &is)
 
TValue ()
 
void Clear ()
 
void Swap (LatticeHolder *other)
 
bool ExtractRange (const LatticeHolder &other, const std::string &range)
 
 ~LatticeHolder ()
 

Static Public Member Functions

static bool Write (std::ostream &os, bool binary, const T &t)
 
static bool IsReadInBinary ()
 

Private Attributes

Tt_
 

Detailed Description

Definition at line 107 of file kaldi-lattice.h.

Member Typedef Documentation

◆ T

typedef Lattice T

Definition at line 109 of file kaldi-lattice.h.

Constructor & Destructor Documentation

◆ LatticeHolder()

LatticeHolder ( )
inline

Definition at line 111 of file kaldi-lattice.h.

References CompactLatticeHolder::t_.

111 { t_ = NULL; }

◆ ~LatticeHolder()

~LatticeHolder ( )
inline

Definition at line 140 of file kaldi-lattice.h.

References CompactLatticeHolder::Clear().

140 { Clear(); }

Member Function Documentation

◆ Clear()

void Clear ( )
inline

Definition at line 129 of file kaldi-lattice.h.

References CompactLatticeHolder::t_.

129 { delete t_; t_ = NULL; }

◆ ExtractRange()

bool ExtractRange ( const LatticeHolder other,
const std::string &  range 
)
inline

Definition at line 135 of file kaldi-lattice.h.

References KALDI_ERR.

135  {
136  KALDI_ERR << "ExtractRange is not defined for this type of holder.";
137  return false;
138  }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ IsReadInBinary()

static bool IsReadInBinary ( )
inlinestatic

Definition at line 122 of file kaldi-lattice.h.

122 { return true; }

◆ Read()

bool Read ( std::istream &  is)

Definition at line 482 of file kaldi-lattice.cc.

References KALDI_WARN, and kaldi::ReadLattice().

482  {
483  Clear(); // in case anything currently stored.
484  int c = is.peek();
485  if (c == -1) {
486  KALDI_WARN << "End of stream detected reading Lattice.";
487  return false;
488  } else if (isspace(c)) { // The text form of the lattice begins
489  // with space (normally, '\n'), so this means it's text (the binary form
490  // cannot begin with space because it starts with the FST Type() which is not
491  // space).
492  return ReadLattice(is, false, &t_);
493  } else if (c != 214) { // 214 is first char of FST magic number,
494  // on little-endian machines which is all we support (\326 octal)
495  KALDI_WARN << "Reading compact lattice: does not appear to be an FST "
496  << " [non-space but no magic number detected], file pos is "
497  << is.tellg();
498  return false;
499  } else {
500  return ReadLattice(is, true, &t_);
501  }
502 }
bool ReadLattice(std::istream &is, bool binary, Lattice **lat)
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ Swap()

void Swap ( LatticeHolder other)
inline

Definition at line 131 of file kaldi-lattice.h.

References kaldi::swap(), CompactLatticeHolder::t_, and LatticeHolder::t_.

131  {
132  std::swap(t_, other->t_);
133  }
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)

◆ Value()

T& Value ( )
inline

Definition at line 124 of file kaldi-lattice.h.

References KALDI_ASSERT, and CompactLatticeHolder::t_.

124  {
125  KALDI_ASSERT(t_ != NULL && "Called Value() on empty LatticeHolder");
126  return *t_;
127  }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Write()

static bool Write ( std::ostream &  os,
bool  binary,
const T t 
)
inlinestatic

Definition at line 113 of file kaldi-lattice.h.

References CompactLatticeHolder::Read(), and kaldi::WriteLattice().

113  {
114  // Note: we don't include the binary-mode header when writing
115  // this object to disk; this ensures that if we write to single
116  // files, the result can be read by OpenFst.
117  return WriteLattice(os, binary, t);
118  }
bool WriteLattice(std::ostream &os, bool binary, const Lattice &t)

Member Data Documentation

◆ t_

T* t_
private

Definition at line 142 of file kaldi-lattice.h.

Referenced by LatticeHolder::Swap().


The documentation for this class was generated from the following files: