All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Input Class Reference

#include <kaldi-io.h>

Collaboration diagram for Input:

Public Member Functions

 Input (const std::string &rxfilename, bool *contents_binary=NULL)
 The normal constructor. More...
 
 Input ()
 
bool Open (const std::string &rxfilename, bool *contents_binary=NULL)
 
bool OpenTextMode (const std::string &rxfilename)
 
bool IsOpen ()
 
int32 Close ()
 
std::istream & Stream ()
 
 ~Input ()
 

Private Member Functions

bool OpenInternal (const std::string &rxfilename, bool file_binary, bool *contents_binary)
 
 KALDI_DISALLOW_COPY_AND_ASSIGN (Input)
 

Private Attributes

InputImplBaseimpl_
 

Detailed Description

Definition at line 190 of file kaldi-io.h.

Constructor & Destructor Documentation

Input ( const std::string &  rxfilename,
bool *  contents_binary = NULL 
)

The normal constructor.

Opens the stream in binary mode. Equivalent to calling the default constructor followed by Open(); then, if binary != NULL, it calls ReadHeader(), putting the output in "binary"; it throws on error.

Definition at line 740 of file kaldi-io.cc.

References KALDI_ERR, Input::Open(), and kaldi::PrintableRxfilename().

740  : impl_(NULL) {
741  if (!Open(rxfilename, binary)) {
742  KALDI_ERR << "Error opening input stream "
743  << PrintableRxfilename(rxfilename);
744  }
745 }
InputImplBase * impl_
Definition: kaldi-io.h:235
bool Open(const std::string &rxfilename, bool *contents_binary=NULL)
Definition: kaldi-io-inl.h:26
std::string PrintableRxfilename(std::string rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:58
#define KALDI_ERR
Definition: kaldi-error.h:127
Input ( )
inline

Definition at line 198 of file kaldi-io.h.

198 : impl_(NULL) {}
InputImplBase * impl_
Definition: kaldi-io.h:235
~Input ( )

Definition at line 809 of file kaldi-io.cc.

References Input::Close(), and Input::impl_.

809 { if (impl_) Close(); }
InputImplBase * impl_
Definition: kaldi-io.h:235
int32 Close()
Definition: kaldi-io.cc:747

Member Function Documentation

KALDI_DISALLOW_COPY_AND_ASSIGN ( Input  )
private
bool Open ( const std::string &  rxfilename,
bool *  contents_binary = NULL 
)
inline
bool OpenInternal ( const std::string &  rxfilename,
bool  file_binary,
bool *  contents_binary 
)
private

Definition at line 758 of file kaldi-io.cc.

References kaldi::ClassifyRxfilename(), Input::Close(), Input::impl_, kaldi::InitKaldiInputStream(), Input::IsOpen(), KALDI_WARN, kaldi::kFileInput, kaldi::kOffsetFileInput, kaldi::kPipeInput, kaldi::kStandardInput, InputImplBase::MyType(), InputImplBase::Open(), kaldi::PrintableRxfilename(), and InputImplBase::Stream().

Referenced by Input::Open(), and Input::OpenTextMode().

760  {
761  InputType type = ClassifyRxfilename(rxfilename);
762  if (IsOpen()) {
763  // May have to close the stream first.
764  if (type == kOffsetFileInput && impl_->MyType() == kOffsetFileInput) {
765  // We want to use the same object to Open... this is in case
766  // the files are the same, so we can just seek.
767  if (!impl_->Open(rxfilename, file_binary)) { // true is binary mode--
768  // always open in binary.
769  delete impl_;
770  impl_ = NULL;
771  return false;
772  }
773  // read the binary header, if requested.
774  if (contents_binary != NULL)
775  return InitKaldiInputStream(impl_->Stream(), contents_binary);
776  else
777  return true;
778  } else {
779  Close();
780  // and fall through to code below which actually opens the file.
781  }
782  }
783  if (type == kFileInput) {
784  impl_ = new FileInputImpl();
785  } else if (type == kStandardInput) {
786  impl_ = new StandardInputImpl();
787  } else if (type == kPipeInput) {
788  impl_ = new PipeInputImpl();
789  } else if (type == kOffsetFileInput) {
790  impl_ = new OffsetFileInputImpl();
791  } else { // type == kNoInput
792  KALDI_WARN << "Invalid input filename format "<<
793  PrintableRxfilename(rxfilename);
794  return false;
795  }
796  if (!impl_->Open(rxfilename, file_binary)) { // true is binary mode--
797  // always read in binary.
798  delete impl_;
799  impl_ = NULL;
800  return false;
801  }
802  if (contents_binary != NULL)
803  return InitKaldiInputStream(impl_->Stream(), contents_binary);
804  else
805  return true;
806 }
InputType ClassifyRxfilename(const std::string &filename)
ClassifyRxfilenames interprets filenames for reading as follows:
Definition: kaldi-io.cc:130
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
virtual bool Open(const std::string &filename, bool binary)=0
bool IsOpen()
Definition: kaldi-io-inl.h:34
InputImplBase * impl_
Definition: kaldi-io.h:235
virtual InputType MyType()=0
std::string PrintableRxfilename(std::string rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:58
virtual std::istream & Stream()=0
#define KALDI_WARN
Definition: kaldi-error.h:130
int32 Close()
Definition: kaldi-io.cc:747
InputType
Definition: kaldi-io.h:105
bool OpenTextMode ( const std::string &  rxfilename)
inline
std::istream & Stream ( )

Definition at line 812 of file kaldi-io.cc.

References Input::impl_, Input::IsOpen(), KALDI_ERR, and InputImplBase::Stream().

Referenced by CopyExcludedFeats(), CopyIncludedFeats(), kaldi::CopySubsetLattices(), SequentialTableReaderScriptImpl< Holder >::EnsureObjectLoaded(), kaldi::GetUtterancePairs(), RandomAccessTableReaderScriptImpl< Holder >::HasKeyInternal(), Nnet::Init(), kaldi::InitAmGmmFromOld(), LinearTransform::InitData(), FixedAffineComponent::InitFromConfig(), FixedLinearComponent::InitFromString(), FixedAffineComponent::InitFromString(), main(), SequentialTableReaderArchiveImpl< Holder >::Next(), SequentialTableReaderScriptImpl< Holder >::NextScpLine(), NnetChainTrainer::NnetChainTrainer(), NnetDiscriminativeTrainer::NnetDiscriminativeTrainer(), NnetTrainer::NnetTrainer(), PdfPrior::PdfPrior(), kaldi::PrepareMap(), Nnet::Read(), fst::ReadFstKaldi(), kaldi::ReadIntegerVectorSimple(), kaldi::ReadIntegerVectorVectorSimple(), kaldi::ReadKaldiObject(), kaldi::ReadNetwork(), ReadNetwork(), RandomAccessTableReaderArchiveImplBase< Holder >::ReadNextObject(), kaldi::ReadScriptFile(), kaldi::ReadSharedPhonesList(), kaldi::ReadSymbolList(), test_io(), TestAmDiagGmmAccsIO(), TestAmDiagGmmIO(), kaldi::TestBuildTreeStatsIo(), fst::TestContextFst(), kaldi::TestEventTypeIo(), kaldi::TestFmpe(), kaldi::TestGenRandContextDependency(), TestMllrAccsIO(), kaldi::TestSetOfNumbers(), TestSgmm2AccsIO(), TestSgmm2FmllrAccsIO(), TestSgmm2IO(), kaldi::UnitTestDiagGmm(), UnitTestEstimateDiagGmm(), UnitTestFullGmm(), kaldi::nnet2::UnitTestGenericComponentInternal(), kaldi::UnitTestIoNew(), kaldi::UnitTestIoPipe(), kaldi::UnitTestRangesMatrix(), kaldi::UnitTestRegtreeFmllrDiagGmm(), and WordBoundaryInfo::WordBoundaryInfo().

812  {
813  if (!IsOpen()) KALDI_ERR << "Input::Stream(), not open.";
814  return impl_->Stream();
815 }
bool IsOpen()
Definition: kaldi-io-inl.h:34
InputImplBase * impl_
Definition: kaldi-io.h:235
virtual std::istream & Stream()=0
#define KALDI_ERR
Definition: kaldi-error.h:127

Member Data Documentation

InputImplBase* impl_
private

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