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 754 of file kaldi-io.cc.

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

754  : impl_(NULL) {
755  if (!Open(rxfilename, binary)) {
756  KALDI_ERR << "Error opening input stream "
757  << PrintableRxfilename(rxfilename);
758  }
759 }
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:61
#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 823 of file kaldi-io.cc.

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

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

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 772 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().

774  {
775  InputType type = ClassifyRxfilename(rxfilename);
776  if (IsOpen()) {
777  // May have to close the stream first.
778  if (type == kOffsetFileInput && impl_->MyType() == kOffsetFileInput) {
779  // We want to use the same object to Open... this is in case
780  // the files are the same, so we can just seek.
781  if (!impl_->Open(rxfilename, file_binary)) { // true is binary mode--
782  // always open in binary.
783  delete impl_;
784  impl_ = NULL;
785  return false;
786  }
787  // read the binary header, if requested.
788  if (contents_binary != NULL)
789  return InitKaldiInputStream(impl_->Stream(), contents_binary);
790  else
791  return true;
792  } else {
793  Close();
794  // and fall through to code below which actually opens the file.
795  }
796  }
797  if (type == kFileInput) {
798  impl_ = new FileInputImpl();
799  } else if (type == kStandardInput) {
800  impl_ = new StandardInputImpl();
801  } else if (type == kPipeInput) {
802  impl_ = new PipeInputImpl();
803  } else if (type == kOffsetFileInput) {
804  impl_ = new OffsetFileInputImpl();
805  } else { // type == kNoInput
806  KALDI_WARN << "Invalid input filename format "<<
807  PrintableRxfilename(rxfilename);
808  return false;
809  }
810  if (!impl_->Open(rxfilename, file_binary)) { // true is binary mode--
811  // always read in binary.
812  delete impl_;
813  impl_ = NULL;
814  return false;
815  }
816  if (contents_binary != NULL)
817  return InitKaldiInputStream(impl_->Stream(), contents_binary);
818  else
819  return true;
820 }
InputType ClassifyRxfilename(const std::string &filename)
ClassifyRxfilenames interprets filenames for reading as follows:
Definition: kaldi-io.cc:138
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:61
virtual std::istream & Stream()=0
#define KALDI_WARN
Definition: kaldi-error.h:130
int32 Close()
Definition: kaldi-io.cc:761
InputType
Definition: kaldi-io.h:105
bool OpenTextMode ( const std::string &  rxfilename)
inline
std::istream & Stream ( )

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

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

Referenced by kaldi::BuildConstArpaLm(), kaldi::Compile(), 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(), kaldi::nnet3::ProcessRangeFile(), Nnet::Read(), fst::ReadFstKaldi(), fst::ReadFstKaldiGeneric(), kaldi::ReadIntegerVectorSimple(), kaldi::ReadIntegerVectorVectorSimple(), kaldi::ReadKaldiObject(), kaldi::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().

826  {
827  if (!IsOpen()) KALDI_ERR << "Input::Stream(), not open.";
828  return impl_->Stream();
829 }
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: