soma-io 6.0.6
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.
 
virtual T * read (carto::Object header=carto::none(), int passbegin=1, int passend=4)
 Creates and reads an object.
 
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.

References _datasourceinfo, and Reader().

Referenced by Reader(), Reader(), Reader(), Reader(), and Reader().

◆ Reader() [2/5]

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

Definition at line 85 of file reader_d.h.

References _datasourceinfo, and Reader().

◆ Reader() [3/5]

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

Definition at line 75 of file reader_d.h.

References _datasourceinfo, and Reader().

◆ Reader() [4/5]

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

Definition at line 80 of file reader_d.h.

References _datasourceinfo, and Reader().

◆ Reader() [5/5]

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

Definition at line 92 of file reader_d.h.

References _datasourceinfo, and Reader().

◆ ~Reader()

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

Definition at line 99 of file reader_d.h.

References ~Reader().

Referenced by ~Reader().

Member Function Documentation

◆ allocatorContext()

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

Definition at line 113 of file reader_d.h.

References _alloccontext, and allocatorContext().

Referenced by allocatorContext().

◆ 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.

References _datasourceinfo, and attach().

Referenced by attach(), attach(), and attach().

◆ 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.

References _datasourceinfo, and attach().

◆ attach() [3/3]

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

Definition at line 165 of file reader_d.h.

References _datasourceinfo, and attach().

◆ close()

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

Definition at line 205 of file reader_d.h.

References _datasourceinfo, and close().

Referenced by close().

◆ dataSource() [1/2]

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

Definition at line 187 of file reader_d.h.

References _datasourceinfo, dataSource(), and soma::DataSource::none().

◆ dataSource() [2/2]

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

Definition at line 177 of file reader_d.h.

References _datasourceinfo, dataSource(), and soma::DataSource::none().

Referenced by dataSource(), dataSource(), read(), and read().

◆ dataSourceInfo() [1/2]

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

Definition at line 126 of file reader.h.

References _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 _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.

References _datasourceinfo, and flush().

Referenced by flush().

◆ options() [1/2]

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

Definition at line 134 of file reader_d.h.

References _options, and options().

◆ options() [2/2]

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

Definition at line 128 of file reader_d.h.

References _options, and options().

Referenced by options(), options(), and setOptions().

◆ 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 _alloccontext, _datasourceinfo, _options, soma::DataSourceInfoLoader::check(), soma::FormatReader< T >::clone(), dataSource(), soma::DataSourceList::empty(), carto::FileUtil::extension(), carto::rc_ptr< typename T >::get(), soma::DataSourceInfo::header(), carto::Object::isNone(), carto::io_error::keepExceptionPriority(), carto::io_error::launchExcept(), soma::DataSourceInfoLoader::launchException(), soma::DataSourceInfo::list(), localMsg, carto::DataTypeCode< class T >::name(), read(), 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 _alloccontext, _datasourceinfo, _options, soma::DataSourceInfoLoader::check(), soma::FormatReader< T >::clone(), dataSource(), soma::DataSourceList::empty(), carto::FileUtil::extension(), carto::rc_ptr< typename T >::get(), soma::DataSourceInfo::header(), carto::Object::isNone(), carto::io_error::keepExceptionPriority(), carto::io_error::launchExcept(), soma::DataSourceInfoLoader::launchException(), soma::DataSourceInfo::list(), localMsg, carto::DataTypeCode< class T >::name(), read(), soma::FormatDictionary< T >::readExtensions(), soma::FormatDictionary< T >::readFormat(), soma::FormatDictionary< T >::readFormats(), carto::toString(), and carto::Object::value().

Referenced by operator>>(), read(), and read().

◆ setAllocatorContext()

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

Definition at line 107 of file reader_d.h.

References _alloccontext, and setAllocatorContext().

Referenced by setAllocatorContext().

◆ setOptions()

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

Definition at line 122 of file reader_d.h.

References _options, options(), and setOptions().

Referenced by setOptions().

Member Data Documentation

◆ _alloccontext

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

Definition at line 169 of file reader.h.

Referenced by allocatorContext(), read(), read(), and setAllocatorContext().

◆ _datasourceinfo

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

◆ _options

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

Definition at line 170 of file reader.h.

Referenced by options(), options(), read(), read(), and setOptions().


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