soma-io  5.0.5
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 68 of file reader_d.h.

◆ Reader() [2/5]

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

Definition at line 83 of file reader_d.h.

◆ Reader() [3/5]

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

Definition at line 73 of file reader_d.h.

◆ Reader() [4/5]

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

Definition at line 78 of file reader_d.h.

◆ Reader() [5/5]

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

Definition at line 90 of file reader_d.h.

◆ ~Reader()

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

Definition at line 97 of file reader_d.h.

Member Function Documentation

◆ allocatorContext()

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

Definition at line 111 of file reader_d.h.

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

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

◆ attach() [1/3]

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

Definition at line 141 of file reader_d.h.

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

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

◆ attach() [2/3]

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

Definition at line 151 of file reader_d.h.

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

◆ attach() [3/3]

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

Definition at line 163 of file reader_d.h.

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

◆ close()

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

Definition at line 203 of file reader_d.h.

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

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

◆ dataSource() [1/2]

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

◆ dataSource() [2/2]

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

Definition at line 185 of file reader_d.h.

References soma::Reader< T >::_datasourceinfo, and soma::DataSource::none().

◆ dataSourceInfo() [1/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.

◆ dataSourceInfo() [2/2]

◆ 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 195 of file reader_d.h.

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

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

◆ options() [1/2]

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

◆ options() [2/2]

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

Definition at line 132 of file reader_d.h.

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

◆ read() [1/2]

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

◆ read() [2/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 wich 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 425 of file reader_d.h.

References soma::Reader< T >::_alloccontext, soma::Reader< T >::_datasourceinfo, soma::Reader< T >::_options, soma::DataSourceInfoLoader::check(), soma::FormatReader< T >::clone(), soma::Reader< T >::dataSource(), 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::AllocatorContext::setDataSourceInfo(), carto::toString(), and carto::Object::value().

◆ setAllocatorContext()

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

Definition at line 105 of file reader_d.h.

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

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

◆ setOptions()

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

Member Data Documentation

◆ _alloccontext

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

◆ _datasourceinfo

◆ _options

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

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