All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
KaldiObjectHolder< KaldiType > Singleton Reference

KaldiObjectHolder works for Kaldi objects that have the "standard" Read and Write functions, and a copy constructor. More...

#include <kaldi-holder-inl.h>

Collaboration diagram for KaldiObjectHolder< KaldiType >:

Public Types

typedef KaldiType T
 

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (KaldiObjectHolder)
 

Private Attributes

Tt_
 

Detailed Description

template<class KaldiType>
singleton kaldi::KaldiObjectHolder< KaldiType >

KaldiObjectHolder works for Kaldi objects that have the "standard" Read and Write functions, and a copy constructor.

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

Member Typedef Documentation

typedef KaldiType T

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

Constructor & Destructor Documentation

KaldiObjectHolder ( )
inline

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

47 : t_(NULL) { }
~KaldiObjectHolder ( )
inline

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

References KaldiObjectHolder< KaldiType >::t_.

113 { delete t_; }

Member Function Documentation

void Clear ( )
inline

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

References KaldiObjectHolder< KaldiType >::t_.

60  {
61  if (t_) {
62  delete t_;
63  t_ = NULL;
64  }
65  }
bool ExtractRange ( const KaldiObjectHolder< T > &  other,
const std::string &  range 
)
inline

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

References kaldi::ExtractObjectRange(), KALDI_ASSERT, and KaldiObjectHolder< KaldiType >::t_.

105  {
106  KALDI_ASSERT(other.t_ != NULL);
107  delete t_;
108  t_ = new T;
109  // this call will fail for most object types.
110  return ExtractObjectRange(*(other.t_), range, t_);
111  }
bool ExtractObjectRange(const Matrix< Real > &input, const std::string &range, Matrix< Real > *output)
The template is specialized with a version that actually does something, for types Matrix and ...
Definition: kaldi-holder.cc:27
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
static bool IsReadInBinary ( )
inlinestatic

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

91 { return true; }
KALDI_DISALLOW_COPY_AND_ASSIGN ( KaldiObjectHolder< KaldiType >  )
private
bool Read ( std::istream &  is)
inline

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

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

68  {
69  delete t_;
70  t_ = new T;
71  // Don't want any existing state to complicate the read function: get new
72  // object.
73  bool is_binary;
74  if (!InitKaldiInputStream(is, &is_binary)) {
75  KALDI_WARN << "Reading Table object, failed reading binary header\n";
76  return false;
77  }
78  try {
79  t_->Read(is, is_binary);
80  return true;
81  } catch(const std::exception &e) {
82  KALDI_WARN << "Exception caught reading Table object. " << e.what();
83  delete t_;
84  t_ = NULL;
85  return false;
86  }
87  }
bool InitKaldiInputStream(std::istream &is, bool *binary)
Initialize an opened stream for reading by detecting the binary header and.
Definition: io-funcs-inl.h:306
#define KALDI_WARN
Definition: kaldi-error.h:130
void Swap ( KaldiObjectHolder< T > *  other)
inline

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

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

99  {
100  // the t_ values are pointers so this is a shallow swap.
101  std::swap(t_, other->t_);
102  }
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
const T& Value ( ) const
inline

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

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

93  {
94  // code error if !t_.
95  if (!t_) KALDI_ERR << "KaldiObjectHolder::Value() called wrongly.";
96  return *t_;
97  }
#define KALDI_ERR
Definition: kaldi-error.h:127
static bool Write ( std::ostream &  os,
bool  binary,
const T t 
)
inlinestatic

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

References kaldi::InitKaldiOutputStream(), and KALDI_WARN.

49  {
50  InitKaldiOutputStream(os, binary); // Puts binary header if binary mode.
51  try {
52  t.Write(os, binary);
53  return os.good();
54  } catch(const std::exception &e) {
55  KALDI_WARN << "Exception caught writing Table object. " << e.what();
56  return false; // Write failure.
57  }
58  }
#define KALDI_WARN
Definition: kaldi-error.h:130
void InitKaldiOutputStream(std::ostream &os, bool binary)
InitKaldiOutputStream initializes an opened stream for writing by writing an optional binary header a...
Definition: io-funcs-inl.h:291

Member Data Documentation


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