HFST - Helsinki Finite-State Transducer Technology - C++ API  version 3.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
HfstInputStream Class Reference

A stream for reading HFST binary transducers. More...

#include <HfstInputStream.h>

Public Member Functions

HFSTDLL void close (void)
 Close the stream. More...
 
HFSTDLL ImplementationType get_type (void) const
 The type of the first transducer in the stream. More...
 
HFSTDLL HfstInputStream (void)
 Create a stream to standard input for reading binary transducers. More...
 
HFSTDLL HfstInputStream (const std::string &filename)
 Open a stream to file filename for reading binary transducers. More...
 
HFSTDLL bool is_bad (void)
 Whether badbit is set. More...
 
HFSTDLL bool is_eof (void)
 Whether the stream is at end. More...
 
HFSTDLL bool is_good (void)
 Whether the state of the stream is good for input operations. More...
 
HFSTDLL ~HfstInputStream (void)
 Destructor. More...
 

Detailed Description

A stream for reading HFST binary transducers.

An example:

#include "HfstInputStream.h"

...

HfstInputStream *in = NULL;

try 
{
  in = new HfstInputStream("testfile");
} 
catch (StreamNotReadableException e) 
{
    std::cerr << "ERROR: File does not exist." << std::endl;
    exit(1);
}

int transducers_read = 0;

while (not in->is_eof()) 
{
  if (in->is_bad()) 
  {
  std::cerr << "ERROR: Stream cannot be read." << std::endl;
  exit(1); 
  }
  HfstTransducer t(*in);
  std::cerr << "One transducer successfully read." << std::endl;
  transducers_read++;
}

std::cerr << "Read " 
          << transducers_read 
          << " transducers in total."
      << std::endl;
in->close();
delete in;

For documentation on the HFST binary transducer format, see here.

  @see HfstTransducer::HfstTransducer(HfstInputStream &in)  

Constructor & Destructor Documentation

HfstInputStream ( void  )

Create a stream to standard input for reading binary transducers.

Exceptions
StreamNotReadableException
NotTransducerStreamException
EndOfStreamException
TransducerHeaderException
HfstInputStream ( const std::string &  filename)

Open a stream to file filename for reading binary transducers.

Precondition
The file exists. Otherwise, a StreamNotReadableException is thrown.
@throws StreamNotReadableException 
@throws NotTransducerStreamException
@throws EndOfStreamException
@throws TransducerHeaderException
~HfstInputStream ( void  )

Destructor.

Member Function Documentation

void close ( void  )

Close the stream.

If the stream points to standard input, nothing is done.

ImplementationType get_type ( void  ) const

The type of the first transducer in the stream.

By default, all transducers in a stream have the same type, else a TransducerTypeMismatchException is thrown when reading the first transducer that has a different type than the previous ones.

bool is_bad ( void  )

Whether badbit is set.

bool is_eof ( void  )

Whether the stream is at end.

bool is_good ( void  )

Whether the state of the stream is good for input operations.


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