soma-io  5.1.2
areader.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_READER_AREADER_H
35 #define SOMAIO_READER_AREADER_H
36 //--- soma-io ----------------------------------------------------------------
39 //--- cartobase --------------------------------------------------------------
41 #ifndef CARTOBASE_OBJECT_SYNTAX_H
42  #include <cartobase/object/syntax.h>
43 #endif
45 //----------------------------------------------------------------------------
46 
47 namespace soma
48 {
49 
50  //=========================================================================
51  // C L A S S D E C L A R A T I O N
52  //=========================================================================
53 
56  {
57 
58  public:
59 
60  //------------------------------------------------------------------------
62  //------------------------------------------------------------------------
64 
65  typedef void (*Helper)( carto::GenericObject&, const std::string&,
66  DataSource &);
67  typedef std::map<std::string,Helper> HelperSet;
68 
70 
71  //------------------------------------------------------------------------
73  //------------------------------------------------------------------------
75 
77  const carto::SyntaxSet& rules,
78  const HelperSet& helpers = HelperSet() );
79 
85  AttributedReader(const std::string& filename,
86  const carto::SyntaxSet& rules,
87  const HelperSet& helpers = HelperSet());
88 
94  const HelperSet& helpers = HelperSet());
95 
98  virtual ~AttributedReader();
99 
101 
102  //------------------------------------------------------------------------
104  //------------------------------------------------------------------------
106 
110  void open(const std::string& filename);
113  void attach( std::istream & stream, int line_num = 1 );
114 
117  void close();
118  carto::rc_ptr<DataSource> dataSource() { return _datasource; }
119 
121 
122  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
126 
128  virtual std::string name() const;
129 
131  int line() const;
132 
134 
135  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
139 
143  bool operator!() const;
144 
148  bool is_open() const;
149 
153  bool eof() const;
154 
156 
157  protected:
158 
159  //------------------------------------------------------------------------
161  //------------------------------------------------------------------------
163 
169  const std::string& semantic);
170 
171  // DO NOT USE! DEPRECIATED
173  const std::string& semantic)
174  __attribute__((__deprecated__));
175 
177 
178  //------------------------------------------------------------------------
180  //------------------------------------------------------------------------
182 
185 
188 
191 
193 
194  private:
195 
198  void init();
199 
200  //------------------------------------------------------------------------
202  //------------------------------------------------------------------------
204 
207 
209  AttributedReader& operator=(const AttributedReader&);
210 
212  };
213 
214 }
215 
216 #endif
#define CARTOBASE_API
#define __attribute__(a)
To read GenericObject from a file.
Definition: areader.h:56
AttributedReader(const carto::SyntaxSet &rules, const HelperSet &helpers=HelperSet())
configure the parameters
virtual ~AttributedReader()
clean up
void close()
detach or close the stream
std::map< std::string, Helper > HelperSet
Definition: areader.h:67
carto::rc_ptr< DataSource > dataSource()
Definition: areader.h:118
HelperSet _helpers
helper functions read basic data type
Definition: areader.h:190
AttributedReader(carto::rc_ptr< DataSource > ds, const carto::SyntaxSet &rules, const HelperSet &helpers=HelperSet())
carto::SyntaxSet _rules
rules for every syntactic attribute
Definition: areader.h:184
bool operator!() const
return the status of the stream
carto::rc_ptr< DataSource > _datasource
filtering stream to read from
Definition: areader.h:187
bool eof() const
have we hit EOF?
void readAttribute(carto::GenericObject &object, const std::string &semantic)
construct the value of a semantic attribute
virtual std::string name() const
name of the file to read from
void open(const std::string &filename)
open a new file
void attach(std::istream &stream, int line_num=1)
attach to an existing istream
AttributedReader(const std::string &filename, const carto::SyntaxSet &rules, const HelperSet &helpers=HelperSet())
configure the parameters
void readAttribute(carto::GenericObject *object, const std::string &semantic) __attribute__((__deprecated__))
bool is_open() const
is the stream open?
void attach(carto::rc_ptr< DataSource > ds)
Abstraction layer for various data sources (file, buffer, socket...).
Definition: datasource.h:65
std::map< std::string, Syntax > SyntaxSet
Definition: allocator.h:49