• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List

fileio.h

00001 /***************************************************************************
00002                           fileio.h  -  description
00003                              -------------------
00004     begin                : Fri Apr 6 2001
00005     copyright            : (C) 2001 by Thies Jochimsen
00006     email                : jochimse@cns.mpg.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef FILEIO_H
00019 #define FILEIO_H
00020 
00021 //shortcut to check for type from string (templated function doesn work well with mingw - so we use macro)
00022 #define IS_TYPE(type, name) (name==TypeTraits::type2label((type)0))
00023 
00024 #include <odindata/data.h>
00025 #include <odindata/fileio_opts.h>
00026 
00027 
00028 #define AUTODETECTSTR "autodetect"
00029 #define AUTOTDATAYPESTR "automatic"
00030 
00031 
00045 enum                      dataDim { timeDim=0, sliceDim, phaseDim, readDim, n_dataDim };
00046 static const char* dataDimLabel[]={"time",    "slice",  "phase",  "read"};
00047 
00048 
00052 class FileIO {
00053 
00054  public:
00055 
00059   typedef STD_map<Protocol, Data<float,4> > ProtocolDataMap;
00060 
00067   static int autoread(ProtocolDataMap& pdmap, const STD_string& filename, const FileReadOpts& opts, const Protocol& protocol_template,ProgressMeter* progmeter=0);
00068 
00074   static int autowrite(const ProtocolDataMap& pdmap, const STD_string& filename, const FileWriteOpts& opts);
00075 
00079   static svector autoformats();
00080 
00084   static STD_string autoformats_str(const STD_string& indent="");
00085 
00086 
00090   static bool get_trace_status() {return do_trace;}
00091 
00095   static void set_trace_status(bool stat) {do_trace=stat;}
00096 
00097 
00098   static const char* get_compName(); // For debugging FilieIO component
00099 
00100  private:
00101   static logPriority loglevel() {if(do_trace) return infoLog; else return normalDebug;}
00102   static bool do_trace;
00103 
00104   static int read_dir(ProtocolDataMap& pdmap, const STD_string& dirname, const FileReadOpts& opts, const Protocol& protocol_template,ProgressMeter* progmeter=0);
00105 
00106 };
00107 
00109 
00110 
00114 class FileFormat {
00115 
00116  public:
00117 
00121   void register_format();
00122 
00126   static svector create_unique_filenames(const STD_string& filename, const FileIO::ProtocolDataMap& pdmap, const STD_string& par);
00127 
00131   static float voxel_extent(const Geometry& geometry, direction direction, int size);
00132 
00133 
00134 
00135 protected:
00136   virtual ~FileFormat() {} // avoid compiler warnings
00137 
00141   static STD_string select_write_datatype(const Protocol &prot,const FileWriteOpts& opts);
00142 
00143  private:
00144 
00145   // limit access
00146   friend class FileIO;
00147 
00148   virtual STD_string description() const = 0;
00149 
00150   virtual svector suffix() const = 0;
00151 
00152   virtual svector dialects() const = 0;
00153 
00154   virtual int read(Data<float,4>& data, const STD_string& filename, const FileReadOpts& opts, Protocol& prot);
00155   virtual int read(FileIO::ProtocolDataMap& pdmap, const STD_string& filename, const FileReadOpts& opts, const Protocol& protocol_template);
00156 
00157   virtual int write(const Data<float,4>& data, const STD_string& filename, const FileWriteOpts& opts, const Protocol& prot);
00158   virtual int write(const FileIO::ProtocolDataMap& pdmap, const STD_string& filename, const FileWriteOpts& opts);
00159 
00160   typedef STD_list<FileFormat*> FormatList;
00161   typedef STD_map<STD_string, FormatList> FormatMap;
00162   static FormatMap formats;
00163 
00164   static STD_string analyze_suffix(const STD_string& filename);
00165 
00166   static FileFormat* get_format(const STD_string& filename, const STD_string& override_suffix);
00167 
00168   static svector possible_formats();
00169 
00170   static STD_string formats_str(const STD_string& indent);
00171 
00172   static void format_error(const STD_string& filename);
00173 
00174 };
00175 
00176 
00177 
00184 #endif

Generated on Tue Dec 18 2012 15:11:14 by  doxygen 1.7.1