All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GenericHolder< SomeType > Class Template Reference

GenericHolder serves to document the requirements of the Holder interface; it's not intended to be used. More...

#include <kaldi-holder.h>

Collaboration diagram for GenericHolder< SomeType >:

Public Types

typedef SomeType T
 

Public Member Functions

 GenericHolder ()
 Must have a constructor that takes no arguments. More...
 
bool Read (std::istream &is)
 Reads into the holder. More...
 
const TValue () const
 Returns the value of the object held here. More...
 
void Clear ()
 The Clear() function doesn't have to do anything. More...
 
void Swap (GenericHolder< T > *other)
 This swaps the objects held by *this and *other (preferably a shallow swap). More...
 
bool ExtractRange (const GenericHolder< T > &other, const std::string &range)
 At the time of writing this will only do something meaningful KaldiObjectHolder holding matrix objects, in order to extract a holder holding a sub-matrix specified by 'range', e.g. More...
 
 ~GenericHolder ()
 If the object held pointers, the destructor would free them. More...
 

Static Public Member Functions

static bool Write (std::ostream &os, bool binary, const T &t)
 Write() writes this object of type T. More...
 
static bool IsReadInBinary ()
 IsReadInBinary() will return true if the object wants the file to be opened in binary for reading (if the file system has binary/text modes), and false otherwise. More...
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (GenericHolder)
 

Private Attributes

T t_
 

Detailed Description

template<class SomeType>
class kaldi::GenericHolder< SomeType >

GenericHolder serves to document the requirements of the Holder interface; it's not intended to be used.

Definition at line 82 of file kaldi-holder.h.

Member Typedef Documentation

typedef SomeType T

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

Constructor & Destructor Documentation

GenericHolder ( )
inline

Must have a constructor that takes no arguments.

Definition at line 87 of file kaldi-holder.h.

87 { }
~GenericHolder ( )
inline

If the object held pointers, the destructor would free them.

Definition at line 151 of file kaldi-holder.h.

151 { }

Member Function Documentation

void Clear ( )
inline

The Clear() function doesn't have to do anything.

Its purpose is to allow the object to free resources if they're no longer needed.

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

131 { }
bool ExtractRange ( const GenericHolder< T > &  other,
const std::string &  range 
)
inline

At the time of writing this will only do something meaningful KaldiObjectHolder holding matrix objects, in order to extract a holder holding a sub-matrix specified by 'range', e.g.

[0:3,2:10], like in Matlab but with zero-based indexing. It returns true with successful extraction of the range, false if the range was invalid or outside the bounds of the matrix. For other types of holder it just throws an error.

Definition at line 145 of file kaldi-holder.h.

References KALDI_ERR.

145  {
146  KALDI_ERR << "ExtractRange is not defined for this type of holder.";
147  return false;
148  }
#define KALDI_ERR
Definition: kaldi-error.h:127
static bool IsReadInBinary ( )
inlinestatic

IsReadInBinary() will return true if the object wants the file to be opened in binary for reading (if the file system has binary/text modes), and false otherwise.

Static function. Kaldi objects always return true as they always read in binary mode. Note that we must be able to read, in this mode, objects written in both text and binary mode by Write (which may mean ignoring "\r" characters). I doubt we will ever want this function to return false.

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

122 { return true; }
KALDI_DISALLOW_COPY_AND_ASSIGN ( GenericHolder< SomeType >  )
private
bool Read ( std::istream &  is)

Reads into the holder.

Must work out from the stream (which will be opened on Windows in binary mode if the IsReadInBinary() function of this class returns true, and text mode otherwise) whether the actual data is binary or not (usually via reading the Kaldi binary-mode header). We put the responsibility for reading the Kaldi binary-mode header in the Read function (rather than making the binary mode an argument to this function), so that for non-Kaldi binary files we don't have to write the header, which would prevent the file being read by non-Kaldi programs (e.g. if we write to individual files using an scp). Read must deallocate any existing data we have here, if applicable (must not assume the object was newly constructed). Returns true on success. If Read() returns false, the contents of this object and hence the value returned by Value() may be undefined.

void Swap ( GenericHolder< T > *  other)
inline

This swaps the objects held by *this and *other (preferably a shallow swap).

Note, this is just an example. The swap is with the *same type* of holder, not with some nonexistent base-class (remember, GenericHolder is an example for documentation, not a base-class).

Definition at line 137 of file kaldi-holder.h.

References kaldi::swap(), and GenericHolder< SomeType >::t_.

137 { std::swap(t_, other->t_); }
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
const T& Value ( ) const
inline

Returns the value of the object held here.

Will only ever be called if Read() has been previously called and it returned true (so OK to throw exception if no object was read).

Definition at line 127 of file kaldi-holder.h.

References GenericHolder< SomeType >::t_.

127 { return t_; } // if t is a pointer, would return *t_;
static bool Write ( std::ostream &  os,
bool  binary,
const T t 
)
static

Write() writes this object of type T.

Possibly also writes a binary-mode header so that the Read function knows which mode to read in (since the Read function does not get this information). It's a static member so we can write those not inside this class (can use this function with Value() to write from this class). The Write method may throw if it cannot write the object in the given (binary/non-binary) mode. The holder object can assume the stream has been opened in the given mode (where relevant). The object can write the data how it likes.

Member Data Documentation

T t_
private

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