aimsdata 6.0.0
Neuroimaging data handling
anytype_reader_details.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_DETAILS_H
34#define AIMS_ANYTYPE_READER_DETAILS_H
35
38
39// includes from STL
40#include <limits>
41
42// includes from AIMS
43#include "aims/io/finder.h"
45
46namespace aims
47{
48
49 namespace
50 {
51 // TODO: should add traits to the whole scheme to call the convertor. Also to get some error
52 // checking from converter -- right now, it always returns true.
53 template < typename TCaller, typename TFile >
54 bool anytype_reader(Process & p, const std::string & filein, Finder & f)
55 {
56 typedef typename TCaller::return_type return_type;
57 typedef typename TCaller::convertor_type::template Type<TFile, return_type>::type convertor_type;
58
59 // restore true caller type
60 TCaller & atr = dynamic_cast<TCaller &>(p);
61
62 // read data with original type
63 TFile data;
64 Reader<TFile> r(filein);
65 std::string format = f.format();
66 r.read(data, 0, &format);
67
68 // converting to desired type
69 convertor_type convert;
70 convert.convert(data, atr.get());
71
72 return true;
73 }
74 }
75
76 //-----------------------------------------------------------------------------------
77
78
79 template < typename T, typename TConvertorFamily >
81 : m_res(init)
82 {
83 this->registerProcesses();
84 }
85
86
87 template < typename T, typename TConvertorFamily >
88 void AnyTypeReaderProcess<T, TConvertorFamily>::registerProcesses()
89 {
91
92 // TODO: other file types can be added for other needs
93 registerProcessType("Volume", "S8", &anytype_reader<Self, AimsData< int8_t > >);
94 registerProcessType("Volume", "U8", &anytype_reader<Self, AimsData< uint8_t > >);
95 registerProcessType("Volume", "S16", &anytype_reader<Self, AimsData< int16_t > >);
96 registerProcessType("Volume", "U16", &anytype_reader<Self, AimsData< uint16_t > >);
97 registerProcessType("Volume", "S32", &anytype_reader<Self, AimsData< int32_t > >);
98 registerProcessType("Volume", "U32", &anytype_reader<Self, AimsData< uint32_t > >);
99 registerProcessType("Volume", "FLOAT", &anytype_reader<Self, AimsData< float > >);
100 registerProcessType("Volume", "DOUBLE", &anytype_reader<Self, AimsData< double > >);
101 }
102
103
104 //-----------------------------------------------------------------------------------
105
106 template < typename T, typename TConvertorFamily >
108 : Base((T()))
109 , m_filename(filename)
110 {}
111
112
113 template < typename T, typename TConvertorFamily >
115 {
116 this->execute(m_filename);
117 out = this->get();
118 }
119
120
121
122} // namespace aims
123
124#endif
125
A process to read an object of type T, even if the type on file is different.
AnyTypeReaderProcess(const T &init)
Initialize result with init.
T & get()
Get data loaded from file.
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
Generic finder / checker for all data objects and file formats This will replace the old AimsFinder.
Definition finder.h:118
Link mechanism between the Finder and a process operating on arbitrary data types.
Definition process.h:200
bool execute(const std::string &filename)
Executes the process on the object / data type found in the given file.
Generic reader for every format of Aims object.
Definition reader.h:70
The class for EcatSino data write operation.