TokenVectorHolder Class Reference

#include <kaldi-holder-inl.h>

Collaboration diagram for TokenVectorHolder:

Public Types

typedef std::vector< std::string > T
 

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (TokenVectorHolder)
 

Private Attributes

T t_
 

Detailed Description

Definition at line 695 of file kaldi-holder-inl.h.

Member Typedef Documentation

◆ T

typedef std::vector<std::string> T

Definition at line 697 of file kaldi-holder-inl.h.

Constructor & Destructor Documentation

◆ TokenVectorHolder()

TokenVectorHolder ( )
inline

Definition at line 699 of file kaldi-holder-inl.h.

699 { }

Member Function Documentation

◆ Clear()

void Clear ( )
inline

Definition at line 713 of file kaldi-holder-inl.h.

References KaldiObjectHolder< KaldiType >::t_.

713 { t_.clear(); }

◆ ExtractRange()

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

Definition at line 745 of file kaldi-holder-inl.h.

References KaldiObjectHolder< KaldiType >::KALDI_DISALLOW_COPY_AND_ASSIGN(), and KALDI_ERR.

746  {
747  KALDI_ERR << "ExtractRange is not defined for this type of holder.";
748  return false;
749  }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ IsReadInBinary()

static bool IsReadInBinary ( )
inlinestatic

Definition at line 737 of file kaldi-holder-inl.h.

737 { return false; }

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( TokenVectorHolder  )
private

◆ Read()

bool Read ( std::istream &  is)
inline

Definition at line 717 of file kaldi-holder-inl.h.

References KALDI_WARN, kaldi::SplitStringToVector(), and KaldiObjectHolder< KaldiType >::t_.

717  {
718  t_.clear();
719 
720  // there is no binary/non-binary mode.
721 
722  std::string line;
723  getline(is, line); // this will discard the \n, if present.
724  if (is.fail()) {
725  KALDI_WARN << "BasicVectorHolder::Read, error reading line " << (is.eof()
726  ? "[eof]" : "");
727  return false; // probably eof. fail in any case.
728  }
729  const char *white_chars = " \t\n\r\f\v";
730  SplitStringToVector(line, white_chars, true, &t_); // true== omit
731  // empty strings e.g. between spaces.
732  return true;
733  }
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
Definition: text-utils.cc:63
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ Swap()

void Swap ( TokenVectorHolder other)
inline

Definition at line 741 of file kaldi-holder-inl.h.

References KaldiObjectHolder< KaldiType >::t_, and TokenVectorHolder::t_.

741  {
742  t_.swap(other->t_);
743  }

◆ Value()

T& Value ( )
inline

Definition at line 739 of file kaldi-holder-inl.h.

References KaldiObjectHolder< KaldiType >::t_.

739 { return t_; }

◆ Write()

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

Definition at line 701 of file kaldi-holder-inl.h.

References kaldi::IsToken(), and KALDI_ASSERT.

701  { // ignore binary-mode
702  for (std::vector<std::string>::const_iterator iter = t.begin();
703  iter != t.end();
704  ++iter) {
705  KALDI_ASSERT(IsToken(*iter)); // make sure it's whitespace-free,
706  // printable and nonempty.
707  os << *iter << ' ';
708  }
709  os << '\n';
710  return os.good();
711  }
bool IsToken(const std::string &token)
Returns true if "token" is nonempty, and all characters are printable and whitespace-free.
Definition: text-utils.cc:105
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

Member Data Documentation

◆ t_

T t_
private

Definition at line 753 of file kaldi-holder-inl.h.

Referenced by TokenVectorHolder::Swap().


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