GenericHolder serves to document the requirements of the Holder interface; it's not intended to be used. More...
#include <kaldi-holder.h>
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... | |
T & | Value () |
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_ |
GenericHolder serves to document the requirements of the Holder interface; it's not intended to be used.
Definition at line 83 of file kaldi-holder.h.
typedef SomeType T |
Definition at line 85 of file kaldi-holder.h.
|
inline |
Must have a constructor that takes no arguments.
Definition at line 88 of file kaldi-holder.h.
References GenericHolder< SomeType >::Read(), and GenericHolder< SomeType >::Write().
|
inline |
If the object held pointers, the destructor would free them.
Definition at line 152 of file kaldi-holder.h.
References GenericHolder< SomeType >::KALDI_DISALLOW_COPY_AND_ASSIGN().
|
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 132 of file kaldi-holder.h.
|
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 146 of file kaldi-holder.h.
References KALDI_ERR.
|
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 123 of file kaldi-holder.h.
|
private |
Referenced by GenericHolder< SomeType >::~GenericHolder().
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.
Referenced by GenericHolder< SomeType >::GenericHolder().
|
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 138 of file kaldi-holder.h.
References kaldi::swap(), and GenericHolder< SomeType >::t_.
|
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 128 of file kaldi-holder.h.
References GenericHolder< SomeType >::t_.
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.
Referenced by GenericHolder< SomeType >::GenericHolder().
|
private |
Definition at line 156 of file kaldi-holder.h.
Referenced by GenericHolder< SomeType >::Swap(), and GenericHolder< SomeType >::Value().