RandomAccessTableReaderArchiveImplBase< Holder > Class Template Reference

#include <kaldi-table-inl.h>

Inheritance diagram for RandomAccessTableReaderArchiveImplBase< Holder >:
Collaboration diagram for RandomAccessTableReaderArchiveImplBase< Holder >:

Public Types

typedef Holder::T T
 
- Public Types inherited from RandomAccessTableReaderImplBase< Holder >
typedef Holder::T T
 

Public Member Functions

 RandomAccessTableReaderArchiveImplBase ()
 
virtual bool Open (const std::string &rspecifier)
 
void ReadNextObject ()
 
virtual bool IsOpen () const
 
bool CloseInternal ()
 
 ~RandomAccessTableReaderArchiveImplBase ()
 
- Public Member Functions inherited from RandomAccessTableReaderImplBase< Holder >
virtual bool HasKey (const std::string &key)=0
 
virtual const TValue (const std::string &key)=0
 
virtual bool Close ()=0
 
virtual ~RandomAccessTableReaderImplBase ()
 

Protected Types

enum  {
  kUninitialized, kNoObject, kHaveObject, kEof,
  kError
}
 

Protected Attributes

std::string cur_key_
 
Holder * holder_
 
std::string rspecifier_
 
std::string archive_rxfilename_
 
RspecifierOptions opts_
 
enum kaldi::RandomAccessTableReaderArchiveImplBase:: { ... }  state_
 

Private Attributes

Input input_
 

Detailed Description

template<class Holder>
class kaldi::RandomAccessTableReaderArchiveImplBase< Holder >

Definition at line 1895 of file kaldi-table-inl.h.

Member Typedef Documentation

◆ T

typedef Holder::T T

Definition at line 1898 of file kaldi-table-inl.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
kUninitialized 
kNoObject 
kHaveObject 
kEof 
kError 

Definition at line 2031 of file kaldi-table-inl.h.

2031  { // [The state of the reading process] [does holder_ [is input_
2032  // have object] open]
2033  kUninitialized, // Uninitialized or closed no no
2034  kNoObject, // Do not have object in holder_ no yes
2035  kHaveObject, // Have object in holder_ yes yes
2036  kEof, // End of file no yes
2037  kError, // Some kind of error-state in the reading. no yes
2038  } state_;
enum kaldi::RandomAccessTableReaderArchiveImplBase::@5 state_

Constructor & Destructor Documentation

◆ RandomAccessTableReaderArchiveImplBase()

◆ ~RandomAccessTableReaderArchiveImplBase()

Definition at line 2015 of file kaldi-table-inl.h.

References KALDI_ASSERT.

2015  {
2016  // The child class has the responsibility to call CloseInternal().
2017  KALDI_ASSERT(state_ == kUninitialized && holder_ == NULL);
2018  }
enum kaldi::RandomAccessTableReaderArchiveImplBase::@5 state_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

Member Function Documentation

◆ CloseInternal()

bool CloseInternal ( )
inline

Definition at line 1993 of file kaldi-table-inl.h.

References TableWriter< Holder >::IsOpen(), KALDI_ASSERT, KALDI_ERR, and KALDI_WARN.

1993  {
1994  if (!this->IsOpen())
1995  KALDI_ERR << "Close() called on TableReader twice or otherwise wrongly.";
1996  if (input_.IsOpen())
1997  input_.Close();
1998  if (state_ == kHaveObject) {
1999  KALDI_ASSERT(holder_ != NULL);
2000  delete holder_;
2001  holder_ = NULL;
2002  } else {
2003  KALDI_ASSERT(holder_ == NULL);
2004  }
2005  bool ans = (state_ != kError);
2007  if (!ans && opts_.permissive) {
2008  KALDI_WARN << "Error state detected closing reader. "
2009  << "Ignoring it because you specified permissive mode.";
2010  return true;
2011  }
2012  return ans;
2013  }
bool IsOpen()
Definition: kaldi-io-inl.h:34
enum kaldi::RandomAccessTableReaderArchiveImplBase::@5 state_
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 Close()
Definition: kaldi-io.cc:761
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ IsOpen()

virtual bool IsOpen ( ) const
inlinevirtual

Definition at line 1982 of file kaldi-table-inl.h.

References KALDI_ERR.

1982  {
1983  switch (state_) {
1984  case kEof: case kError: case kHaveObject: case kNoObject: return true;
1985  case kUninitialized: return false;
1986  default: KALDI_ERR << "IsOpen() called on invalid object.";
1987  return false;
1988  }
1989  }
enum kaldi::RandomAccessTableReaderArchiveImplBase::@5 state_
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ Open()

