soma-io  5.1.2
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 
34 #ifndef SOMAIO_IO_READER_H
35 #define SOMAIO_IO_READER_H
36 //--- soma-io ----------------------------------------------------------------
40 //--- cartobase --------------------------------------------------------------
42 //--- system -----------------------------------------------------------------
43 #include <string>
44 //----------------------------------------------------------------------------
45 
46 namespace soma
47 {
48 
74  template <typename T>
75  class Reader
76  {
77  public:
78  //========================================================================
79  // C O N S T R U C T O R S
80  //========================================================================
81  Reader();
82  Reader( const std::string & filename );
85  Reader( std::istream & stream );
86  virtual ~Reader();
87 
88  //========================================================================
89  // R E A D I N G
90  //========================================================================
101  virtual bool read( T & obj, carto::Object header = carto::none(),
102  int passbegin = 1, int passend = 4 );
103 
118  virtual T* read( carto::Object header = carto::none(),
119  int passbegin = 1, int passend = 4 );
120 
121  //========================================================================
122  // D A T A S O U R C E I N F O
123  //========================================================================
125  { return _datasourceinfo; }
127  { return _datasourceinfo; }
128 
129  //========================================================================
130  // A L L O C A T O R
131  //========================================================================
132  void setAllocatorContext( const AllocatorContext & ac );
133  const AllocatorContext & allocatorContext() const;
134 
135  //========================================================================
136  // O P T I O N S
137  //========================================================================
139  carto::Object options() const;
141 
142  //========================================================================
143  // D A T A S O U R C E
144  //========================================================================
145  // these methods are kept for compatibility. They manipulate the "default"
146  // datasource
150  void attach( const std::string & filename, offset_t offset = 0 );
151  void attach( std::istream & stream );
152 
153  //========================================================================
154  // C O N T R O L
155  //========================================================================
156  void flush();
157  void close();
158  // void flushAll();
159  // void closeAll();
160 
161  //========================================================================
162  // U T I L I T I E S
163  //========================================================================
164  // is it actually used or implemented somewhere ?
165  static std::string extension( const std::string & filename );
166 
167  protected:
171  };
172 
173  extern template class Reader<carto::GenericObject>;
174  extern template class Reader<carto::Object>;
175 }
176 
177 //============================================================================
178 // S T R E A M O P E R A T O R
179 //============================================================================
180 template <class T>
181 inline soma::Reader<T> &
182 operator >> ( soma::Reader<T> & reader, T & thing )
183 {
184  reader.read( thing );
185  return reader;
186 }
187 
188 #endif
Allocation context.
Definition: allocator.h:261
Generic reader for every format of Cartograph object.
Definition: reader.h:76
void close()
Definition: reader_d.h:205
void setAllocatorContext(const AllocatorContext &ac)
Definition: reader_d.h:107
const carto::rc_ptr< DataSourceInfo > & dataSourceInfo() const
Definition: reader.h:124
AllocatorContext _alloccontext
Definition: reader.h:169
static std::string extension(const std::string &filename)
const carto::rc_ptr< DataSource > dataSource() const
Definition: reader_d.h:177
carto::Object options() const
Definition: reader_d.h:128
carto::Object _options
Definition: reader.h:170
virtual bool read(T &obj, carto::Object header=carto::none(), int passbegin=1, int passend=4)
Finds the correct format and reads the object.
Definition: reader_d.h:223
void flush()
Definition: reader_d.h:197
const AllocatorContext & allocatorContext() const
Definition: reader_d.h:113
virtual ~Reader()
Definition: reader_d.h:99
void setOptions(carto::Object options)
Definition: reader_d.h:122
carto::rc_ptr< DataSourceInfo > & dataSourceInfo()
Definition: reader.h:126
void attach(carto::rc_ptr< DataSource > ds)
Definition: reader_d.h:143
carto::rc_ptr< DataSourceInfo > _datasourceinfo
Definition: reader.h:168
Object none()
Definition: allocator.h:49
unsigned long long offset_t
Offsets are 64 bits if supported.
Definition: datasource.h:51
soma::Reader< T > & operator>>(soma::Reader< T > &reader, T &thing)
Definition: reader.h:182