RandomAccessTableReaderDSortedArchiveImpl< Holder > Class Template Reference

#include <kaldi-table-inl.h>

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

Public Types

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

Public Member Functions

 RandomAccessTableReaderDSortedArchiveImpl ()
 
virtual bool Close ()
 
virtual bool HasKey (const std::string &key)
 
virtual const TValue (const std::string &key)
 
virtual ~RandomAccessTableReaderDSortedArchiveImpl ()
 
- Public Member Functions inherited from RandomAccessTableReaderArchiveImplBase< Holder >
 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 ~RandomAccessTableReaderImplBase ()
 

Private Member Functions

bool FindKeyInternal (const std::string &key)
 

Private Attributes

std::string last_requested_key_
 Last string provided to HasKey() or Value();. More...
 

Additional Inherited Members

- Protected Types inherited from RandomAccessTableReaderArchiveImplBase< Holder >
enum  {
  kUninitialized, kNoObject, kHaveObject, kEof,
  kError
}
 
- Protected Attributes inherited from RandomAccessTableReaderArchiveImplBase< Holder >
std::string cur_key_
 
Holder * holder_
 
std::string rspecifier_
 
std::string archive_rxfilename_
 
RspecifierOptions opts_
 
enum kaldi::RandomAccessTableReaderArchiveImplBase:: { ... }  state_
 

Detailed Description

template<class Holder>
class kaldi::RandomAccessTableReaderDSortedArchiveImpl< Holder >

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

Member Typedef Documentation

◆ T

typedef Holder::T T

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

Constructor & Destructor Documentation

◆ RandomAccessTableReaderDSortedArchiveImpl()

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

2068 { }

◆ ~RandomAccessTableReaderDSortedArchiveImpl()

virtual ~RandomAccessTableReaderDSortedArchiveImpl ( )
inlinevirtual

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

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

2089  {
2090  if (this->IsOpen())
2091  if (!Close()) // more specific warning will already have been printed.
2092  // we are in some kind of error state & user did not find out by
2093  // calling Close().
2094  KALDI_ERR << "Error closing RandomAccessTableReader: rspecifier is "
2095  << rspecifier_;
2096  }
#define KALDI_ERR
Definition: kaldi-error.h:147

Member Function Documentation

◆ Close()

virtual bool Close ( )
inlinevirtual

Implements RandomAccessTableReaderImplBase< Holder >.

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

2070  {
2071  // We don't have anything additional to clean up, so just
2072  // call generic base-class one.
2073  return this->CloseInternal();
2074  }

◆ FindKeyInternal()

bool FindKeyInternal ( const std::string &  key)
inlineprivate

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

References KALDI_ASSERT, and KALDI_ERR.

2101  {
2102  // First check that the user is calling us right: should be
2103  // in sorted order. If not, error.
2104  if (!last_requested_key_.empty()) {
2105  if (key.compare(last_requested_key_) < 0) { // key < last_requested_key_
2106  KALDI_ERR << "You provided the \"cs\" option "
2107  << "but are not calling with keys in sorted order: "
2108  << key << " < " << last_requested_key_ << ": rspecifier is "
2109  << rspecifier_;
2110  }
2111  }
2112  // last_requested_key_ is just for debugging of order of calling.
2113  last_requested_key_ = key;
2114 
2115  if (state_ == kNoObject)
2116  ReadNextObject(); // This can only happen
2117  // once, the first time someone calls HasKey() or Value(). We don't
2118  // do it in the initializer to stop the program hanging too soon,
2119  // if reading from a pipe.
2120 
2121  if (state_ == kEof || state_ == kError) return false;
2122 
2123  if (state_ == kUninitialized)
2124  KALDI_ERR << "Trying to access a RandomAccessTableReader object that is"
2125  " not open.";
2126 
2127  std::string last_key_; // To check that
2128  // the archive we're reading is in sorted order.
2129  while (1) {
2131  int compare = key.compare(cur_key_);
2132  if (compare == 0) { // key == key_
2133  return true; // we got it..
2134  } else if (compare < 0) { // key < cur_key_, so we already read past the
2135  // place where we want to be. This implies that we will never find it
2136  // [due to the sorting etc., this means it just isn't in the archive].
2137  return false;
2138  } else { // compare > 0, key > cur_key_. We need to read further ahead.
2139  last_key_ = cur_key_;
2140  // read next object.. we have to set state to kNoObject first.
2141  KALDI_ASSERT(holder_ != NULL);
2142  delete holder_;
2143  holder_ = NULL;
2144  state_ = kNoObject;
2145  ReadNextObject();
2146  if (state_ != kHaveObject)
2147  return false; // eof or read error.
2148  if (cur_key_.compare(last_key_) <= 0) {
2149  KALDI_ERR << "You provided the \"s\" option "
2150  << " (sorted order), but keys are out of order or"
2151  " duplicated: "
2152  << last_key_ << " is followed by " << cur_key_
2153  << ": rspecifier is " << rspecifier_;
2154  }
2155  }
2156  }
2157  }
enum kaldi::RandomAccessTableReaderArchiveImplBase::@5 state_
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
std::string last_requested_key_
Last string provided to HasKey() or Value();.

◆ HasKey()

virtual bool HasKey ( const std::string &  key)
inlinevirtual

Implements RandomAccessTableReaderImplBase< Holder >.

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

2076  {
2077  return FindKeyInternal(key);
2078  }

◆ Value()

virtual const T& Value ( const std::string &  key)
inlinevirtual

Implements RandomAccessTableReaderImplBase< Holder >.

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

References KALDI_ASSERT, KALDI_ERR, and kaldi::PrintableRxfilename().

2079  {
2080  if (!FindKeyInternal(key)) {
2081  KALDI_ERR << "Value() called but no such key " << key
2082  << " in archive " << PrintableRxfilename(archive_rxfilename_);
2083  }
2084  KALDI_ASSERT(this->state_ == kHaveObject && key == this->cur_key_
2085  && holder_ != NULL);
2086  return this->holder_->Value();
2087  }
enum kaldi::RandomAccessTableReaderArchiveImplBase::@5 state_
#define KALDI_ERR
Definition: kaldi-error.h:147
#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

Member Data Documentation

◆ last_requested_key_

std::string last_requested_key_
private

Last string provided to HasKey() or Value();.

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


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