TokenHolder Class Reference

#include <kaldi-holder-inl.h>

Collaboration diagram for TokenHolder:

Public Types

typedef std::string T
 

Public Member Functions

 TokenHolder ()
 
void Clear ()
 
bool Read (std::istream &is)
 
TValue ()
 
 ~TokenHolder ()
 
void Swap (TokenHolder *other)
 
bool ExtractRange (const TokenHolder &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 (TokenHolder)
 

Private Attributes

T t_
 

Detailed Description

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

Member Typedef Documentation

◆ T

typedef std::string T

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

Constructor & Destructor Documentation

◆ TokenHolder()

TokenHolder ( )
inline

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

643 {}

◆ ~TokenHolder()

~TokenHolder ( )
inline

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

676 { }

Member Function Documentation

◆ Clear()

void Clear ( )
inline

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

References KaldiObjectHolder< KaldiType >::t_.

651 { t_.clear(); }

◆ ExtractRange()

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

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

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

683  {
684  KALDI_ERR << "ExtractRange is not defined for this type of holder.";
685  return false;
686  }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ IsReadInBinary()

static bool IsReadInBinary ( )
inlinestatic

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

672 { return false; }

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( TokenHolder  )
private

◆ Read()

bool Read ( std::istream &  is)
inline

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

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

654  {
655  is >> t_;
656  if (is.fail()) return false;
657  char c;
658  while (isspace(c = is.peek()) && c!= '\n') is.get();
659  if (is.peek() != '\n') {
660  KALDI_WARN << "TokenHolder::Read, expected newline, got char "
661  << CharToString(is.peek())
662  << ", at stream pos " << is.tellg();
663  return false;
664  }
665  is.get(); // get '\n'
666  return true;
667  }
#define KALDI_WARN
Definition: kaldi-error.h:150
std::string CharToString(const char &c)
Definition: kaldi-utils.cc:36

◆ Swap()

void Swap ( TokenHolder other)
inline

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

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

678  {
679  t_.swap(other->t_);
680  }

◆ Value()

T& Value ( )
inline

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

References KaldiObjectHolder< KaldiType >::t_.

674 { return t_; }

◆ Write()

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

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

References kaldi::IsToken(), and KALDI_ASSERT.

645  { // ignore binary-mode
646  KALDI_ASSERT(IsToken(t));
647  os << t << '\n';
648  return os.good();
649  }
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 690 of file kaldi-holder-inl.h.

Referenced by TokenHolder::Swap().


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