soma-io 6.0.6
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 --------------------------------------------------------------
39#include <cartobase/config/cartobase_config.h>
40#include <cartobase/object/object.h>
41#include <cartobase/object/syntax.h>
42//--- system -----------------------------------------------------------------
43#include <iostream>
44//----------------------------------------------------------------------------
45
46namespace 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
73 virtual void read( carto::GenericObject & );
74 virtual void read( carto::Object & );
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 );
90 void attach( const std::string& filename );
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;
105 const carto::SyntaxSet & syntaxes() const;
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);
124 const std::string & semantic );
125 std::string readVariableName();
130 bool readSyntax( std::string & syntax );
131 std::string readString( char separator, unsigned & charsread );
132
136 const std::string&,
137 PythonReader & r );
138
140 const std::string&,
141 PythonReader & r );
142
143 template<typename T>
145 const std::string&,
146 PythonReader & r );
147
148 template<typename T>
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
163namespace carto
164{
165 DECLARE_GENERIC_OBJECT_TYPE( soma::PythonReader::Helper )
166 DECLARE_GENERIC_OBJECT_TYPE( soma::PythonReader::HelperSet )
167}
168
169#endif
#define __deprecated__(msg)
#define CARTOBASE_API
#define __attribute__(a)
bool operator!() const
status of the stream
std::string readString(char separator, unsigned &charsread)
void readDictionary(carto::GenericObject &obj)
reads an already allocated dictionary: just fills it (doesn't clear it)
HelperSet & helpers()
void attach(std::istream &s, int line_num=1)
attach to an existing istream
std::string readWhile(const std::string &s)
read characters in s
void readDictionary2(carto::GenericObject &obj)
reads the remaining attributes of a string dictionary
void readIntDictionary2(carto::TypedObject< carto::IntDictionary > &obj)
reads the remaining attributes of an int dictionary
virtual std::string name() const
file name
void init(const HelperSet &helpers)
static carto::GenericObject * genericSequenceHelper(carto::GenericObject *, const std::string &, PythonReader &r)
unsigned skipWhile(const std::string &s)
skip characters in s
const carto::SyntaxSet & syntaxes() const
void attach(const std::string &filename)
void skipUntil(const std::string &s)
skip characters not in s
PythonReader(const std::string &filename, const carto::SyntaxSet &rules=carto::SyntaxSet(), const HelperSet &helpers=HelperSet())
std::string readVariableName()
std::map< std::string, Helper > HelperSet
static carto::GenericObject * propertySetHelper(carto::GenericObject *, const std::string &, PythonReader &r)
virtual void read(carto::Object &)
static carto::GenericObject * genericDictHelper(carto::GenericObject *, const std::string &, PythonReader &r)
carto::SyntaxSet & syntaxes()
bool eof() const
have we hit EOF?
std::string lineString() const
PythonReader(carto::rc_ptr< DataSource > ds, const carto::SyntaxSet &rules=carto::SyntaxSet(), const HelperSet &helpers=HelperSet())
PythonReader takes ownership of the DataSource.
int line() const
std::string readUntil(const std::string &s)
read characters not in s
carto::rc_ptr< DataSource > dataSource()
static carto::GenericObject * dictHelper(carto::GenericObject *, const std::string &, PythonReader &r)
utility function, dictionary helper (can be useful in more specialized readers)
void attach(carto::rc_ptr< DataSource > ds)
const HelperSet & helpers() const
helper functions read basic data type
virtual ~PythonReader()
bool is_open() const
is the stream open?
virtual carto::GenericObject * read()
bool readSyntax(std::string &syntax)
attempts to read the syntax and general type of next element and fills syntax and type accordingly.
PythonReader(const carto::SyntaxSet &rules=carto::SyntaxSet(), const HelperSet &helpers=HelperSet())
virtual void read(carto::GenericObject &)
attempts to read an already allocated object, if file data matches the object type.
void open(const std::string &filename) __attribute__((__deprecated__("use attach() instead")))
carto::GenericObject * read(carto::GenericObject *parent, const std::string &semantic)
std::map< std::string, Syntax > SyntaxSet
#define DECLARE_GENERIC_OBJECT_TYPE(T)