soma-io  5.0.5
soma::DataSourceInfoLoader Class Reference

Generic information retreiver / checker for all data sources and file formats. More...

#include <soma-io/datasourceinfo/datasourceinfoloader.h>

Public Types

enum  State { Unchecked, Ok, Error }
 

Public Member Functions

 DataSourceInfoLoader ()
 
 ~DataSourceInfoLoader ()
 
DataSourceInfo check (DataSourceInfo dsi, carto::Object options=carto::none(), int passbegin=1, int passend=3)
 Finds the right format checker. More...
 
State state () const
 
std::string errorMessage () const
 
void launchException ()
 

Static Public Member Functions

static void registerFormat (const std::string &fmtid, FormatChecker *format, const std::vector< std::string > &extensions)
 Registers a FormatChecker into the dictionary. More...
 
static FormatCheckerformatInfo (const std::string &format)
 Returns the corresponding FormatChecker. More...
 
static carto::Object readMinf (DataSource &ds, carto::Object base=carto::none(), carto::Object options=carto::none())
 Called inter alia by format-specific FormatChecker to complete header informations. More...
 
static carto::SyntaxSetminfSyntax ()
 Syntax for minf dictionaries. More...
 
static std::set< std::string > extensions (const std::string &format)
 Extensions matching a specified format. More...
 
static std::set< std::string > formats (const std::string &ext)
 Formats matching a specified extension. More...
 
static std::set< std::string > readFormats (const std::string &ext, const std::string &data_type_name)
 Available reading formats for an extension and a data type. More...
 
static std::set< std::string > writeFormats (const std::string &ext, const std::string &data_type_name)
 Available writing formats for an extension and a data type. More...
 

Static Protected Member Functions

static std::set< std::string > formats (const std::string &ext, soma::IOObjectTypesDictionary::FormatInfo &format_info)
 Available formats for an extension and a format info. More...
 

Protected Attributes

Private * d
 

Detailed Description

Generic information retreiver / checker for all data sources and file formats.

It replaces carto::DataSourceInfo and aims::Finder.
DataSourceInfoLoader provides a plug-in system for new formats and data types. Formats are hidden in the plugins and should never be accessed directly.
Usage: check() the DataSourceInfo and then process according to the object type ("Volume of S16", "Mesh", "Texture", "Bucket", ...).
Use the generic Reader once the data type is known, the right format will be selected automatically.
Avoiding manually switching on objects and data types is possible using the ReaderAlgorithm interface and presumably, template functions.
Here is an example of how to use the DataSourceInfoLoader class:

#include <cartodata/volume/volume.h>
#include <iostream>
using namespace soma;
using namespace carto;
using namespace std;
DataSourceInfo info( "toto.ima" );
info = f.check( info );
if( !info.header().get() )
cerr << "could not load " << info.dataSource()->url() << endl;
else
{
string object_type = info.header()->getProperty( "object_type" )->getString();
if( object_type == DataTypeCode<Volume<int16_t> >::name() )
{
Reader<Volume<int16_t> > vr( info );
VolumeRef<int16_t> vol( vr.read() );
if( vol )
cout << "volume read" << endl;
else
cerr << "Error loading " << info.dataSource()->url() << endl;
}
else if( object_type == DataTypeCode<Mesh>::name() )
{
// do your thing
}
else
cerr << info.dataSource()->url() << " is of type " << object_type
<< " which is not handled" << endl;
}
See also
DataSourceInfo, Reader, ReaderAlgorithm

Definition at line 107 of file datasourceinfoloader.h.

Member Enumeration Documentation

◆ State

Enumerator
Unchecked 
Ok 
Error 

Definition at line 110 of file datasourceinfoloader.h.

Constructor & Destructor Documentation

◆ DataSourceInfoLoader()

soma::DataSourceInfoLoader::DataSourceInfoLoader ( )

◆ ~DataSourceInfoLoader()

soma::DataSourceInfoLoader::~DataSourceInfoLoader ( )

Member Function Documentation

◆ check()

DataSourceInfo soma::DataSourceInfoLoader::check ( DataSourceInfo  dsi,
carto::Object  options = carto::none(),
int  passbegin = 1,
int  passend = 3 
)

Finds the right format checker.

Parameters
dsiDataSourceInfo containing header, DSlist and . capabilities. It allows us to have none, some or all information already computed. It is for the DSIloader to deal with the all case, and for the FormatCheckers to deal with some and none cases.
optionsA dictionary containing options. They may not be of any use to the checker, but soma are ( resolution_level ).
Returns
A DataSourceInfo object containing a header, a list of DataSource and a list of Capabilities. It is possible to specify wich passes to process through passbegin and passend.
  • pass 1 : extension
  • pass 2 : empty extension
  • pass 3 : all writers
See also
DataSourceInfo DataSourceList DataSourceCapabilities

Referenced by soma::FormatReader< carto::GenericObject >::checkDataSourceInfo(), and soma::Reader< T >::read().

◆ errorMessage()

std::string soma::DataSourceInfoLoader::errorMessage ( ) const

◆ extensions()

static std::set<std::string> soma::DataSourceInfoLoader::extensions ( const std::string &  format)
static

Extensions matching a specified format.

◆ formatInfo()

static FormatChecker* soma::DataSourceInfoLoader::formatInfo ( const std::string &  format)
static

Returns the corresponding FormatChecker.

Parameters
formatIdentification of the format. ex: "GIS"

◆ formats() [1/2]

static std::set<std::string> soma::DataSourceInfoLoader::formats ( const std::string &  ext)
static

Formats matching a specified extension.

◆ formats() [2/2]

static std::set<std::string> soma::DataSourceInfoLoader::formats ( const std::string &  ext,
soma::IOObjectTypesDictionary::FormatInfo format_info 
)
staticprotected

Available formats for an extension and a format info.

◆ launchException()

void soma::DataSourceInfoLoader::launchException ( )

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

◆ minfSyntax()

static carto::SyntaxSet& soma::DataSourceInfoLoader::minfSyntax ( )
static

Syntax for minf dictionaries.

◆ readFormats()

static std::set<std::string> soma::DataSourceInfoLoader::readFormats ( const std::string &  ext,
const std::string &  data_type_name 
)
static

Available reading formats for an extension and a data type.

◆ readMinf()

static carto::Object soma::DataSourceInfoLoader::readMinf ( DataSource ds,
carto::Object  base = carto::none(),
carto::Object  options = carto::none() 
)
static

Called inter alia by format-specific FormatChecker to complete header informations.

Parameters
dsDataSource to minf file
baseIf given, the function keeps information from the base header and adds that from the minf file.

◆ registerFormat()

static void soma::DataSourceInfoLoader::registerFormat ( const std::string &  fmtid,
FormatChecker format,
const std::vector< std::string > &  extensions 
)
static

Registers a FormatChecker into the dictionary.

Parameters
fmtidIdentification of the format. ex: "GIS"
formatSpecialized FormatChecker
extensionsExtensions readable by the FormatChecker

◆ state()

State soma::DataSourceInfoLoader::state ( ) const

◆ writeFormats()

static std::set<std::string> soma::DataSourceInfoLoader::writeFormats ( const std::string &  ext,
const std::string &  data_type_name 
)
static

Available writing formats for an extension and a data type.

Member Data Documentation

◆ d

Private* soma::DataSourceInfoLoader::d
protected

Definition at line 183 of file datasourceinfoloader.h.


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