11 #ifndef BIOPROCESSING_IO_PYTHON_HELPERS_H
12 #define BIOPROCESSING_IO_PYTHON_HELPERS_H
17 #include <cartobase/object/property.h>
18 #include <cartobase/object/object.h>
19 #include <cartobase/object/pythonwriter.h>
20 #include <cartobase/object/pythonreader.h>
22 template <
typename T >
23 carto::GenericObject*
listHelper( carto::GenericObject*
object,
const std::string & semantic, soma::PythonReader & r )
27 soma::DataSource & ds = *r.dataSource();
31 r.skipWhile(
" \t\n\\\r" );
33 carto::io_error::launchErrnoExcept( ds.url() );
34 char c = ds.getch(), mark;
36 carto::io_error::launchErrnoExcept( ds.url() );
43 throw std::runtime_error( std::string(
"PythonReader: Not a list/tuple: " )
44 + r.name() +
", line " + r.lineString() );
47 std::string synt =
"", contsem =
"";
48 carto::GenericObject *obj =
new carto::ValueObject<T >;
51 bool genfallback =
false;
52 soma::PythonReader::HelperSet::const_iterator h = r.helpers().end();
53 carto::SyntaxSet::const_iterator syntax = r.syntaxes().find( obj->type() );
54 if( syntax == r.syntaxes().end() && !genfallback )
56 syntax = r.syntaxes().find(
"__generic__" );
60 if( syntax != r.syntaxes().end() )
63 carto::Syntax::const_iterator
property = syntax->second.find(
"" );
64 if( property == syntax->second.end() && !genfallback )
67 carto::SyntaxSet::const_iterator syntax2 = r.syntaxes().find(
"__generic__" );
68 if( syntax2 != r.syntaxes().end() )
71 property = syntax->second.find(
"" );
74 if( property == syntax->second.end() )
76 property = syntax->second.find(
"__fallback__" );
78 if( property != syntax->second.end() )
80 contsem =
property->second.type;
81 h = r.helpers().find( contsem );
90 r.skipWhile(
" \t\n\\\r" );
92 carto::io_error::launchErrnoExcept( ds.url() );
95 carto::io_error::launchErrnoExcept( ds.url() );
98 r.skipWhile(
" \t\n\\\r" );
100 carto::io_error::launchErrnoExcept( ds.url() );
103 carto::io_error::launchErrnoExcept( ds.url() );
112 carto::GenericObject* o1;
113 if( h != r.helpers().end() )
116 o1 = (h->second)( obj, contsem, r );
120 o1 = r.read( obj, contsem );
123 obj->GenericObject::value<T >().push_back( o1->GenericObject::value<
typename T::value_type >() );
125 while( ds.isOpen() );
129 catch( std::exception & e )
136 template <
typename T>
138 soma::PythonReader & r)
141 soma::DataSource & ds = *r.dataSource();
144 r.skipWhile(
" \t\n\\\r" );
146 carto::io_error::launchErrnoExcept( ds.url() );
149 carto::io_error::launchErrnoExcept( ds.url() );
151 std::cerr <<
"Attempt to read a dictionary not starting with '{'" << std::endl;
154 r.skipWhile(
" \t\n\\\r" );
156 carto::io_error::launchErrnoExcept( ds.url() );
159 carto::io_error::launchErrnoExcept( ds.url() );
164 carto::io_error::launchErrnoExcept( ds.url() );
187 carto::GenericObject *obj;
189 obj =
new carto::ValueObject<T>;
193 r.readDictionary2( *obj );
195 catch( std::exception & e )
205 return new carto::ValueObject<T>;
208 throw carto::parse_error(
"unrecognized tag start", std::string() + c,
209 ds.url(), r.line() );
carto::GenericObject * listHelper(carto::GenericObject *object, const std::string &semantic, soma::PythonReader &r)
carto::GenericObject * propertySetHelper(carto::GenericObject *, const std::string &, soma::PythonReader &r)