34 #ifndef AIMS_IO_READER_D_H 
   35 #define AIMS_IO_READER_D_H 
   48 #define localMsg( message ) cartoCondMsg( 4, message, "AIMS::READER" )
 
   50 #define AIMS_INSTANTIATE_READER( T ) \ 
   52     template class aims::Reader< T >; \ 
   55     template class soma::FormatDictionary< T >; \ 
   56     template class soma::Reader< T >; \ 
   58 #define AIMS_INSTANTIATE_AIMS_READER( T ) \ 
   60     template class aims::Reader< T >; \ 
   68     : _mode( 
carto::AllocatorStrategy::Memory )
 
   73     : _filename( filename ), _mode( 
carto::AllocatorStrategy::Memory )
 
   85       case carto::AllocatorStrategy::Memory:
 
   87       case carto::AllocatorStrategy::CopyMap:
 
   88         _alloccontext.setAccessMode( carto::AllocatorStrategy::InternalModif );
 
   90       case carto::AllocatorStrategy::ReadOnlyMap:
 
   91         _alloccontext.setAccessMode( carto::AllocatorStrategy::ReadOnly );
 
   93       case carto::AllocatorStrategy::ReadWriteMap:
 
   94         _alloccontext.setAccessMode( carto::AllocatorStrategy::ReadWrite );
 
   96       case carto::AllocatorStrategy::Unallocated:
 
   97         _alloccontext.setAccessMode( carto::AllocatorStrategy::NotOwner );
 
  100         _alloccontext.setAccessMode( carto::AllocatorStrategy::InternalModif );
 
  105   template <
typename T>
 
  111   template <
