fileio.h
1 /***************************************************************************
2  fileio.h - description
3  -------------------
4  begin : Fri Apr 6 2001
5  copyright : (C) 2000-2015 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 
53 class FileIO {
54 
55  public:
56 
60  typedef STD_map<Protocol, Data<float,4> > ProtocolDataMap;
61 
68  static int autoread(ProtocolDataMap& pdmap, const STD_string& filename, const FileReadOpts& opts, const Protocol& protocol_template,ProgressMeter* progmeter=0);
69 
75  static int autowrite(const ProtocolDataMap& pdmap, const STD_string& filename, const FileWriteOpts& opts);
76 
80  static svector autoformats();
81 
85  static STD_string autoformats_str(const STD_string& indent="");
86 
87 
91  static bool get_trace_status() {return do_trace;}
92 
96  static void set_trace_status(bool stat) {do_trace=stat;}
97 
98 
99  static const char* get_compName(); // For debugging FilieIO component
100 
101  private:
102  static logPriority loglevel() {if(do_trace) return infoLog; else return normalDebug;}
103  static bool do_trace;
104 
105  static int read_dir(ProtocolDataMap& pdmap, const STD_string& dirname, const FileReadOpts& opts, const Protocol& protocol_template,ProgressMeter* progmeter=0);
106 
107 };
108 
110 
111 
115 class FileFormat {
116 
117  public:
118 
122  void register_format();
123 
127  static svector create_unique_filenames(const STD_string& filename, const FileIO::ProtocolDataMap& pdmap, const STD_string& par);
128 
132  static float voxel_extent(const Geometry& geometry, direction direction, int size);
133 
134 
135 
136 protected:
137  virtual ~FileFormat() {} // avoid compiler warnings
138 
142  static STD_string select_write_datatype(const Protocol &prot,const FileWriteOpts& opts);
143 
144  private:
145 
146  // limit access
147  friend class FileIO;
148 
149  virtual STD_string description() const = 0;
150 
151  virtual svector suffix() const = 0;
152 
153  virtual svector dialects() const = 0;
154 
155  virtual int read(Data<float,4>& data, const STD_string& filename, const FileReadOpts& opts, Protocol& prot);
156  virtual int read(FileIO::ProtocolDataMap& pdmap, const STD_string& filename, const FileReadOpts& opts, const Protocol& protocol_template);
157 
158  virtual int write(const Data<float,4>& data, const STD_string& filename, const FileWriteOpts& opts, const Protocol& prot);
159  virtual int write(const FileIO::ProtocolDataMap& pdmap, const STD_string& filename, const FileWriteOpts& opts);
160 
161  typedef STD_list<FileFormat*> FormatList;
162  typedef STD_map<STD_string, FormatList> FormatMap;
163  static FormatMap formats;
164 
165  static STD_string analyze_suffix(const STD_string& filename);
166 
167  static FileFormat* get_format(const STD_string& filename, const STD_string& override_suffix);
168 
169  static svector possible_formats();
170 
171  static STD_string formats_str(const STD_string& indent);
172 
173  static void format_error(const STD_string& filename);
174 
175 };
176 
177 
178 
185 #endif
STD_map< Protocol, Data< float, 4 > > ProtocolDataMap
Definition: fileio.h:60
logPriority
Definition: tjlog.h:48
dataDim
Definition: fileio.h:45
Geometry Settings.
Definition: geometry.h:179
static bool get_trace_status()
Definition: fileio.h:91
static svector create_unique_filenames(const STD_string &filename, const FileIO::ProtocolDataMap &pdmap, const STD_string &par)
int write(const STD_string &str, const STD_string &filename, fopenMode mode=overwriteMode)
static STD_string select_write_datatype(const Protocol &prot, const FileWriteOpts &opts)
static float voxel_extent(const Geometry &geometry, direction direction, int size)
void register_format()
Protcol proxy.
Definition: protocol.h:33
Definition: fileio.h:53
direction
Definition: odinpara.h:38
static void set_trace_status(bool stat)
Definition: fileio.h:96