Mercurial > hg > octave-lyh
comparison src/oct-stream.cc @ 3779:3001e15555e9
[project @ 2001-02-07 04:47:51 by jwe]
author | jwe |
---|---|
date | Wed, 07 Feb 2001 04:48:01 +0000 |
parents | 13905c3a24af |
children | f19f00339363 |
comparison
equal
deleted
inserted
replaced
3778:594ead754542 | 3779:3001e15555e9 |
---|---|
1062 invalid_operation ("fread", "reading"); | 1062 invalid_operation ("fread", "reading"); |
1063 | 1063 |
1064 return retval; | 1064 return retval; |
1065 } | 1065 } |
1066 | 1066 |
1067 #if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY | 1067 #if defined (__GNUG__) && ! defined (CXX_ISO_COMPLIANT_LIBRARY) |
1068 | 1068 |
1069 #define OCTAVE_SCAN(is, fmt, arg) is.scan ((fmt).text, arg) | 1069 #define OCTAVE_SCAN(is, fmt, arg) is.scan ((fmt).text, arg) |
1070 | 1070 |
1071 #else | 1071 #else |
1072 | 1072 |
1073 #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg) | 1073 #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg) |
1074 | |
1075 // XXX FIXME XXX -- this needs to be fixed to handle formats which | |
1076 // specify a maximum width. | |
1074 | 1077 |
1075 template <class T> | 1078 template <class T> |
1076 std::istream& | 1079 std::istream& |
1077 octave_scan (std::istream& is, const scanf_format_elt& fmt, T valptr) | 1080 octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr) |
1078 { | 1081 { |
1079 // Someone else who cares will have to fix this code. I refuse to | 1082 T& ref = *valptr; |
1080 // waste my time working on it when a reasonable alternative like | 1083 |
1081 // istream::scan exists in the GNU iostream library. --jwe | 1084 switch (fmt.type) |
1082 | 1085 { |
1083 error ("formatted input only works when Octave is compiled with G++"); | 1086 case 'o': |
1084 | 1087 is >> std::oct >> ref; |
1085 is.setstate (std::ios::failbit); | 1088 break; |
1089 | |
1090 case 'x': | |
1091 is >> std::hex >> ref; | |
1092 break; | |
1093 | |
1094 default: | |
1095 is >> ref; | |
1096 break; | |
1097 } | |
1086 | 1098 |
1087 return is; | 1099 return is; |
1088 } | 1100 } |
1089 | 1101 |
1090 template std::istream& | 1102 // Note that this specialization is only used for reading characters, not |
1091 octave_scan (std::istream&, const scanf_format_elt&, char*); | 1103 // character strings. See BEGIN_S_CONVERSION for details. |
1092 | 1104 |
1093 template std::istream& | 1105 template<> |
1094 octave_scan (std::istream&, const scanf_format_elt&, int*); | 1106 std::istream& |
1095 | 1107 octave_scan<> (std::istream& is, const scanf_format_elt& fmt, char* valptr) |
1096 template std::istream& | 1108 { |
1097 octave_scan (std::istream&, const scanf_format_elt&, long int*); | 1109 return is >> valptr; |
1098 | 1110 } |
1099 template std::istream& | |
1100 octave_scan (std::istream&, const scanf_format_elt&, short int*); | |
1101 | |
1102 #if 0 | |
1103 template std::istream& | |
1104 octave_scan (std::istream&, const scanf_format_elt&, float*); | |
1105 #endif | |
1106 | |
1107 template std::istream& | |
1108 octave_scan (std::istream&, const scanf_format_elt&, double*); | |
1109 | 1111 |
1110 #endif | 1112 #endif |
1111 | 1113 |
1112 template <class T> | 1114 template <class T> |
1113 void | 1115 void |
1252 \ | 1254 \ |
1253 tmp[width] = '\0'; \ | 1255 tmp[width] = '\0'; \ |
1254 } \ | 1256 } \ |
1255 else \ | 1257 else \ |
1256 { \ | 1258 { \ |
1257 std::ostrstream buf; \ | 1259 std::string buf; \ |
1258 \ | 1260 is >> std::ws >> buf; \ |
1259 int c = EOF; \ | 1261 tmp = strsave (buf.c_str()); \ |
1260 \ | |
1261 while (is && (c = is.get ()) != EOF && isspace (c)) \ | |
1262 /* skip leading whitespace */; \ | |
1263 \ | |
1264 if (is && c != EOF) \ | |
1265 buf << (char) c; \ | |
1266 \ | |
1267 while (is && (c = is.get ()) != EOF && ! isspace (c)) \ | |
1268 buf << (char) c; \ | |
1269 \ | |
1270 if (isspace (c)) \ | |
1271 is.putback (c); \ | |
1272 \ | |
1273 buf << std::ends; \ | |
1274 \ | |
1275 tmp = buf.str (); \ | |
1276 } \ | 1262 } \ |
1277 } \ | 1263 } \ |
1278 while (0) | 1264 while (0) |
1279 | 1265 |
1280 // This format must match a nonempty sequence of characters. | 1266 // This format must match a nonempty sequence of characters. |
1510 switch (elt->modifier) | 1496 switch (elt->modifier) |
1511 { | 1497 { |
1512 case 'h': | 1498 case 'h': |
1513 { | 1499 { |
1514 short int tmp; | 1500 short int tmp; |
1515 do_scanf_conv (is, fmt, &tmp, mval, data, | 1501 do_scanf_conv (is, *elt, &tmp, mval, data, |
1516 data_index, conversion_count, | 1502 data_index, conversion_count, |
1517 nr, max_size, discard); | 1503 nr, max_size, discard); |
1518 } | 1504 } |
1519 break; | 1505 break; |
1520 | 1506 |
1521 case 'l': | 1507 case 'l': |
1522 { | 1508 { |
1523 long int tmp; | 1509 long int tmp; |
1524 do_scanf_conv (is, fmt, &tmp, mval, data, | 1510 do_scanf_conv (is, *elt, &tmp, mval, data, |
1525 data_index, conversion_count, | 1511 data_index, conversion_count, |
1526 nr, max_size, discard); | 1512 nr, max_size, discard); |
1527 } | 1513 } |
1528 break; | 1514 break; |
1529 | 1515 |
1530 default: | 1516 default: |
1531 { | 1517 { |
1532 int tmp; | 1518 int tmp; |
1533 do_scanf_conv (is, fmt, &tmp, mval, data, | 1519 do_scanf_conv (is, *elt, &tmp, mval, data, |
1534 data_index, conversion_count, | 1520 data_index, conversion_count, |
1535 nr, max_size, discard); | 1521 nr, max_size, discard); |
1536 } | 1522 } |
1537 break; | 1523 break; |
1538 } | 1524 } |
1541 | 1527 |
1542 case 'e': case 'f': case 'g': | 1528 case 'e': case 'f': case 'g': |
1543 { | 1529 { |
1544 double tmp; | 1530 double tmp; |
1545 | 1531 |
1546 do_scanf_conv (is, fmt, &tmp, mval, data, | 1532 do_scanf_conv (is, *elt, &tmp, mval, data, |
1547 data_index, conversion_count, | 1533 data_index, conversion_count, |
1548 nr, max_size, discard); | 1534 nr, max_size, discard); |
1549 } | 1535 } |
1550 break; | 1536 break; |
1551 | 1537 |