STIR  6.2.0
Public Types | Public Member Functions | List of all members
stir::InputStreamWithRecords< RecordT, OptionsT > Class Template Reference

A helper class to read data from a (presumably binary) stream. More...

#include "stir/IO/InputStreamWithRecords.h"

Public Types

typedef std::vector< std::streampos >::size_type SavedPosition
 

Public Member Functions

 InputStreamWithRecords (const shared_ptr< std::istream > &stream_ptr, const std::size_t size_of_record_signature, const std::size_t max_size_of_record, const OptionsT &options)
 Constructor taking a stream. More...
 
 InputStreamWithRecords (const std::string &filename, const std::size_t size_of_record_signature, const std::size_t max_size_of_record, const OptionsT &options, const std::streampos start_of_data=0)
 Constructor taking a filename. More...
 
virtual Succeeded get_next_record (RecordT &record) const
 
Succeeded reset ()
 go back to starting position
 
SavedPosition save_get_position ()
 save current "get" position in an internal array More...
 
Succeeded set_get_position (const SavedPosition &)
 set current "get" position to previously saved value
 
std::vector< std::streampos > get_saved_get_positions () const
 Function that enables the user to store the saved get_positions. More...
 
void set_saved_get_positions (const std::vector< std::streampos > &)
 Function that sets the saved get_positions. More...
 
std::istream & get_stream ()
 

Detailed Description

template<class RecordT, class OptionsT>
class stir::InputStreamWithRecords< RecordT, OptionsT >

A helper class to read data from a (presumably binary) stream.

This class is really a helper class for reading different records from a stream. It is useful when all types of records have some kind of signature to allow the function to find out what the size of the record is. In that case, all IO handling is completely generic and is implemented in this class.

Current implementation needs a max_size_of_record to allocate enough memory (on the stack) before reading. This is efficient in many cases, but impractical in others.

Requirements
RecordT needs to have the following member functions
std::size_t
size_of_record_at_ptr(const char * const buffer, const std::size_t size_available_in_buffer,
const OptionsT options) const;
Succeeded
init_from_data_ptr(const char * const buffer,
const std::size_t size_of_record,
const OptionsT options);
Todo:
Allow choosing between allocation with new or on the stack.

Constructor & Destructor Documentation

◆ InputStreamWithRecords() [1/2]

template<class RecordT , class OptionsT>
stir::InputStreamWithRecords< RecordT, OptionsT >::InputStreamWithRecords ( const shared_ptr< std::istream > &  stream_ptr,
const std::size_t  size_of_record_signature,
const std::size_t  max_size_of_record,
const OptionsT &  options 
)
inline

Constructor taking a stream.

Data will be assumed to start at the current position reported by seekg(). If reset() is used, it will go back to this starting position.

References stir::error().

◆ InputStreamWithRecords() [2/2]

template<class RecordT , class OptionsT>
stir::InputStreamWithRecords< RecordT, OptionsT >::InputStreamWithRecords ( const std::string &  filename,
const std::size_t  size_of_record_signature,
const std::size_t  max_size_of_record,
const OptionsT &  options,
const std::streampos  start_of_data = 0 
)
inline

Constructor taking a filename.

File will be opened in binary mode. Data will be assumed to start at start_of_data.

References stir::error(), stir::open_read_binary(), stir::InputStreamWithRecords< RecordT, OptionsT >::reset(), and stir::warning().

Member Function Documentation

◆ save_get_position()

template<class RecordT , class OptionsT >
InputStreamWithRecords< RecordT, OptionsT >::SavedPosition stir::InputStreamWithRecords< RecordT, OptionsT >::save_get_position ( )
inline

save current "get" position in an internal array

Returns
an "index" into the array that allows you to go back.
See also
set_get_position

References stir::error().

◆ get_saved_get_positions()

template<class RecordT , class OptionsT >
std::vector< std::streampos > stir::InputStreamWithRecords< RecordT, OptionsT >::get_saved_get_positions ( ) const
inline

Function that enables the user to store the saved get_positions.

Together with set_saved_get_positions(), this allows reinstating the saved get_positions when reopening the same stream.

◆ set_saved_get_positions()

template<class RecordT , class OptionsT >
void stir::InputStreamWithRecords< RecordT, OptionsT >::set_saved_get_positions ( const std::vector< std::streampos > &  poss)
inline

Function that sets the saved get_positions.

Normally, the argument results from a call to get_saved_get_positions() on the same stream.

Warning
There is no check if the argument actually makes sense for the current stream.

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