soma-io  5.1.2
soma::Reader< T > Class Template Reference

Generic reader for every format of Cartograph object. More...

#include <soma-io/io/reader.h>

Collaboration diagram for soma::Reader< T >:

Public Member Functions

 Reader ()
 
 Reader (const std::string &filename)
 
 Reader (carto::rc_ptr< DataSource > ds)
 
 Reader (carto::rc_ptr< DataSourceInfo > dsi)
 
 Reader (std::istream &stream)
 
virtual ~Reader ()
 
virtual bool read (T &obj, carto::Object header=carto::none(), int passbegin=1, int passend=4)
 Finds the correct format and reads the object. More...
 
virtual T * read (carto::Object header=carto::none(), int passbegin=1, int passend=4)
 Creates and reads an object. More...
 
const carto::rc_ptr< DataSourceInfo > & dataSourceInfo () const
 
carto::rc_ptr< DataSourceInfo > & dataSourceInfo ()
 
void setAllocatorContext (const AllocatorContext &ac)
 
const AllocatorContextallocatorContext () const
 
void setOptions (carto::Object options)
 
carto::Object options () const
 
carto::Objectoptions ()
 
const carto::rc_ptr< DataSourcedataSource () const
 
carto::rc_ptr< DataSourcedataSource ()
 
void attach (carto::rc_ptr< DataSource > ds)
 
void attach (const std::string &filename, offset_t offset=0)
 
void attach (std::istream &stream)
 
void flush ()
 
void close ()
 

Static Public Member Functions

static std::string extension (const std::string &filename)
 

Protected Attributes

carto::rc_ptr< DataSourceInfo_datasourceinfo
 
AllocatorContext _alloccontext
 
carto::Object _options
 

Detailed Description

template<typename T>
class soma::Reader< T >

Generic reader for every format of Cartograph object.

Still a template class, the data type must be switched at upper-level (see DataSourceInfoLoader or ReaderAlgorithm).
Generic readers offer a plug-in mechanism to allow new formats to be registered.
It uses at lower level specific readers of each object type (Volume, Meshes, Buckets, Textures) and even lower, specific reader of each format (GIS, SPM).

See IO system general explanations on how to use Reader and Writer classes.

Adding new readers

The standard cartodata library includes a set of already compiled formats, using a FormatDictionary to provide a common link between Reader and Writer, see FormatDictionary for a list.

If you need to use other types, you'll have to include soma-io/io/reader_d.h in order to have the template functions definitions, soma-io/io/reader.h is only the class declarations. In addition, you may want to specialize the registerBaseFormats() functions of the FormatDictionary classes.

See also
FormatDictionary Writer DataSourceInfo ReaderAlgorithm

Definition at line 75 of file reader.h.

Constructor & Destructor Documentation

◆ Reader() [1/5]

template<class T >
soma::Reader< T >::Reader

Definition at line 70 of file reader_d.h.

◆ Reader() [2/5]

template<class T >
soma::Reader< T >::Reader ( const std::string &  filename)

Definition at line 85 of file reader_d.h.

◆ Reader() [3/5]

template<class T >
soma::Reader< T >::Reader ( carto::rc_ptr< DataSource ds)

Definition at line 75 of file reader_d.h.

◆ Reader() [4/5]

template<class T >
soma::Reader< T >::Reader ( carto::rc_ptr< DataSourceInfo dsi)

Definition at line 80 of file reader_d.h.

◆ Reader() [5/5]

template<class T >
soma::Reader< T >::Reader ( std::istream &  stream)

Definition at line 92 of file reader_d.h.

◆ ~Reader()

template<class T >
soma::Reader< T >::~Reader
virtual

Definition at line 99 of file reader_d.h.

Member Function Documentation

◆ allocatorContext()

template<typename T >
const AllocatorContext & soma::Reader< T >::allocatorContext

Definition at line 113 of file reader_d.h.

◆ attach() [1/3]

template<class T >
void soma::Reader< T >::attach ( carto::rc_ptr< DataSource ds)

Definition at line 143 of file reader_d.h.

◆ attach() [2/3]

template<class T >
void soma::Reader< T >::attach ( const std::string &  filename,
offset_t  offset = 0 
)

Definition at line 153 of file reader_d.h.

◆ attach() [3/3]

template<class T >
void soma::Reader< T >::attach ( std::istream &  stream)

Definition at line 165 of file reader_d.h.

◆ close()

template<typename T >
void soma::Reader< T >::close ( void  )

Definition at line 205 of file reader_d.h.

◆ dataSource() [1/2]

template<class T >
carto::rc_ptr< DataSource > soma::Reader< T >::dataSource

Definition at line 187 of file reader_d.h.

References soma::DataSource::none().

◆ dataSource() [2/2]

