aimsdata 6.0.0
Neuroimaging data handling
anytype_reader.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#ifndef AIMS_ANYTYPE_READER_H
34#define AIMS_ANYTYPE_READER_H
35
36// includes from STL
37#include <iostream>
38#include <string>
39
40// includes from AIMS
41#include "aims/data/data_g.h"
42#include "aims/io/process.h"
44
45namespace aims
46{
47
48 namespace
49 {
52 // TODO: Add specializations for type couples we wish to use.
53 // NB: The reason why it is not a member class of RawConverterWithAllocation is that
54 // it then cannot be partially specialized :(
55 template < typename T1, typename T2 >
56 struct Allocator;
57
60 template < typename T1, typename T2 >
61 struct Allocator< AimsData<T1>, AimsData<T2> >
62 {
64 void operator()(const AimsData<T1> & im1, AimsData<T2> & im2) const
65 {
66 im2 = AimsData<T2>(im1.dimX(), im1.dimY(), im1.dimZ());
67 im2.setSizeX(im1.sizeX());
68 im2.setSizeY(im1.sizeY());
69 im2.setSizeZ(im1.sizeZ());
70 }
71 };
72 }
73
74 namespace
75 {
78 template < typename T1, typename T2 >
79 class RawConverterWithAllocation
80 {
81 public: // constructors
82
85 RawConverterWithAllocation()
86 : m_cartoConverter()
87 , m_allocator()
88 {}
89
90 public: // functions
91
94 void convert(const T1 & in, T2 & out) const
95 {
96 m_allocator(in, out);
97 m_cartoConverter.convert(in, out);
98 }
99
100 private: // data
101
102 carto::RawConverter<T1, T2> m_cartoConverter;
103 Allocator<T1,T2> m_allocator;
104 };
105 }
106
107
108 namespace
109 {
112 // TODO: If found useful elsewhere, could be de-anonymized and put in a separate file.
113 template < template <typename, typename> class TArg2 >
114 struct TArgWrapper2
115 {
116 template <typename T1, typename T2 >
117 struct Type
118 {
119 typedef TArg2<T1, T2> type;
120 };
121 };
122 }
123
124 //----------------------------------------------------------------------------------
125
126 //------------------------//
127 // AnyTypeReaderProcess //
128 //------------------------//
129
136 template < typename T, typename TConvertorFamily = TArgWrapper2<RawConverterWithAllocation> >
138 {
139 public: // typedefs
140 typedef T return_type;
141 typedef TConvertorFamily convertor_type;
142
143 public: // constructors
144
150 explicit AnyTypeReaderProcess(const T & init);
151
152 public: // set & get
153
155 T & get() { return m_res; }
157 T const & get() const { return m_res; }
158
159 private: // functions
160
161 void registerProcesses();
162
163 private: // data
164
165 T m_res;
166 };
167
168
169 //----------------------------------------------------------------------------------
170
171 //-----------------//
172 // AnyTypeReader //
173 //-----------------//
174
192
193 template < typename T, typename TConvertorFamily = TArgWrapper2<RawConverterWithAllocation> >
194 // private inheritance to hide Process members.
195 class AnyTypeReader : private AnyTypeReaderProcess<T, TConvertorFamily>
196 {
197 public: // typedefs
198
200
201 public: // constructors
202
205 explicit AnyTypeReader(std::string filename);
206
207 public: // functions
208
211 void read(T & out);
212
213 private: // data
214
215 std::string m_filename;
216 };
217
218} // namespace aims
219
220
221// implementation
223
224#endif
225
void setSizeY(float sizey)
float sizeX() const
int dimY() const
int dimX() const
float sizeZ() const
float sizeY() const
int dimZ() const
void setSizeZ(float sizez)
void setSizeX(float sizex)
AnyTypeReaderProcess(const T &init)
Initialize result with init.
T const & get() const
Get data loaded from file.
T & get()
Get data loaded from file.
TConvertorFamily convertor_type
void read(T &out)
read file and get result.
AnyTypeReader(std::string filename)
initialize with the name of the file to be read.
AnyTypeReaderProcess< T, TConvertorFamily > Base
Process()
Attempts to read the header of filename and, if successful, calls the operator() of the process \proc...
The class for EcatSino data write operation.
carto::AllocatorContext Allocator
compatibility typedef - NEVER USE IT
Definition allocator.h:51