A.I.M.S


aims::Finder Class Reference

Generic finder / checker for all data objects and file formats This will replace the old AimsFinder. More...

#include <aims/io/finder.h>

Public Types

enum  State { Unchecked, Ok, Error }
 

Public Member Functions

 Finder ()
 
 ~Finder ()
 
bool check (const std::string &filename)
 Determines object associated to file name and returns true if success. More...
 
std::string objectType () const
 
void setObjectType (const std::string &obj)
 
std::string dataType () const
 
void setDataType (const std::string &dat)
 
std::vector< std::string > possibleDataTypes () const
 
void setPossibleDataTypes (const std::vector< std::string > &dt)
 
std::string format () const
 
void setFormat (const std::string &fmt)
 
const Headerheader () const
 
void setHeader (Header *hdr)
 
carto::Object headerObject () const
 
void setHeader (carto::Object hdr)
 
State state () const
 
std::string errorMessage () const
 
void launchException ()
 creates and throws an exception corresponding to the error state More...
 

Static Public Member Functions

static void registerFormat (const std::string &fmtid, FinderFormat *format, const std::vector< std::string > &extensions, const std::string &before="")
 
static FinderFormatfinderFormat (const std::string &format)
 Finds the FinderFormat associated with the given string ID. More...
 
static void postProcessHeader (carto::Object hdr)
 
static std::set< std::string > extensions (const std::string &format)
 show the set of official extensions for a given format More...
 

Detailed Description

Generic finder / checker for all data objects and file formats This will replace the old AimsFinder.

Warning: Finder will be replaced by carto::DataSourceInfo in cartobase library. Avoid using it in new code.

The Finder 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 file and then process according to the object type ("Volume", "Mesh", "Texture", "Bucket", ...) and its data type (if any) ("S16" : short, "U8": unsigned byte, "FLOAT", "DOUBLE", ...)
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 now possible using the new Process interface and presumably, template functions.

See the AimsFileInfo command for an example of how to use it.

Here is an example of using the Finder class:

#include <aims/io/finder.h>
#include <aims/io/reader.h>
#include <aims/data/data.h>
string fname = "toto.ima";
if( ! f.check( fname ) )
cerr << "could not load " << fname << endl;
else
{
if( f.objectType() == "Volume" )
{
if( f.dataType() == "S16" )
{
Reader<AimsData<short> > vr( fname );
if( vr.read( vol )
cout << "volume read\n";
else
cerr << "Error loading " << fname << endl;
}
else
{
cerr << fname << " is not a volume of short\n";
}
}
else if( f.objectType() == "Mesh" )
{
// ...
}
else
cerr << fname << " is not a volume or a mesh\n";
}
See also
Reader Process

Definition at line 117 of file finder.h.

Member Enumeration Documentation

Enumerator
Unchecked 
Ok 
Error 

Definition at line 120 of file finder.h.

Constructor & Destructor Documentation

aims::Finder::Finder ( )
aims::Finder::~Finder ( )

Member Function Documentation

bool aims::Finder::check ( const std::string &  filename)

Determines object associated to file name and returns true if success.

If successful, appropriate infos are stored into the Finder, including the full format header

std::string aims::Finder::dataType ( ) const
inline

Definition at line 142 of file finder.h.

Referenced by aims::AimsGraphReader::read().

std::string aims::Finder::errorMessage ( ) const
inline

Definition at line 159 of file finder.h.

static std::set<std::string> aims::Finder::extensions ( const std::string &  format)
static

show the set of official extensions for a given format

static FinderFormat* aims::Finder::finderFormat ( const std::string &  format)
static

Finds the FinderFormat associated with the given string ID.

std::string aims::Finder::format ( ) const
inline

Definition at line 152 of file finder.h.

const Header* aims::Finder::header ( ) const
carto::Object aims::Finder::headerObject ( ) const
inline

Definition at line 156 of file finder.h.

void aims::Finder::launchException ( )

creates and throws an exception corresponding to the error state

std::string aims::Finder::objectType ( ) const
inline

Definition at line 140 of file finder.h.

Referenced by aims::AimsGraphReader::read().

std::vector<std::string> aims::Finder::possibleDataTypes ( ) const
inline

Some formats (like VIDA and ECAT) can be read as different data types for the same file (for ex. if using shorts resampled for each slice). By asking all the possible data types you can choose the one you prefer for your application. Possible types may be sorted by preference.

Definition at line 148 of file finder.h.

static void aims::Finder::postProcessHeader ( carto::Object  hdr)
static

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

static void aims::Finder::registerFormat ( const std::string &  fmtid,
FinderFormat format,
const std::vector< std::string > &  extensions,
const std::string &  before = "" 
)
static
void aims::Finder::setDataType ( const std::string &  dat)
inline

Definition at line 143 of file finder.h.

void aims::Finder::setFormat ( const std::string &  fmt)
inline

Definition at line 153 of file finder.h.

void aims::Finder::setHeader ( Header hdr)
void aims::Finder::setHeader ( carto::Object  hdr)
void aims::Finder::setObjectType ( const std::string &  obj)
inline

Definition at line 141 of file finder.h.

void aims::Finder::setPossibleDataTypes ( const std::vector< std::string > &  dt)
inline

Definition at line 150 of file finder.h.

State aims::Finder::state ( ) const
inline

Definition at line 158 of file finder.h.


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