34 #ifndef SOMAIO_IO_WRITER_D_H 
   35 #define SOMAIO_IO_WRITER_D_H 
   51 #define localMsg( message ) cartoCondMsg( 4, message, "WRITER" )
 
   68     return writer->
write( obj, options );
 
  113   typedef std::multimap<std::string,std::string> 
multi_S;
 
  114   typedef std::set<std::string> 
set_S;
 
  115   typedef std::pair<std::multimap<std::string, std::string>::const_iterator,
 
  116       std::multimap<std::string, std::string>::const_iterator> 
pair_cit_S;
 
  121                          int passbegin, 
int passend )
 
  127     set_S::iterator  notyet = tried.end();
 
  137       = FileUtil::uriFilename( _datasourceinfo->list().dataSource()->url() );
 
  139       = FileUtil::uriOptions( _datasourceinfo->list().dataSource()->url() );
 
  140     if( urioptions.
get() ) {
 
  141       _datasourceinfo->list().dataSource()
 
  143       options->copyProperties( urioptions );
 
  147     options->getProperty( 
"format", format );
 
  149     bool exactformat = 
false;
 
  152       carto::Object exact = options->getProperty( 
"exact_format" );
 
  153       exactformat = exact->getScalar();
 
  160     if( passbegin <= 1 && passend >= 1 && !format.empty() )
 
  168           localMsg( 
"1. try writer " + format );
 
  169           if( writer->
write( obj, _datasourceinfo, options ) )
 
  174           else if( exactformat )
 
  176               "object in format " ) + format, _datasourceinfo->url() );
 
  178         catch( std::exception & e )
 
  180           localMsg( 
"1. " + format + 
" failed" );
 
  185         tried.insert( format );
 
  187       else if( exactformat )
 
  189           "object in format " ) + format, _datasourceinfo->url() );
 
  195     multi_S::const_iterator ie, ee;
 
  199     if( passbegin <= 2 && passend >= 2 )
 
  202       iext = extensions.equal_range( ext );
 
  203       for( ie=iext.first, ee=iext.second; ie!=ee; ++ie )
 
  204         if( tried.find( ie->second ) == notyet ) {
 
  210               localMsg( 
"2. try writer " + ie->second );
 
  211               if( writer->
write( obj, _datasourceinfo, options ) )
 
  213                 localMsg( 
"2. " + ie->second + 
" OK" );
 
  216               else if( exactformat )
 
  218                   "object in format " ) + format, _datasourceinfo->url() );
 
  220             catch( std::exception & e )
 
  222               localMsg( 
" 2. " + ie->second + 
" failed" );
 
  227             tried.insert( ie->second );
 
  233     if( passbegin <= 3 && passend >= 3 && !ext.empty() )
 
  236       iext = extensions.equal_range( 
"" );
 
  237       for( ie=iext.first, ee=iext.second; ie!=ee; ++ie )
 
  238         if( tried.find( ie->second ) == notyet ) {
 
  244               localMsg( 
"3. try writer " + ie->second );
 
  245               if( writer->
write( obj, _datasourceinfo, options ) )
 
  247                 localMsg( 
"3. " + ie->second + 
" OK" );
 
  250               else if( exactformat )
 
  252                   "object in format " ) + format, _datasourceinfo->url() );
 
  254             catch( std::exception & e )
 
  256               localMsg( 
"3. " + ie->second + 
" failed" );
 
  261             tried.insert( ie->second );
 
  267     if( passbegin <= 4 && passend >= 4 )
 
  270       iext.first = extensions.begin();
 
  271       iext.second = extensions.end();
 
  272       for( ie=iext.first, ee=iext.second; ie!=ee; ++ie )
 
  273         if( tried.find( ie->second ) == notyet ) {
 
  279               localMsg( 
"4. try writer " + ie->second );
 
  280               if( writer->
write( obj, _datasourceinfo, options ) )
 
  282                 localMsg( 
"4. " + ie->second + 
" OK" );
 
  285               else if( exactformat )
 
  287                   "object in format " ) + format, _datasourceinfo->url() );
 
  289             catch( std::exception & e )
 
  291               localMsg( 
"4. " + ie->second + 
" failed" );
 
  296             tried.insert( ie->second );
 
  303                                    filename + 
" : no matching format" );
 
static std::string extension(const std::string &)
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="")
GenericObject * get() const
bool write(const T &obj, carto::Object options=carto::none())
Finds the correct format and writes the object.
carto::rc_ptr< DataSourceInfo > _datasourceinfo
Generic writer for every format of Aims object.
virtual std::string writtenObjectType() const
virtual bool write(const T &obj, carto::Object options=carto::none(), int passbegin=1, int passend=4)
Finds the correct format and writes the object.
std::string toString(const T &object)
std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iterator > pair_cit_S
std::set< std::string > set_S
std::multimap< std::string, std::string > multi_S
#define localMsg(message)