37 #ifndef AIMS_IO_WRITER_D_H
38 #define AIMS_IO_WRITER_D_H
51 #define AIMS_INSTANTIATE_WRITER( T ) \
53 template class aims::Writer< T >; \
55 GenericWriter::write< T >( const T &, bool, const std::string * ); \
58 #define AIMS_INSTANTIATE_ONLY_WRITER( T ) \
60 template class aims::Writer< T >; \
75 const std::string* format )
81 return writer->
write( obj, ascii, format );
113 bool exactformat =
false;
117 options->copyProperties(
121 if( !_options.isNull() )
125 carto::Object exact = _options->getProperty(
"exact_format" );
126 exactformat = (bool) exact->getScalar();
131 options->copyProperties( _options );
134 if( !options->hasProperty(
"ascii" ) )
135 options->setProperty(
"ascii", ascii );
143 _format = oformat->getString();
151 options->setProperty(
"format", *format );
158 std::string uri = _filename;
159 if( ascii || format )
163 if( ascii && format )
166 uri += (
"format=" + *format );
172 options->copyProperties(
176 if( !_options.isNull() )
177 options->copyProperties( _options );
178 return writer.
write( obj, options, 1, 3 );
186 std::set<std::string> tried;
188 std::set<std::string>::iterator notyet = tried.end();
200 std::cout <<
"1. try writer " << *format << std::endl;
204 if( writer->
write( _filename, obj, options ) )
206 else if( exactformat )
208 "object in format " ) + *format, _filename );
210 catch( std::exception & e )
217 tried.insert( *format );
222 std::string::size_type pos = bname.find(
'.' );
223 std::string::size_type dlen = _filename.length() - bname.length();
226 if( pos != std::string::npos )
227 ext = _filename.substr( dlen+pos+1, _filename.length() - pos - 1 );
229 const std::map<std::string, std::list<std::string> > & extensions
232 std::map<std::string, std::list<std::string> >::const_iterator iext
233 = extensions.find( ext ),
234 eext = extensions.end();
235 std::list<std::string>::const_iterator ie, ee;
243 carto::Object defwriters = sett.getProperty(
"default_writers" );
250 catch( std::exception & )
258 std::string defformat = defformato->getString();
260 if( tried.find( defformat ) == notyet )
266 std::cout <<
"2. try writer " << defformat << std::endl;
270 if( writer->
write( _filename, obj, options ) )
272 else if( exactformat )
274 "object in format " ) + defformat, _filename );
276 catch( std::exception & e )
283 tried.insert( defformat );
288 catch( std::exception & )
293 while( iext == eext && (pos=bname.find(
'.', pos+1 ))!=std::string::npos )
295 ext = _filename.substr( dlen+pos+1, _filename.length() - pos - 1 );
296 iext = extensions.find( ext );
301 for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
303 if( tried.find( *ie ) == notyet )
309 std::cout <<
"3. try writer " << *ie << std::endl;
313 if( writer->
write( _filename, obj, options ) )
315 else if( exactformat )
317 "object in format " ) + *ie, _filename );
319 catch( std::exception & e )
322 std::cout <<
"3. failed for " << *ie <<
": " << e.what()
338 iext = extensions.find(
"" );
341 for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
342 if( tried.find( *ie ) == notyet )
348 std::cout <<
"4. try writer " << *ie << std::endl;
352 if( writer->
write( _filename, obj, options ) )
354 else if( exactformat )
356 "object in format " ) + *ie, _filename );
358 catch( std::exception & e )
371 for( iext=extensions.begin(); iext!=eext; ++iext )
372 for( ie=iext->second.begin(), ee=iext->second.end(); ie!=ee; ++ie )
373 if( tried.find( *ie ) == notyet )
379 std::cout <<
"5. try writer " << *ie << std::endl;
383 if( writer->
write( _filename, obj, options ) )
385 else if( exactformat )
387 "object in format " ) + *ie, _filename );
389 catch( std::exception & e )
404 std::string uri = _filename;
405 if( ascii || format )
409 if( ascii && format )
412 uri += (
"format=" + *format );
415 return writer.
write( obj, _options, 4, 4 );
421 _filename +
" : no matching format" );
const std::string & fileName() const
get output file name
bool write(const T &obj, bool ascii=false, const std::string *format=0)
Finds the correct format and writes the object.
static Settings & settings()
Generic writer for every format of Aims object.
virtual std::string writtenObjectType() const
virtual std::string writtenObjectDataType() const
virtual bool write(const T &obj, bool ascii=false, const std::string *format=0)
Finds the correct format and writes the object.
virtual std::string writtenObjectFullType() const
static std::string basename(const std::string &)
Object reference(Object &value)
static void load(int verboseLevel=-1, bool forcereload=false)
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="")
virtual bool write(const T &obj, carto::Object options=carto::none(), int passbegin=1, int passend=4)
The class for EcatSino data write operation.
std::map< std::string, Object > Dictionary