virtual bool Open ( const std::string &  rspecifier)
inlinevirtual

Implements RandomAccessTableReaderImplBase< Holder >.

Definition at line 1903 of file kaldi-table-inl.h.

References kaldi::ClassifyRspecifier(), TableWriter< Holder >::Close(), KALDI_ASSERT, KALDI_ERR, KALDI_WARN, kaldi::kArchiveRspecifier, and kaldi::PrintableRxfilename().

1903  {
1904  if (state_ != kUninitialized) {
1905  if (!this->Close()) // call Close() yourself to suppress this exception.
1906  KALDI_ERR << "Error closing previous input.";
1907  }
1908  rspecifier_ = rspecifier;
1910  &opts_);
1912 
1913  // NULL means don't expect binary-mode header
1914  bool ans;
1915  if (Holder::IsReadInBinary())
1916  ans = input_.Open(archive_rxfilename_, NULL);
1917  else
1919  if (!ans) { // header.
1920  KALDI_WARN << "Failed to open stream "
1922  state_ = kUninitialized; // Failure on Open
1923  return false; // User should print the error message.
1924  } else {
1925  state_ = kNoObject;
1926  }
1927  return true;
1928  }
bool Open(const std::string &rxfilename, bool *contents_binary=NULL)
Definition: kaldi-io-inl.h:26
bool OpenTextMode(const std::string &rxfilename)
Definition: kaldi-io-inl.h:30
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
enum kaldi::RandomAccessTableReaderArchiveImplBase::@5 state_
RspecifierType
Definition: kaldi-table.h:219
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:61

◆ ReadNextObject()

void ReadNextObject ( )
inline

Definition at line 1935 of file kaldi-table-inl.h.

References kaldi::CharToString(), KALDI_ERR, KALDI_WARN, and kaldi::PrintableRxfilename().

1935  {
1936  if (state_ != kNoObject)
1937  KALDI_ERR << "ReadNextObject() called from wrong state.";
1938  // Code error somewhere in this class or a child class.
1939  std::istream &is = input_.Stream();
1940  is.clear(); // Clear any fail bits that may have been set... just in case
1941  // this happened in the Read function.
1942  is >> cur_key_; // This eats up any leading whitespace and gets the string.
1943  if (is.eof()) {
1944  state_ = kEof;
1945  return;
1946  }
1947  if (is.fail()) { // This shouldn't really happen, barring file-system
1948  // errors.
1949  KALDI_WARN << "Error reading archive: rspecifier is " << rspecifier_;
1950  state_ = kError;
1951  return;
1952  }
1953  int c;
1954  if ((c = is.peek()) != ' ' && c != '\t' && c != '\n') { // We expect a
1955  // space ' ' after the key.
1956  // We also allow tab, just so we can read archives generated by scripts
1957  // that may not be fully aware of how this format works.
1958  KALDI_WARN << "Invalid archive file format: expected space after key "
1959  <<cur_key_
1960  <<", got character "
1961  << CharToString(static_cast<char>(is.peek()))
1962  << ", reading archive "
1964  state_ = kError;
1965  return;
1966  }
1967  if (c != '\n') is.get(); // Consume the space or tab.
1968  holder_ = new Holder;
1969  if (holder_->Read(is)) {
1970  state_ = kHaveObject;
1971  return;
1972  } else {
1973  KALDI_WARN << "Object read failed, reading archive "
1975  state_ = kError;
1976  delete holder_;
1977  holder_ = NULL;
1978  return;
1979  }
1980  }
enum kaldi::RandomAccessTableReaderArchiveImplBase::@5 state_
std::istream & Stream()
Definition: kaldi-io.cc:826
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
std::string CharToString(const char &c)
Definition: kaldi-utils.cc:36
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:61

Member Data Documentation

◆ archive_rxfilename_

std::string archive_rxfilename_
protected

Definition at line 2028 of file kaldi-table-inl.h.

◆ cur_key_

std::string cur_key_
protected

Definition at line 2024 of file kaldi-table-inl.h.

◆ holder_

Holder* holder_
protected

Definition at line 2025 of file kaldi-table-inl.h.

◆ input_

Input input_
private

Definition at line 2020 of file kaldi-table-inl.h.

◆ opts_

RspecifierOptions opts_
protected

Definition at line 2029 of file kaldi-table-inl.h.

◆ rspecifier_

std::string rspecifier_
protected

Definition at line 2027 of file kaldi-table-inl.h.

◆ state_

enum { ... } state_

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