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() [1/2]

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
#define KALDI_ERR
Definition: kaldi-error.h:147
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

◆ Input() [2/2]

Input ( )
inline

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

References Output::Close(), Output::IsOpen(), Output::Open(), and Output::Stream().

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

◆ ~Input()

~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

◆ Close()

int32 Close ( )

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

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

Referenced by Nnet::Init(), LinearTransform::InitData(), Input::OpenInternal(), PdfPrior::PdfPrior(), Nnet::Read(), and Input::~Input().

761  {
762  if (impl_) {
763  int32 ans = impl_->Close();
764  delete impl_;
765  impl_ = NULL;
766  return ans;
767  } else {
768  return 0;
769  }
770 }
InputImplBase * impl_
Definition: kaldi-io.h:235
kaldi::int32 int32
virtual int32 Close()=0

◆ IsOpen()

bool IsOpen ( )
inline

Definition at line 34 of file kaldi-io-inl.h.

References Input::impl_.

Referenced by Input::OpenInternal(), and Input::Stream().

34  {
35  return impl_ != NULL;
36 }
InputImplBase * impl_
Definition: kaldi-io.h:235

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( Input  )
private

◆ Open()

bool Open ( const std::string &  rxfilename,
bool contents_binary = NULL 
)
inline

Definition at line 26 of file kaldi-io-inl.h.

References Input::OpenInternal().

Referenced by Input::Input(), NnetDiscriminativeTrainer::NnetDiscriminativeTrainer(), NnetTrainer::NnetTrainer(), and kaldi::ReadScriptFile().

26  {
27  return OpenInternal(rxfilename, true, binary);
28 }
bool OpenInternal(const std::string &rxfilename, bool file_binary, bool *contents_binary)
Definition: kaldi-io.cc:772

◆ OpenInternal()

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
virtual std::istream & Stream()=0
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 Close()
Definition: kaldi-io.cc:761
InputType
Definition: kaldi-io.h:105
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

◆ OpenTextMode()

bool OpenTextMode ( const std::string &  rxfilename)
inline

Definition at line 30 of file kaldi-io-inl.h.

References Input::OpenInternal().

Referenced by PdfPrior::PdfPrior(), kaldi::ReadIntegerVectorSimple(), and kaldi::ReadIntegerVectorVectorSimple().

30  {
31  return OpenInternal(rxfilename, false, NULL);
32 }
bool OpenInternal(const std::string &rxfilename, bool file_binary, bool *contents_binary)
Definition: kaldi-io.cc:772

◆ Stream()

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(), kaldi::GetUtterancePairs(), Nnet::Init(), kaldi::InitAmGmmFromOld(), LinearTransform::InitData(), FixedAffineComponent::InitFromConfig(), FixedLinearComponent::InitFromString(), FixedAffineComponent::InitFromString(), main(), NnetChainTrainer::NnetChainTrainer(), NnetDiscriminativeTrainer::NnetDiscriminativeTrainer(), NnetTrainer::NnetTrainer(), OnlineGmmDecodingModels::OnlineGmmDecodingModels(), PdfPrior::PdfPrior(), kaldi::PrepareMap(), kaldi::nnet3::ProcessRangeFile(), Nnet::Read(), kaldi::ReadDecodeGraph(), fst::ReadFstKaldi(), fst::ReadFstKaldiGeneric(), kaldi::ReadIntegerVectorSimple(), kaldi::ReadIntegerVectorVectorSimple(), kaldi::ReadKaldiObject(), kaldi::ReadNetwork(), 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:147

Member Data Documentation

◆ impl_


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