aimsdata  5.1.2
Neuroimaging data handling
fileFormat.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 /*
35  * Data reader class
36  */
37 #ifndef AIMS_IO_FORMAT_H
38 #define AIMS_IO_FORMAT_H
39 
41 #include <aims/def/general.h>
42 #include <aims/io/datatypecode.h>
43 #include <string>
44 #include <map>
45 #include <vector>
46 #include <set>
47 
48 
49 namespace carto
50 {
51  class Mutex;
52 }
53 
54 namespace aims
55 {
56  class Finder;
57 
61  template<class T> class FileFormat
62  {
63  public:
64  virtual ~FileFormat();
65  virtual bool read( const std::string & filename, T & obj,
66  const carto::AllocatorContext & context,
67  carto::Object options ) = 0;
71  virtual T* read( const std::string & filename,
72  const carto::AllocatorContext & context,
73  carto::Object options );
77  virtual bool write( const std::string &, const T &,
78  carto::Object options = carto::none() );
79  };
80 
81 
89  {
90  public:
91  virtual ~FinderFormat();
92  virtual bool check( const std::string & filename, Finder & f ) const = 0;
93  };
94 
95 
139  template<class T> class FileFormatDictionary
140  {
141  public:
142  static void registerFormat( const std::string & formatID,
143  FileFormat<T>* format,
144  const std::vector<std::string> & extensions,
145  const std::string & before = "" );
146  static void unregisterFormat( const std::string & formatID );
147  static FileFormat<T>* fileFormat( const std::string & format );
148  static const std::map<std::string, std::list<std::string> > & extensions();
149  static std::set<std::string> formats();
166  static void registerBaseFormats();
167  static std::string fileExtension( const std::string & filename );
168  static void init();
169 
170  private:
171  static std::map<std::string, FileFormat<T>*> & _formats();
172  static std::map<std::string, std::list<std::string> > &
173  _extensions();
174  static carto::Mutex & mutex();
175  };
176 
177 
179  {
180  public:
181  typedef std::set<std::string> (*FormatInfo)();
182  static void registerType( const std::string & objtype,
183  const std::string & datatype, FormatInfo info );
184  static bool hasType( const std::string & objtype,
185  const std::string & datatype );
186  static std::map<std::string, std::map<std::string, FormatInfo> > & types();
187  };
188 
189 }
190 
191 #endif
Formats holder for each format of Aims object, used by Reader and Writer.
Definition: fileFormat.h:140
static FileFormat< T > * fileFormat(const std::string &format)
Definition: fileFormat_d.h:199
static std::set< std::string > formats()
Definition: fileFormat_d.h:211
static std::string fileExtension(const std::string &filename)
Definition: fileFormat_d.h:126
static void registerBaseFormats()
builds base formats maps.
static const std::map< std::string, std::list< std::string > > & extensions()
Definition: fileFormat_d.h:105
static void registerFormat(const std::string &formatID, FileFormat< T > *format, const std::vector< std::string > &extensions, const std::string &before="")
Definition: fileFormat_d.h:132
static void unregisterFormat(const std::string &formatID)
Definition: fileFormat_d.h:163
Low-level object IO format: each specific format has such a reader / writer.
Definition: fileFormat.h:62
virtual bool write(const std::string &, const T &, carto::Object options=carto::none())
the base class has a default implementation which only returns false so if your new format only suppo...
Definition: fileFormat_d.h:73
virtual bool read(const std::string &filename, T &obj, const carto::AllocatorContext &context, carto::Object options)=0
virtual ~FileFormat()
Definition: fileFormat_d.h:46
Finder format checker.
Definition: fileFormat.h:89
virtual ~FinderFormat()
virtual bool check(const std::string &filename, Finder &f) const =0
Generic finder / checker for all data objects and file formats This will replace the old AimsFinder.
Definition: finder.h:118
static bool hasType(const std::string &objtype, const std::string &datatype)
static void registerType(const std::string &objtype, const std::string &datatype, FormatInfo info)
std::set< std::string >(* FormatInfo)()
Definition: fileFormat.h:181
static std::map< std::string, std::map< std::string, FormatInfo > > & types()
The class for EcatSino data write operation.
Definition: borderfiller.h:13
Object none()