ODIN
fileio.h
1 /***************************************************************************
2  fileio.h - description
3  -------------------
4  begin : Fri Apr 6 2001
5  copyright : (C) 2000-2021 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef FILEIO_H
19 #define FILEIO_H
20 
21 //shortcut to check for type from string (templated function doesn work well with mingw - so we use macro)
22 #define IS_TYPE(type, name) (name==TypeTraits::type2label((type)0))
23 
24 #include <odindata/data.h>
25 #include <odindata/fileio_opts.h>
26 
27 
28 #define AUTODETECTSTR "autodetect"
29 #define AUTOTDATAYPESTR "automatic"
30 
31 
45 enum dataDim { timeDim=0, sliceDim, phaseDim, readDim, n_dataDim };
46 static const char* dataDimLabel[]={"time", "slice", "phase", "read"};
47 AVOID_CC_WARNING(dataDimLabel)
48 
49 
50 
52 // helper class to enable/disable tracing
53 class FileIOTrace {
54 
55  public:
59  static bool get_trace_status() {return do_trace;}
60 
64  static void set_trace_status(bool stat) {do_trace=stat;}
65 
66 
67  protected:
68  static logPriority loglevel() {if(get_trace_status()) return infoLog; else return normalDebug;}
69 
70 
71  private:
72  static bool do_trace;
73 
74 };
75 
76 
78 
82 class FileIO : public FileIOTrace {
83 
84  public:
85 
89  typedef STD_map<Protocol, Data<float,4> > ProtocolDataMap;
90 
97  static int autoread(ProtocolDataMap& pdmap, const STD_string& filename, const FileReadOpts& opts, const Protocol& protocol_template, ProgressMeter* progmeter=0);
98 
104  static int autowrite(const ProtocolDataMap& pdmap, const STD_string& filename, const FileWriteOpts& opts);
105 
110 
114  static STD_string autoformats_str(const STD_string& indent="");
115 
116 
117 
118  static const char* get_compName(); // For debugging FilieIO component
119 
120  private:
121 
122  static int read_dir(ProtocolDataMap& pdmap, const STD_string& dirname, const FileReadOpts& opts, const Protocol& protocol_template,ProgressMeter* progmeter=0);
123 
124 };
125 
127 
128 
132 class FileFormat {
133 
134  public:
135 
140 
144  static svector create_unique_filenames(const STD_string& filename, const FileIO::ProtocolDataMap& pdmap, const STD_string& par);
145 
149  static float voxel_extent(const Geometry& geometry, direction direction, int size);
150 
151 
152 
153 protected:
154  virtual ~FileFormat() {} // avoid compiler warnings
155 
159  static STD_string select_write_datatype(const Protocol &prot,const FileWriteOpts& opts);
160 
161  private:
162 
163  // limit access
164  friend class FileIO;
165 
166  virtual STD_string description() const = 0;
167 
168  virtual svector suffix() const = 0;
169 
170  virtual svector dialects() const = 0;
171 
172  virtual int read(Data<float,4>& data, const STD_string& filename, const FileReadOpts& opts, Protocol& prot);
173  virtual int read(FileIO::ProtocolDataMap& pdmap, const STD_string& filename, const FileReadOpts& opts, const Protocol& protocol_template);
174 
175  virtual int write(const Data<float,4>& data, const STD_string& filename, const FileWriteOpts& opts, const Protocol& prot);
176  virtual int write(const FileIO::ProtocolDataMap& pdmap, const STD_string& filename, const FileWriteOpts& opts);
177 
178  typedef STD_list<FileFormat*> FormatList;
179  typedef STD_map<STD_string, FormatList> FormatMap;
180  static FormatMap formats;
181 
182  static STD_string analyze_suffix(const STD_string& filename);
183 
184  static FileFormat* get_format(const STD_string& filename, const STD_string& override_suffix);
185 
186  static svector possible_formats();
187 
188  static STD_string formats_str(const STD_string& indent);
189 
190  static void format_error(const STD_string& filename);
191 
192 };
193 
194 
195 
202 #endif
static float voxel_extent(const Geometry &geometry, direction direction, int size)
static STD_string select_write_datatype(const Protocol &prot, const FileWriteOpts &opts)
void register_format()
static svector create_unique_filenames(const STD_string &filename, const FileIO::ProtocolDataMap &pdmap, const STD_string &par)
Definition: fileio.h:82
STD_map< Protocol, Data< float, 4 > > ProtocolDataMap
Definition: fileio.h:89
static svector autoformats()
static int autowrite(const ProtocolDataMap &pdmap, const STD_string &filename, const FileWriteOpts &opts)
static int autoread(ProtocolDataMap &pdmap, const STD_string &filename, const FileReadOpts &opts, const Protocol &protocol_template, ProgressMeter *progmeter=0)
static STD_string autoformats_str(const STD_string &indent="")
Geometry Settings.
Definition: geometry.h:179
Protocol proxy.
Definition: protocol.h:33
dataDim
Definition: fileio.h:45
direction
Definition: odinpara.h:41
int write(const STD_string &str, const STD_string &filename, fopenMode mode=overwriteMode)
logPriority
Definition: tjlog.h:48