template<class T >
const carto::rc_ptr< DataSource > soma::Reader< T >::dataSource

Definition at line 177 of file reader_d.h.

References soma::DataSource::none().

◆ dataSourceInfo() [1/2]

template<typename T >
carto::rc_ptr<DataSourceInfo>& soma::Reader< T >::dataSourceInfo ( )
inline

Definition at line 126 of file reader.h.

References soma::Reader< T >::_datasourceinfo.

◆ dataSourceInfo() [2/2]

template<typename T >
const carto::rc_ptr<DataSourceInfo>& soma::Reader< T >::dataSourceInfo ( ) const
inline

Definition at line 124 of file reader.h.

References soma::Reader< T >::_datasourceinfo.

◆ extension()

template<typename T >
static std::string soma::Reader< T >::extension ( const std::string &  filename)
static

◆ flush()

template<typename T >
void soma::Reader< T >::flush

Definition at line 197 of file reader_d.h.

◆ options() [1/2]

template<class T >
carto::Object & soma::Reader< T >::options

Definition at line 134 of file reader_d.h.

◆ options() [2/2]

template<class T >
carto::Object soma::Reader< T >::options

Definition at line 128 of file reader_d.h.

◆ read() [1/2]

template<class T >
T * soma::Reader< T >::read ( carto::Object  header = carto::none(),
int  passbegin = 1,
int  passend = 4 
)
virtual

Creates and reads an object.

This function differs from the read( T&, ... ) function in the way that it creates the object and does not just fill it. This enables to create sub-classes of T (factory-like behaviour) on types that allow subclasses. The object is created by new and can be deleted. The default is just to create a T and call the read( T&, ... ) function, but some specialized low-level readers may behave differently. It is possible to specify which passes to process through passbegin and passend.

  • pass 1 : format hint
  • pass 2 : extension
  • pass 3 : empty extension
  • pass 4 : all readers

Definition at line 427 of file reader_d.h.

References soma::DataSourceInfoLoader::check(), soma::FormatReader< T >::clone(), soma::DataSourceList::empty(), carto::FileUtil::extension(), rc_ptr< GenericObject >::get(), soma::DataSourceInfo::header(), carto::Object::isNone(), carto::io_error::keepExceptionPriority(), carto::io_error::launchExcept(), soma::DataSourceInfoLoader::launchException(), soma::DataSourceInfo::list(), localMsg, soma::FormatDictionary< T >::readExtensions(), soma::FormatDictionary< T >::readFormat(), soma::FormatDictionary< T >::readFormats(), carto::toString(), and carto::Object::value().

◆ read() [2/2]

template<class T >
bool soma::Reader< T >::read ( T &  obj,
carto::Object  header = carto::none(),
int  passbegin = 1,
int  passend = 4 
)
virtual

Finds the correct format and reads the object.

if format is specified, this format is tried first, so you can use it as a hint if you already know it (from the DataSourceInfoLoader check ). It is possible to specify which passes to process through passbegin and passend.

  • pass 1 : format hint
  • pass 2 : extension
  • pass 3 : empty extension
  • pass 4 : all readers

Definition at line 223 of file reader_d.h.

References soma::DataSourceInfo::capabilities(), soma::DataSourceInfoLoader::check(), soma::FormatReader< T >::clone(), soma::DataSourceList::empty(), carto::FileUtil::extension(), rc_ptr< GenericObject >::get(), soma::DataSourceInfo::header(), carto::Object::isNone(), carto::io_error::keepExceptionPriority(), carto::io_error::launchExcept(), soma::DataSourceInfoLoader::launchException(), soma::DataSourceInfo::list(), localMsg, soma::FormatDictionary< T >::readExtensions(), soma::FormatDictionary< T >::readFormat(), soma::FormatDictionary< T >::readFormats(), soma::DataSourceCapabilities::setMemoryMapping(), carto::toString(), and carto::Object::value().

Referenced by operator>>().

◆ setAllocatorContext()

template<typename T >
void soma::Reader< T >::setAllocatorContext ( const AllocatorContext ac)

Definition at line 107 of file reader_d.h.

◆ setOptions()

template<class T >
void soma::Reader< T >::setOptions ( carto::Object  options)

Definition at line 122 of file reader_d.h.

Member Data Documentation

◆ _alloccontext

template<typename T >
AllocatorContext soma::Reader< T >::_alloccontext
protected

Definition at line 169 of file reader.h.

◆ _datasourceinfo

template<typename T >
carto::rc_ptr<DataSourceInfo> soma::Reader< T >::_datasourceinfo
protected

Definition at line 168 of file reader.h.

Referenced by soma::Reader< T >::dataSourceInfo().

◆ _options

template<typename T >
carto::Object soma::Reader< T >::_options
protected

Definition at line 170 of file reader.h.


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