soma-io 6.0.6
formatdictionary_d.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#ifndef SOMAIO_IO_FORMATDICTIONARY_D_H
35#define SOMAIO_IO_FORMATDICTIONARY_D_H
36//--- soma-io ----------------------------------------------------------------
38#include <soma-io/io/formatdictionary.h> // class declaration
39#include <soma-io/reader/formatreader.h> // map of
40#include <soma-io/writer/formatwriter.h> // map of
41//--- cartobase --------------------------------------------------------------
42#include <cartobase/type/types.h> // where is it used ?
43//--- system -----------------------------------------------------------------
44#include <string>
45#include <map>
46#include <set>
47#include <vector>
48//--- debug ------------------------------------------------------------------
49#include <cartobase/config/verbose.h>
50#define localMsg( message ) cartoCondMsg( 4, message, "FORMATDICTIONARY" )
51// localMsg must be undef at end of file
52//----------------------------------------------------------------------------
53
54namespace soma
55{
56
57 template <typename T>
58 std::map<std::string, FormatReader<T>*> &
59 FormatDictionary<T>::_readformats()
60 {
61 static std::map<std::string, FormatReader<T>*> form;
62 return form;
63 }
64
65 template <typename T>
66 std::map<std::string, FormatWriter<T>*> &
67 FormatDictionary<T>::_writeformats()
68 {
69 static std::map<std::string, FormatWriter<T>*> form;
70 return form;
71 }
72
73 template <typename T>
74 std::multimap<std::string, std::string> &
75 FormatDictionary<T>::_readextensions()
76 {
77 static std::multimap<std::string, std::string> ext;
78 return ext;
79 }
80
81 template <typename T>
82 std::multimap<std::string, std::string> &
83 FormatDictionary<T>::_writeextensions()
84 {
85 static std::multimap<std::string, std::string> ext;
86 return ext;
87 }
88
89 template <typename T>
90 const std::multimap<std::string, std::string> &
92 {
93 init();
94 return _readextensions();
95 }
96
97 template <typename T>
98 const std::multimap<std::string, std::string> &
100 {
101 init();
102 return _writeextensions();
103 }
104
105 template <typename T>
107 {
108 static bool initialized = false;
109 if( !initialized )
110 {
111// localMsg("initializing soma format dictionaries ...");
112// localMsg("read formats dictionary [" + carto::toString(&(_readformats())) + "] ...")
113// localMsg("write formats dictionary [" + carto::toString(&(_writeformats())) + "] ...")
114 initialized = true;
117 &readFormats );
119 &writeFormats );
121 }
122 }
123
124
125 template <typename T>
129
130
131 template <typename T>
132 void
133 FormatDictionary<T>::registerFormat( const std::string & format,
134 FormatReader<T>* formatObj,
135 const std::vector<std::string>
136 & extensions )
137 {
138 init();
139
140 FormatReader<T> *oldr = readFormat( format );
141 delete oldr;
142 _readformats()[ format ] = formatObj;
143
144 std::vector<std::string>::const_iterator ie, ee = extensions.end();
145 for( ie=extensions.begin(); ie!=ee; ++ie )
146 _readextensions().insert
147 ( std::pair<std::string, std::string>( *ie, format ) );
148 }
149
150
151 template <typename T>
152 void
153 FormatDictionary<T>::registerFormat( const std::string & format,
154 FormatWriter<T>* formatObj,
155 const std::vector<std::string>
156 & extensions )
157 {
158 init();
159
160 FormatWriter<T> *oldr = writeFormat( format );
161 delete oldr;
162 _writeformats()[ format ] = formatObj;
163
164 std::vector<std::string>::const_iterator ie, ee = extensions.end();
165 for( ie=extensions.begin(); ie!=ee; ++ie )
166 _writeextensions().insert
167 ( std::pair<std::string, std::string>( *ie, format ) );
168 }
169
170
171 template <typename T>
173 FormatDictionary<T>::readFormat( const std::string & format )
174 {
175 init();
176
177 typename std::map<std::string, FormatReader<T>*>::const_iterator i
178 = _readformats().find( format );
179 if( i == _readformats().end() )
180 return( 0 );
181 return( (*i).second );
182 }
183
184
185 template <typename T>
187 FormatDictionary<T>::writeFormat( const std::string & format )
188 {
189 init();
190
191 typename std::map<std::string, FormatWriter<T>*>::const_iterator i
192 = _writeformats().find( format );
193 if( i == _writeformats().end() )
194 return( 0 );
195 return( (*i).second );
196 }
197
198
199 template <typename T>
200 std::set<std::string> FormatDictionary<T>::readFormats()
201 {
202// localMsg("Retrieving soma read formats from format dictionary [" + carto::toString(&(_readformats())) + "] ...")
203 std::set<std::string> f;
204 typename std::map<std::string, FormatReader<T>*>::const_iterator
205 i, e = _readformats().end();
206 for( i=_readformats().begin(); i!=e; ++i )
207 f.insert( i->first );
208 return( f );
209 }
210
211
212 template <typename T>
213 std::set<std::string> FormatDictionary<T>::writeFormats()
214 {
215// localMsg("Retrieving soma write formats from format dictionary [" + carto::toString(&(_writeformats())) + "] ...")
216 std::set<std::string> f;
217 typename std::map<std::string, FormatWriter<T>*>::const_iterator
218 i, e = _writeformats().end();
219 for( i=_writeformats().begin(); i!=e; ++i )
220 f.insert( i->first );
221 return( f );
222 }
223
224}
225
226#undef localMsg
227
228#endif
std::string name()
static const std::multimap< std::string, std::string > & readExtensions()
static std::set< std::string > readFormats()
static const std::multimap< std::string, std::string > & writeExtensions()
static void registerFormat(const std::string &formatID, FormatReader< T > *format, const std::vector< std::string > &extensions)
static std::set< std::string > writeFormats()
static FormatWriter< T > * writeFormat(const std::string &format)
static void registerBaseFormats()
builds base formats maps.
static FormatReader< T > * readFormat(const std::string &format)
Low-level object IO reader specialized for a specific format.
Low-level object IO writer specialized for a specific format.
static void registerWriteType(const std::string &datatype, FormatInfo info)
static void registerReadType(const std::string &datatype, FormatInfo info)