34 #ifndef SOMAIO_UTILITIES_ASCIIDATASOURCETRAITS_H
35 #define SOMAIO_UTILITIES_ASCIIDATASOURCETRAITS_H
71 const std::string & chars =
" \t\n\r",
74 const std::string & chars =
" \t\n\r",
79 const std::string & chars =
" \t\n\r",
83 static bool skip( std::istream &,
const std::string & chars =
" \t\n\r",
89 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
95 make_compil_error( x,
"Instantiation on an unexpected type. "
96 "This function must be specialized." );
111 make_compil_error( x,
"Instantiation on an unexpected type. "
112 "This function must be specialized." );
126 template <
typename T>
134 template <
typename T>
170 const uint8_t & item )
185 const int8_t & item )
190 #if !defined(__sun__) || !defined(_CHAR_IS_SIGNED)
218 const uint16_t & item )
233 const int16_t & item )
249 const uint32_t & item )
264 const int32_t & item )
279 const int64_t & item )
296 const uint64_t & item )
301 #ifdef CARTO_LONG_IS_DISTINCT
321 unsigned long & item )
330 const unsigned long & item )
362 const double & item )
378 if( c ==
'\0' || !ds.
isOpen() || c ==
'\n' || c ==
'\r' || c ==
' '
381 item +=
static_cast<char>( c );
393 const std::string & item )
403 char *
const & item )
413 const char *
const & item )
436 if( c ==
'\0' || !ds.
isOpen() )
438 if( c < '0' || c >
'9' )
440 if( !sign && i == expo && ( c ==
'-' || c ==
'+' ) )
442 else if( c ==
'x' && !hex && i == sign+1 && num[sign] ==
'0' )
444 else if( !hex && !expo && ( c ==
'e' || c ==
'E' ) && i > sign )
449 else if( !hex || c <
'A' || ( c >
'F' && c <
'a' ) || c >
'f' )
452 num +=
static_cast<char>( c );
467 std::ostringstream ss;
490 if( c ==
'\0' || !ds.
isOpen() )
494 if( c !=
"nf"[inf-1] && c !=
"NF"[inf-1] )
508 if( c !=
"an"[nan-1] && c !=
"AN"[nan-1] )
520 else if( c < '0' || c >
'9' )
522 if( !sign && i == expo && ( c ==
'-' || c ==
'+' ) )
524 else if( !dot && c ==
'x' && !hex && i == sign+1
525 && num[sign] ==
'0' )
527 else if( !dot && !hex && c ==
'.' )
529 else if( !hex && !expo && ( c ==
'e' || c ==
'E' ) && i > sign )
534 else if( !hex && !dot && ( c ==
'n' || c ==
'N' ) )
536 else if( !hex && !dot && ( c ==
'i' || c ==
'I' ) )
538 else if( !hex || c <
'A' || ( c >
'F' && c <
'a' ) || c >
'f' )
541 num +=
static_cast<char>( c );
556 std::ostringstream ss;
578 template<
typename T>
inline
586 #if !defined(__sun__) || !defined(_CHAR_IS_SIGNED)
651 #ifdef CARTO_LONG_IS_DISTINCT
698 template <
typename T,
unsigned int C>
706 template <
typename T,
unsigned int C>
inline
716 if( c !=
' ' && c !=
'\t' && c !=
'\n' && c !=
'(' )
723 for(
unsigned int i=1; i<C; ++i )
725 while( ( c ==
' ' || c ==
'\t' ) && ds.
isOpen() )
741 while( ( c ==
' ' || c ==
'\t' ) && ds.
isOpen() )
743 if( c == 0 || c ==
')' ) {
753 template <
typename T,
unsigned int C>
inline
759 for(
unsigned int i=0; i<C-1; ++i )
760 ds <<
static_cast<int>( item[i] ) <<
',';
761 ds << static_cast<int>( item[C-1] ) <<
')';
850 item = std::complex<float>( x[0], x[1] );
856 DataSource & ds,
const std::complex<float> & item )
876 DataSource & ds, std::complex<double> & item )
881 item = std::complex<double>( x[0], x[1] );
887 DataSource & ds,
const std::complex<double> & item )
static bool read(DataSource &ds, T &item)
static bool write(DataSource &ds, const T &item)
Abstraction layer for various data sources (file, buffer, socket...).
virtual long writeBlock(const char *data, unsigned long len)=0
virtual bool ungetch(int ch)=0
virtual bool isOpen() const =0
static std::string readUntil(DataSource &, const std::string &chars=" \t\n\r", bool ascii=true)
static std::string readWhile(DataSource &, const std::string &chars=" \t\n\r", bool ascii=true)
static bool skip(DataSource &, const std::string &chars=" \t\n\r", bool ascii=true)
static bool skip(std::istream &, const std::string &chars=" \t\n\r", bool ascii=true)
static bool getline(DataSource &ds, std::string &)
static bool skipUntil(DataSource &, const std::string &chars=" \t\n\r", bool ascii=true)
static bool read(DataSource &, T &)
static bool write(DataSource &, const T &)
static bool read(DataSource &, T &)
static bool write(DataSource &, const T &)
void stringTo(const std::string &value, T &result)
std::ostream & operator<<(std::ostream &os, const MemoryAllocator &thing)
DataSource & operator>>(DataSource &ds, T &x)