SpectMorph
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SpectMorph::InFile Class Reference

Class to read SpectMorph binary data. More...

#include <sminfile.hh>

Public Types

enum  Event {
  NONE, END_OF_FILE, READ_ERROR, BEGIN_SECTION,
  END_SECTION, BOOL, INT, STRING,
  FLOAT, FLOAT_BLOCK, UINT16_BLOCK, BLOB,
  BLOB_REF
}
 

Public Member Functions

 InFile (const std::string &filename)
 
 InFile (GenericIn *file)
 
bool open_ok ()
 
Event event ()
 
std::string event_name ()
 
float event_float ()
 
int event_int ()
 
bool event_bool ()
 
std::string event_data ()
 
const std::vector< float > & event_float_block ()
 
const std::vector< uint16_t > & event_uint16_block ()
 
std::string event_blob_sum ()
 
void next_event ()
 
void add_skip_event (const std::string &event)
 
std::string file_type ()
 
int file_version ()
 
GenericInopen_blob ()
 

Protected Member Functions

bool read_raw_bool (bool &b)
 
bool read_raw_string (std::string &str)
 
bool read_raw_int (int &i)
 
bool read_raw_float (float &f)
 
bool read_raw_float_block (std::vector< float > &fb)
 
bool skip_raw_float_block ()
 
bool read_raw_uint16_block (std::vector< uint16_t > &ib)
 
bool skip_raw_uint16_block ()
 
void read_file_type_and_version ()
 

Protected Attributes

GenericInfile
 
bool file_delete
 
Event current_event
 
std::string current_event_str
 
bool current_event_bool
 
int current_event_int
 
std::string current_event_data
 
float current_event_float
 
std::vector< float > current_event_float_block
 
std::vector< uint16_t > current_event_uint16_block
 
size_t current_event_blob_pos
 
size_t current_event_blob_size
 
std::string current_event_blob_sum
 
std::string m_file_type
 
int m_file_version
 
std::set< std::string > skip_events
 

Detailed Description

Class to read SpectMorph binary data.

This class allows reading SpectMorph binary data from a file (with name) or from a GenericIn object; the files consist of events, which are read one by one until an error occurs or until EOF. The events are typed, end the event data should be queried according to the current event type.

Constructor & Destructor Documentation

InFile::InFile ( const std::string &  filename)

Create InFile object for reading a file.

Parameters
filenamename of the file
InFile::InFile ( GenericIn file)

Create InFile object for reading an input stream.

Parameters
filethe input stream object to read data from

Member Function Documentation

void InFile::add_skip_event ( const std::string &  event)

Add event names to skip (currently only implemented for FLOAT_BLOCK events); this speeds up reading files, while ignoring certain events.

Parameters
skip_eventname of the event to skip
InFile::Event InFile::event ( )

Get current event type.

Returns
current event type (or READ_ERROR or END_OF_FILE).
string InFile::event_blob_sum ( )

Get blob's checksum. This works for both: BLOB objects and BLOB_REF objects. During writing files, the first occurence of a BLOB is stored completely, whereas after that, only the blob sum is stored as BLOB_REF event. During loading, code for handling both needs to be supplied.

Returns
the blob's checksum
bool InFile::event_bool ( )

Get bool data of the current event (only if the event is BOOL).

Returns
current event bool data
string InFile::event_data ( )

Get string data of the current event (only if the event is STRING).

Returns
current event string data
float InFile::event_float ( )

Get float data of the current event (only if the event is a FLOAT).

Returns
current event float data.
const vector< float > & InFile::event_float_block ( )

Get float block data of the current event (only if the event is FLOAT_BLOCK).

Returns
current event float block data (by reference)
int InFile::event_int ( )

Get int data of the current event (only if the event is an INT).

Returns
current event int data
string InFile::event_name ( )

Get name of the current event.

Returns
current event name
const vector< uint16_t > & InFile::event_uint16_block ( )

Get uint16 block data of the current event (only if the event is UINT16_BLOCK).

Returns
current event uint16 block data (by reference)
string InFile::file_type ( )

Get file type (usually a class name, like "SpectMorph::WavSet").

Returns
file type
int InFile::file_version ( )

Get file version, an integer.

Returns
file version
void InFile::next_event ( )

Reads next event from file. Call event() to get event type, and event_*() to get event data.

GenericIn * InFile::open_blob ( )

This function will open the blob (it will only work for BLOB events, not BLOB_REF events) and the returned GenericIn object be used to read the content of the BLOB. The caller is responsible for freeing the GenericIn object when done. NULL will be returned on error.

bool SpectMorph::InFile::open_ok ( )
inline

Check if file open succeeded.

Returns
true if file was opened successfully, false otherwise

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