A.I.M.S


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 FileFormat<T>* fileFormat( const std::string & format );
147  static const std::map<std::string, std::list<std::string> > & extensions();
148  static std::set<std::string> formats();
165  static void registerBaseFormats();
166  static std::string fileExtension( const std::string & filename );
167  static void init();
168 
169  private:
170  static std::map<std::string, FileFormat<T>*> & _formats();
171  static std::map<std::string, std::list<std::string> > &
172  _extensions();
173  static carto::Mutex & mutex();
174  };
175 
176 
178  {
179  public:
180  typedef std::set<std::string> (*FormatInfo)();
181  static void registerType( const std::string & objtype,
182  const std::string & datatype, FormatInfo info );
183  static bool hasType( const std::string & objtype,
184  const std::string & datatype );
185  static std::map<std::string, std::map<std::string, FormatInfo> > & types();
186  };
187 
188 }
189 
190 #endif
static void registerType(const std::string &objtype, const std::string &datatype, FormatInfo info)
static std::map< std::string, std::map< std::string, FormatInfo > > & types()
static void registerFormat(const std::string &formatID, FileFormat< T > *format, const std::vector< std::string > &extensions, const std::string &before="")
Definition: fileFormat_d.h:140
static bool hasType(const std::string &objtype, const std::string &datatype)
static std::string fileExtension(const std::string &filename)
Definition: fileFormat_d.h:126
static void registerBaseFormats()
builds base formats maps.
std::set< std::string >(* FormatInfo)()
Definition: fileFormat.h:180
Formats holder for each format of Aims object, used by Reader and Writer.
Definition: fileFormat.h:139
virtual ~FileFormat()
Definition: fileFormat_d.h:45
static const std::map< std::string, std::list< std::string > > & extensions()
Definition: fileFormat_d.h:104
virtual bool check(const std::string &filename, Finder &f) const =0
virtual bool read(const std::string &filename, T &obj, const carto::AllocatorContext &context, carto::Object options)=0
Generic finder / checker for all data objects and file formats This will replace the old AimsFinder...
Definition: finder.h:117
static FileFormat< T > * fileFormat(const std::string &format)
Definition: fileFormat_d.h:171
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:72
static std::set< std::string > formats()
Definition: fileFormat_d.h:183
virtual ~FinderFormat()
Object none()
Pointer to an empty aims::StructuringElement.
Low-level object IO format: each specific format has such a reader / writer.
Definition: fileFormat.h:61
Finder format checker.
Definition: fileFormat.h:88