aimsdata  4.7.0
Neuroimaging data handling
itemW_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_ITEMW_STL_H
35 #define AIMS_IO_ITEMW_STL_H
36 
37 #include <aims/io/defaultItemW.h>
38 #include <vector>
39 
40 namespace aims
41 {
42 
44  template <class T>
45  class DefaultItemWriter<std::vector<T> >
46  : public ItemWriter<std::vector<T> >
47  {
48  public:
49  DefaultItemWriter() : ItemWriter<std::vector<T> >() { }
50  virtual ~DefaultItemWriter() { }
51 
52  virtual void write( std::ostream & os,
53  const std::vector<T> & item ) const
54  { write( os, &item, 1 ); }
55  virtual void write( std::ostream & os, const std::vector<T> * pitem,
56  size_t n ) const;
57  virtual ItemWriter<std::vector<T> >* writer( const std::string & openmode
58  = "binar",
59  bool bswap = false ) const;
60  };
61 
62 
64  template <class T>
65  class DefaultBSwapItemWriter<std::vector<T> >
66  : public DefaultItemWriter<std::vector<T> >
67  {
68  public:
71 
72  virtual void write( std::ostream & os,
73  const std::vector<T> & item ) const
74  { write( os, &item, 1 ); }
75  virtual void write( std::ostream & os, const std::vector<T> * pitem,
76  size_t n ) const;
77  };
78 
79 
81  template <class T>
82  class DefaultAsciiItemWriter<std::vector<T> >
83  : public DefaultItemWriter<std::vector<T> >
84  {
85  public:
88 
89  virtual void write( std::ostream & os,
90  const std::vector<T> & item ) const
91  { write( os, &item, 1 ); }
92  virtual void write( std::ostream & os, const std::vector<T> * pitem,
93  size_t n ) const;
94  };
95 
96 
97  // definitions
98 
99  template<class T> ItemWriter<std::vector<T> >*
100  DefaultItemWriter<std::vector<T> >::writer( const std::string & openmode,
101  bool bswap ) const
102  {
103  if( openmode == "ascii" )
104  return( new DefaultAsciiItemWriter<std::vector<T> > );
105  if( bswap )
106  return( new DefaultBSwapItemWriter<std::vector<T> > );
107  return( new DefaultItemWriter<std::vector<T> > );
108  }
109 
110 
111  template <class T> inline void
113  const std::vector<T>* pitem,
114  size_t n ) const
115  {
117  unsigned p;
118  const std::vector<T> *ptr = pitem;
120 
121  for( p=0; p<n; ++p, ++ptr )
122  {
123  ir2.write( os, ptr->size() );
124  ir.write( os, &(*ptr)[0], ptr->size() );
125  }
126  }
127 
128 
129  template <class T> inline void
131  const std::vector<T>
132  * pitem,
133  size_t n ) const
134  {
136  unsigned p;
137  const std::vector<T> *ptr = pitem;
139 
140  for( p=0; p<n; ++p, ++ptr )
141  {
142  ir2.write( os, ptr->size() );
143  ir.write( os, &(*ptr)[0], ptr->size() );
144  }
145  }
146 
147 
148  template <class T> inline void
150  const std::vector<T>
151  * pitem,
152  size_t n ) const
153  {
155  unsigned p;
156  const std::vector<T> *ptr = pitem;
158 
159  for( p=0; p<n; ++p, ++ptr )
160  {
161  ir2.write( os, ptr->size() );
162  ir.write( os, &(*ptr)[0], ptr->size() );
163  }
164  }
165 
166 }
167 
168 #endif
Default low-levels writers.
Definition: defaultItemW.h:58
virtual ItemWriter< T > * writer(const std::string &openmode="binar", bool bswap=false) const
Definition: defaultItemW.h:139
virtual void write(std::ostream &os, const T &item) const
Definition: defaultItemW.h:159
STL namespace.
The class for EcatSino data write operation.
Definition: border.h:42
Low-level "small item" writer, used by higher-level file readers.
Definition: itemW.h:50
virtual void write(std::ostream &os, const std::vector< T > &item) const
Definition: itemW_stl.h:52
virtual void write(std::ostream &os, const T &item) const
Definition: defaultItemW.h:91
virtual void write(std::ostream &os, const std::vector< T > &item) const
Definition: itemW_stl.h:72
virtual void write(std::ostream &os, const std::vector< T > &item) const
Definition: itemW_stl.h:89
virtual void write(std::ostream &os, const T &item) const
Definition: defaultItemW.h:64