soma-io  5.1.2
soma::FormatReader< T > Class Template Referenceabstract

Low-level object IO reader specialized for a specific format. More...

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

Inheritance diagram for soma::FormatReader< T >:

Public Member Functions

virtual ~FormatReader ()
 
virtual void setupAndRead (T &obj, carto::rc_ptr< DataSourceInfo > dsi, const AllocatorContext &context, carto::Object options)
 Full reading procedure, for an already existing object. More...
 
virtual T * createAndRead (carto::rc_ptr< DataSourceInfo > dsi, const AllocatorContext &context, carto::Object options)
 Factory mode: creates an object and reads it. More...
 
virtual void read (T &obj, carto::rc_ptr< DataSourceInfo > dsi, const AllocatorContext &context, carto::Object options)
 Reads part or all of the object obj. More...
 
virtual FormatReader< T > * clone () const =0
 Duplicate the FormatReader. More...
 
virtual std::string formatID () const =0
 Format identifier (abstract). More...
 
virtual carto::rc_ptr< DataSourceInfocheckDataSourceInfo (carto::rc_ptr< DataSourceInfo > dsi, carto::Object options)
 Checks that dsi has been identified with the matching format checker. More...
 
virtual T * create (carto::Object header, const AllocatorContext &context, carto::Object options)
 create the object to be read, bind the allocation context. More...
 
virtual void setup (T &obj, carto::Object header, const AllocatorContext &context, carto::Object options)
 setup an existing object (for resizing or reallocation for instance). More...
 

Detailed Description

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

Low-level object IO reader specialized for a specific format.

To invoque such a format-specific reader, information about the source is supposed to be already read, this is to say: the object header has already been read (using DataSourceInfo).

This is a low-level format reader, which is not intended to be used alone: Reader will use it to achieve appropriate decoding, allocation, and reading.

The job of a reader can be decomposed into several steps:

  • (the header has already been read by a FormatChecker)
  • determination of the correct allocator, matching with the stream decoder characteristics: this means creating an AllocatorContext bound to the specific DataSource decoder.
  • allocation or setup (reallocation, resizing) of the object to be read, according to reading options (partial reading of an already allocated object may not require a reallocation...). This is performed using a Creator.
  • reading of the data, or of a part of it, which can be done on demand, directly via the DataSource once it is setup and plugged

    Todo:
    Needs to be added:

Definition at line 84 of file formatreader.h.

Constructor & Destructor Documentation

◆ ~FormatReader()

template<typename T >
soma::FormatReader< T >::~FormatReader
virtual

Definition at line 61 of file formatreader_d.h.

Member Function Documentation

◆ checkDataSourceInfo()

template<typename T >
carto::rc_ptr< DataSourceInfo > soma::FormatReader< T >::checkDataSourceInfo ( carto::rc_ptr< DataSourceInfo dsi,
carto::Object  options 
)
virtual

Checks that dsi has been identified with the matching format checker.

If not, instantiate a new DataSourceInfo and return it. If yes, the returned DataSourceInfo will be the input one. This method is called automatically from createAndRead() or setupAndRead().

Definition at line 118 of file formatreader_d.h.

References soma::DataSourceInfoLoader::check(), carto::Object::isNone(), localMsg, and carto::Object::value().

◆ clone()

template<typename T >
virtual FormatReader<T>* soma::FormatReader< T >::clone ( ) const
pure virtual

Duplicate the FormatReader.

Some FormatReader can contain data describing the data source or storage buffer, so must be cloned for each read. Note that, for now, the cloned instance does not need to have the same bound internal data, since it is cloned precisely to work on a different source/buffer. It just needs to be another instance of the same exact type.

Implemented in soma::XMLFormatReader, soma::PythonFormatReader, and soma::JsonFormatReader.

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

◆ create()

template<typename T >
T * soma::FormatReader< T >::create ( carto::Object  header,
const AllocatorContext context,
carto::Object  options 
)
virtual

create the object to be read, bind the allocation context.

Either create() or setup() will be called, depending if we are working on an existing object or have to allocate a new one. The default implementations just calls Creator<T>::create().

Definition at line 140 of file formatreader_d.h.

References soma::Creator< T >::create(), and localMsg.

◆ createAndRead()

template<typename T >
T * soma::FormatReader< T >::createAndRead ( carto::rc_ptr< DataSourceInfo dsi,
const AllocatorContext context,
carto::Object  options 
)
virtual

Factory mode: creates an object and reads it.

The returned object belongs to the calling layer and may be deleted by the standard delete

Reimplemented in soma::XMLFormatReader, soma::PythonFormatReader, and soma::JsonFormatReader.

Definition at line 83 of file formatreader_d.h.

◆ formatID()

template<typename T >
virtual std::string soma::FormatReader< T >::formatID ( ) const
pure virtual

Format identifier (abstract).

Used to match checker and reader

Implemented in soma::XMLFormatReader, soma::PythonFormatReader, and soma::JsonFormatReader.

◆ read()

template<typename T >
void soma::FormatReader< T >::read ( T &  obj,
carto::rc_ptr< DataSourceInfo dsi,
const AllocatorContext context,
carto::Object  options 
)
virtual

Reads part or all of the object obj.

This read() method should be called after everything is setup and bound For objects supporting allocators, context should be the same as the context bound to the object, and reading is just a matter of calling the read methods of the DataSource bound to the context.

Parameters
objobject to read into
dsiDataSourceInfo containing pre-computed header, data source list and capabilities.
optionsmay specify a sub-object for partial reading

Definition at line 106 of file formatreader_d.h.

◆ setup()

template<typename T >
void soma::FormatReader< T >::setup ( T &  obj,
carto::Object  header,
const AllocatorContext context,
carto::Object  options 
)
virtual

setup an existing object (for resizing or reallocation for instance).

Either create() or setup() will be called, depending if we are working on an existing object or have to allocate a new one. The default implementations just calls Creator<T>::create().

Definition at line 149 of file formatreader_d.h.

◆ setupAndRead()

template<typename T >
void soma::FormatReader< T >::setupAndRead ( T &  obj,
carto::rc_ptr< DataSourceInfo dsi,
const AllocatorContext context,
carto::Object  options 
)
virtual

Full reading procedure, for an already existing object.

Definition at line 69 of file formatreader_d.h.

References soma::AllocatorContext::accessMode(), localMsg, and soma::AllocatorContext::useFactor().


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