CompactLatticeHolder Class Reference

#include <kaldi-lattice.h>

Collaboration diagram for CompactLatticeHolder:

Public Types

typedef CompactLattice T
 

Public Member Functions

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

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 69 of file kaldi-lattice.h.

Member Typedef Documentation

◆ T

typedef CompactLattice T

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

Constructor & Destructor Documentation

◆ CompactLatticeHolder()

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

References CompactLatticeHolder::t_.

73 { t_ = NULL; }

◆ ~CompactLatticeHolder()

~CompactLatticeHolder ( )
inline

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

References CompactLatticeHolder::Clear().

102 { Clear(); }

Member Function Documentation

◆ Clear()

void Clear ( )
inline

◆ ExtractRange()

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

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

References KALDI_ERR.

97  {
98  KALDI_ERR << "ExtractRange is not defined for this type of holder.";
99  return false;
100  }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ IsReadInBinary()

static bool IsReadInBinary ( )
inlinestatic

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

84 { return true; }

◆ Read()

bool Read ( std::istream &  is)

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

References KALDI_WARN, and kaldi::ReadCompactLattice().

Referenced by CompactLatticeHolder::Write(), and LatticeHolder::Write().

366  {
367  Clear(); // in case anything currently stored.
368  int c = is.peek();
369  if (c == -1) {
370  KALDI_WARN << "End of stream detected reading CompactLattice.";
371  return false;
372  } else if (isspace(c)) { // The text form of the lattice begins
373  // with space (normally, '\n'), so this means it's text (the binary form
374  // cannot begin with space because it starts with the FST Type() which is not
375  // space).
376  return ReadCompactLattice(is, false, &t_);
377  } else if (c != 214) { // 214 is first char of FST magic number,
378  // on little-endian machines which is all we support (\326 octal)
379  KALDI_WARN << "Reading compact lattice: does not appear to be an FST "
380  << " [non-space but no magic number detected], file pos is "
381  << is.tellg();
382  return false;
383  } else {
384  return ReadCompactLattice(is, true, &t_);
385  }
386 }
#define KALDI_WARN
Definition: kaldi-error.h:150
bool ReadCompactLattice(std::istream &is, bool binary, CompactLattice **clat)

◆ Swap()

void Swap ( CompactLatticeHolder other)
inline

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

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

93  {
94  std::swap(t_, other->t_);
95  }
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)

◆ Value()

T& Value ( )
inline

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

References KALDI_ASSERT, and CompactLatticeHolder::t_.

86  {
87  KALDI_ASSERT(t_ != NULL && "Called Value() on empty CompactLatticeHolder");
88  return *t_;
89  }
#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 75 of file kaldi-lattice.h.

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

75  {
76  // Note: we don't include the binary-mode header when writing
77  // this object to disk; this ensures that if we write to single
78  // files, the result can be read by OpenFst.
79  return WriteCompactLattice(os, binary, t);
80  }
bool WriteCompactLattice(std::ostream &os, bool binary, const CompactLattice &t)

Member Data Documentation

◆ t_


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