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",
76 static bool skip(
DataSource &,
const std::string & chars =
" \t\n\r",
79 const std::string & chars =
" \t\n\r",
81 static bool getline(
DataSource & ds, std::string & );
83 static bool skip( std::istream &,
const std::string & chars =
" \t\n\r",
89 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES 95 make_compil_error( x,
"Instanciation on an unexpected type. " 96 "This function must be specialized." );
111 make_compil_error( x,
"Instanciation 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;
565 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES 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] ) <<
')';
765 template<
typename T,
unsigned int C>
inline DataSource &
766 operator << ( DataSource & ds, const carto::VoxelValue<T,C> & x )
850 item = std::complex<float>( x[0], x[1] );
856 DataSource & ds,
const std::complex<float> & item )
866 operator << ( DataSource & ds, const std::complex<float> & x )
876 DataSource & ds, std::complex<double> & item )
881 item = std::complex<double>( x[0], x[1] );
887 DataSource & ds,
const std::complex<double> & item )
897 operator << ( DataSource & ds, const std::complex<double> & x )
static bool read(DataSource &ds, T &item)
virtual long writeBlock(const char *data, unsigned long len)=0
static bool skip(DataSource &, const std::string &chars=" \\, bool ascii=true)
static bool write(DataSource &, const T &)
DataSource & operator>>(DataSource &ds, T &x)
Abstraction layer for various data sources (file, buffer, socket...).
void stringTo(const std::string &value, T &result)
static bool write(DataSource &ds, const T &item)
std::ostream & operator<<(std::ostream &os, const MemoryAllocator &thing)
virtual bool ungetch(int ch)=0
static bool read(DataSource &, T &)
static bool write(DataSource &, const T &)
virtual bool isOpen() const =0
static bool read(DataSource &, T &)