soma-io  5.0.5
pythonreader.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_PYTHONREADER_H
35 #define SOMAIO_READER_PYTHONREADER_H
36 //--- soma-io ----------------------------------------------------------------
38 //--- cartobase --------------------------------------------------------------
42 //--- system -----------------------------------------------------------------
43 #include <iostream>
44 //----------------------------------------------------------------------------
45 
46 namespace soma
47 {
48  class DataSource;
49 
51  {
52  public:
54  const std::string &,
55  PythonReader & );
56  typedef std::map<std::string, Helper> HelperSet;
57 
58  PythonReader( const std::string& filename ,
59  const carto::SyntaxSet& rules = carto::SyntaxSet(),
60  const HelperSet& helpers = HelperSet() );
62  const HelperSet& helpers = HelperSet() );
65  const carto::SyntaxSet& rules = carto::SyntaxSet(),
66  const HelperSet& helpers = HelperSet() );
67  virtual ~PythonReader();
68 
69  virtual carto::GenericObject* read();
73  virtual void read( carto::GenericObject & );
74  virtual void read( carto::Object & );
76  void readDictionary( carto::GenericObject & obj );
78  void readDictionary2( carto::GenericObject & obj );
80  void readIntDictionary2( carto::TypedObject<carto::IntDictionary> & obj );
81 
82 
84  void open( const std::string& filename )
85  __attribute__((__deprecated__("use attach() instead")));
86  void close();
88  void attach( std::istream & s, int line_num = 1 );
89  void attach( carto::rc_ptr<DataSource> ds );
90  void attach( const std::string& filename );
91  carto::rc_ptr<DataSource> dataSource();
93  virtual std::string name() const;
94  int line() const;
95  std::string lineString() const;
97  bool operator!() const;
99  bool is_open() const;
101  bool eof() const;
103  const HelperSet & helpers() const;
104  HelperSet & helpers();
105  const carto::SyntaxSet & syntaxes() const;
106  carto::SyntaxSet & syntaxes();
107 
111  std::string readUntil(const std::string& s);
114  void skipUntil(const std::string& s);
118  std::string readWhile(const std::string& s);
122  unsigned skipWhile(const std::string& s);
123  carto::GenericObject* read( carto::GenericObject *parent,
124  const std::string & semantic );
125  std::string readVariableName();
130  bool readSyntax( std::string & syntax );
131  std::string readString( char separator, unsigned & charsread );
132 
135  static carto::GenericObject* dictHelper( carto::GenericObject *,
136  const std::string&,
137  PythonReader & r );
138 
139  static carto::GenericObject* propertySetHelper(carto::GenericObject *,
140  const std::string&,
141  PythonReader & r );
142 
143  template<typename T>
144  static carto::GenericObject* genericSequenceHelper( carto::GenericObject *,
145  const std::string&,
146  PythonReader & r );
147 
148  template<typename T>
149  static carto::GenericObject* genericDictHelper( carto::GenericObject *,
150  const std::string&,
151  PythonReader & r );
152 
153  protected:
154  void init( const HelperSet & helpers );
155 
156  private:
157  struct Private;
158  Private *d;
159  };
160 
161 }
162 
163 namespace carto
164 {
167 }
168 
169 #endif
#define DECLARE_GENERIC_OBJECT_TYPE(T)
#define __deprecated__(msg)
std::map< std::string, Helper > HelperSet
Definition: pythonreader.h:56
Definition: allocator.h:48
std::map< std::string, Syntax > SyntaxSet
#define CARTOBASE_API
carto::GenericObject *(* Helper)(carto::GenericObject *, const std::string &, PythonReader &)
Definition: pythonreader.h:53
#define __attribute__(a)