aimsdata 6.0.0
Neuroimaging data handling
itemR_stl.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 AIMS_IO_ITEMR_STL_H
35#define AIMS_IO_ITEMR_STL_H
36
38#include <vector>
39
40namespace aims
41{
42
44 template <class T>
45 class DefaultItemReader<std::vector<T> >
46 : public ItemReader<std::vector<T> >
47 {
48 public:
49 DefaultItemReader() : ItemReader<std::vector<T> >() { }
50 virtual ~DefaultItemReader() { }
51
52 virtual void read( std::istream & os, std::vector<T> & item ) const
53 { read( os, &item, 1 ); }
54 virtual void read( std::istream & os, std::vector<T> * pitem,
55 size_t n ) const;
56 virtual ItemReader<std::vector<T> >* reader( const std::string & openmode
57 = "binar",
58 bool bswap = false ) const;
59 };
60
61
63 template <class T>
64 class DefaultBSwapItemReader<std::vector<T> >
65 : public DefaultItemReader<std::vector<T> >
66 {
67 public:
70
71 virtual void read( std::istream & os, std::vector<T> & item ) const
72 { read( os, &item, 1 ); }
73 virtual void read( std::istream & os, std::vector<T> * pitem,
74 size_t n ) const;
75 };
76
77
79 template <class T>
80 class DefaultAsciiItemReader<std::vector<T> >
81 : public DefaultItemReader<std::vector<T> >
82 {
83 public:
86
87 virtual void read( std::istream & os, std::vector<T> & item ) const
88 { read( os, &item, 1 ); }
89 virtual void read( std::istream & os, std::vector<T> * pitem,
90 size_t n ) const;
91 };
92
93
94 // definitions
95
96 template<class T> ItemReader<std::vector<T> >*
97 DefaultItemReader<std::vector<T> >::reader( const std::string & openmode,
98 bool bswap ) const
99 {
100 if( openmode == "ascii" )
101 return( new DefaultAsciiItemReader<std::vector<T> > );
102 if( bswap )
103 return( new DefaultBSwapItemReader<std::vector<T> > );
104 return( new DefaultItemReader<std::vector<T> > );
105 }
106
107
108 template <class T> inline void
110 std::vector<T>* pitem,
111 size_t n ) const
112 {
114 unsigned p;
115 std::vector<T> *ptr = pitem;
117 uint32_t nitem;
118
119 for( p=0; p<n; ++p, ++ptr )
120 {
121 ir2.read( os, nitem );
122 *ptr = std::vector<T>( nitem );
123 ir.read( os, &(*ptr)[0], nitem );
124 }
125 }
126
127
128 template <class T> inline void
130 std::vector<T>
131 * pitem,
132 size_t n ) const
133 {
135 unsigned p;
136 std::vector<T> *ptr = pitem;
138 uint32_t nitem;
139
140 for( p=0; p<n; ++p, ++ptr )
141 {
142 ir2.read( os, nitem );
143 *ptr = std::vector<T>( nitem );
144 ir.read( os, &(*ptr)[0], nitem );
145 }
146 }
147
148
149 template <class T> inline void
151 std::vector<T> * pitem,
152 size_t n ) const
153 {
155 unsigned p;
156 std::vector<T> *ptr = pitem;
158 uint32_t nitem;
159
160 for( p=0; p<n; ++p, ++ptr )
161 {
162 ir2.read( os, nitem );
163 *ptr = std::vector<T>( nitem );
164 ir.read( os, &(*ptr)[0], nitem );
165 }
166 }
167
168}
169
170#endif
virtual void read(std::istream &os, std::vector< T > &item) const
Definition itemR_stl.h:87
virtual void read(std::istream &is, T &item) const
virtual void read(std::istream &os, std::vector< T > &item) const
Definition itemR_stl.h:71
virtual void read(std::istream &is, T &item) const
virtual ItemReader< std::vector< T > > * reader(const std::string &openmode="binar", bool bswap=false) const
Definition itemR_stl.h:97
virtual void read(std::istream &os, std::vector< T > &item) const
Definition itemR_stl.h:52
virtual ItemReader< T > * reader(const std::string &openmode="binar", bool bswap=false) const
virtual void read(std::istream &is, T &item) const
Low-level "small item" reader, used by higher-level file readers.
Definition itemR.h:99
The class for EcatSino data write operation.
STL namespace.