typename T>
 
  114     return _alloccontext;
 
  120     _filename = fileName;
 
  152     read_options->copyProperties(
 
  157     if( !_options.get() )
 
  161         _options->setProperty( 
"frame", frame );
 
  163         _options->setProperty( 
"subobjectsfilter", frame );
 
  166       _options->setProperty( 
"border", border );
 
  174         _format = oformat->getString();
 
  182       _options->setProperty( 
"format", *format );
 
  185     read_options->copyProperties(_options);
 
  192       std::string uri = _filename;
 
  193       if( border != 0 || frame != -1 )
 
  197       if( border != 0 && frame != -1 )
 
  207       options->setProperty( 
"convert_to_aims", 
true );
 
  212     localMsg(
"0. Try soma::Reader ...") ;
 
  214       return reader.
read( obj, n, 1, 3 );
 
  217     catch( std::exception & e )
 
  227     std::set<std::string>               tried;
 
  228     std::set<FileFormat<T> *>           triedf;
 
  230     std::set<std::string>::iterator     notyet = tried.end();
 
  231     typename std::set<FileFormat<T> *>::iterator        notyetf = triedf.end();
 
  241       if( read_options.
isNull() )
 
  243       read_options->copyProperties( uri_opt );
 
  254           localMsg(
"1. try reader " + *format);
 
  256           if( reader->
read( filename, obj, _alloccontext, read_options ) )
 
  267         catch( std::exception & e )
 
  275         tried.insert( *format );
 
  276         triedf.insert( reader );
 
  281     std::string::size_type     pos = bname.find( 
'.' );
 
  282     std::string::size_type     dlen = filename.length() - bname.length();
 
  285     if( pos != std::string::npos )
 
  286       ext = filename.substr( dlen+pos+1, filename.length() - pos - 1 );
 
  288     const std::map<std::string, std::list<std::string> >        & extensions
 
  291     std::map<std::string, std::list<std::string> >::const_iterator iext
 
  292         = extensions.find( ext ),
 
  293     eext = extensions.end();
 
  294     std::list<std::string>::const_iterator ie, ee;
 
  296     while( iext == eext && (pos=bname.find( 
'.', pos+1 ))!=std::string::npos )
 
  298       ext = filename.substr( dlen+pos+1, filename.length() - pos - 1 );
 
  299       iext = extensions.find( ext );
 
  304       for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
 
  305         if( tried.find( *ie ) == notyet )
 
  308           if( reader && triedf.find( reader ) == notyetf )
 
  315               if( reader->
read( filename, obj, _alloccontext, read_options ) )
 
  326             catch( std::exception & e )
 
  335             localMsg(
"2. unsuccessfully tried " + *ie);
 
  338             triedf.insert( reader );
 
  345       iext = extensions.find( 
"" );
 
  348         for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
 
  349           if( tried.find( *ie ) == notyet )
 
  352             if( reader && triedf.find( reader ) == notyetf )
 
  359                 if( reader->
read( filename, obj, _alloccontext, read_options ) )
 
  370               catch( std::exception & e )
 
  379               triedf.insert( reader );
 
  385     for( iext=extensions.begin(); iext!=eext; ++iext )
 
  386       for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
 
  387         if( tried.find( *ie ) == notyet )
 
  390           if( reader && triedf.find( reader ) == notyetf )
 
  397               if( reader->
read( filename, obj, _alloccontext, read_options ) )
 
  408             catch( std::exception & e )
 
  417             triedf.insert( reader );
 
  426       std::string uri = filename;
 
  427       if( border != 0 || frame != -1 )
 
  431       if( border != 0 && frame != -1 )
 
  439       return reader.
read( obj, n, 4, 4 );
 
  445                                    filename + 
" : no matching format" );
 
  461     read_options->copyProperties(
 
  466     if( !_options.get() )
 
  470         _options->setProperty( 
"frame", frame );
 
  472         _options->setProperty( 
"subobjectsfilter", frame );
 
  475       _options->setProperty( 
"border", border );
 
  483         _format = oformat->getString();
 
  491       _options->setProperty( 
"format", *format );
 
  494     read_options->copyProperties(_options);
 
  501       std::string uri = _filename;
 
  502       if( border != 0 || frame != -1 )
 
  506       if( border != 0 && frame != -1 )
 
  512     localMsg(
"building soma::Reader using uri: " + uri);
 
  519       options->setProperty( 
"convert_to_aims", 
true );
 
  523     localMsg(
"0. Try soma::Reader ...");
 
  528     catch( std::exception & e )
 
  538     std::set<std::string>               tried;
 
  539     std::set<FileFormat<T> *>           triedf;
 
  541     std::set<std::string>::iterator     notyet = tried.end();
 
  542     typename std::set<FileFormat<T> *>::iterator        notyetf = triedf.end();
 
  553       if( read_options.
isNull() )
 
  555       read_options->copyProperties( uri_opt );
 
  566           localMsg(
"1. try reader " + *format);
 
  568           obj = reader->
read( filename, _alloccontext, read_options );
 
  580         catch( std::exception & e )
 
  588         tried.insert( *format );
 
  589         triedf.insert( reader );
 
  595     const std::map<std::string, std::list<std::string> >        & extensions
 
  598     std::map<std::string, std::list<std::string> >::const_iterator iext
 
  599         = extensions.find( ext ),
 
  600     eext = extensions.end();
 
  601     std::list<std::string>::const_iterator ie, ee;
 
  605       for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
 
  606         if( tried.find( *ie ) == notyet )
 
  609           if( reader && triedf.find( reader ) == notyetf )
 
  616               obj = reader->
read( filename, _alloccontext, read_options );
 
  628             catch( std::exception & e )
 
  637             localMsg(
"2. unsuccessfully tried " + *ie);
 
  640             triedf.insert( reader );
 
  647       iext = extensions.find( 
"" );
 
  650         for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
 
  651           if( tried.find( *ie ) == notyet )
 
  654             if( reader && triedf.find( reader ) == notyetf )
 
  661                 obj = reader->
read( filename, _alloccontext, read_options );
 
  673               catch( std::exception & e )
 
  682               triedf.insert( reader );
 
  688     for( iext=extensions.begin(); iext!=eext; ++iext )
 
  689       for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
 
  690         if( tried.find( *ie ) == notyet )
 
  693           if( reader && triedf.find( reader ) == notyetf )
 
  700               obj = reader->
read( filename, _alloccontext, read_options );
 
  712             catch( std::exception & e )
 
  721             triedf.insert( reader );
 
  730       std::string uri = filename;
 
  731       if( border != 0 || frame != -1 )
 
  735       if( border != 0 && frame != -1 )
 
  748                                    filename + 
" : no matching format" );
 
const carto::AllocatorStrategy::MappingMode MAP
static void postProcessHeader(carto::Object hdr)
carto::Object options() const
void setAllocatorContext(const carto::AllocatorContext &ac)
allocator control (not used by every format yet)
virtual bool read(T &obj, int border=0, const std::string *format=0, int frame=-1)
Finds the correct format and reads the object. if format is specified, this format is tried first,...
const carto::AllocatorContext & allocatorContext() const
void setFileName(const std::string &fileName)
set input file name
void setOptions(carto::Object options)
void setMode(carto::AllocatorStrategy::MappingMode mode)
set input file mode - soon obsolete
static Settings & settings()
static std::string basename(const std::string &)
static std::string extension(const std::string &)
static std::string uriFilename(const std::string &filein)
static Object uriOptions(const std::string &filein)
Object reference(Object &value)
static void keepExceptionPriority(std::exception &e, int &prio, int &type, std::string &message, int raiseprio=0)
static void launchExcept(int code, const std::string &msg, const std::string &defmsg="")
void setAllocatorContext(const AllocatorContext &ac)
virtual bool read(T &obj, carto::Object header=carto::none(), int passbegin=1, int passend=4)
void setOptions(carto::Object options)
The class for EcatSino data write operation.
std::string toString(const T &object)
carto::Object getObjectHeader(Headered &h)
std::map< std::string, Object > Dictionary
#define localMsg(message)