@@ -19,9 +19,10 @@ namespace rde
1919/* *
2020 * this is a super cut down replacement for std::stringstream
2121 * current limitations:
22- * - only converts from string -> primitve type
23- * - only supports signed int, signed long, float and rde::string
24- * - no support for unsigned word types
22+ * - only converts from rde::string -> arithmetic types
23+ * - supports bool, short, ushort, int/long, uint/ulong, long long, float, double, and long double
24+ * - unsigned long long (_ULonglong/unsigned __int64) not currently supported
25+ * - long double values are treated as doubles
2526 * - untested unicode support, no support for custom allocator
2627 * - supports only narrow conversions (8-bit char size)
2728 */
@@ -48,21 +49,76 @@ struct basic_stringstream
4849 init (inp);
4950 }
5051
51- // Output operators
52+ // Extraction operator>> (input)
5253
53- basic_stringstream& operator >>(int & x) {
54- if (next ()) { x = static_cast <int >(atoi (current.c_str ())); }
54+ basic_stringstream& operator >>(short & x)
55+ {
56+ if (next ()) { x = static_cast <short >(atoi (current.c_str ())); }
57+ return *this ;
58+ }
59+ basic_stringstream& operator >>(unsigned short & x)
60+ {
61+ if (next ()) { x = static_cast <unsigned short >(atoi (current.c_str ())); }
62+ return *this ;
63+ }
64+ basic_stringstream& operator >>(int & x)
65+ {
66+ if (next ()) { x = static_cast <int >(atoll (current.c_str ())); }
67+ return *this ;
68+ }
69+ basic_stringstream& operator >>(unsigned int & x)
70+ {
71+ if (next ()) { x = static_cast <unsigned int >(atoll (current.c_str ())); }
5572 return *this ;
5673 }
57- basic_stringstream& operator >>(long & x) {
58- if (next ()) { x = static_cast <long >(atol (current.c_str ())); }
74+ basic_stringstream& operator >>(long & x)
75+ {
76+ if (next ()) { x = static_cast <long >(atoll (current.c_str ())); }
77+ return *this ;
78+ }
79+ basic_stringstream& operator >>(unsigned long & x)
80+ {
81+ if (next ()) { x = static_cast <unsigned long >(atoll (current.c_str ())); }
5982 return *this ;
6083 }
61- basic_stringstream& operator >>(float & x) {
84+ basic_stringstream& operator >>(long long & x)
85+ {
86+ if (next ()) { x = static_cast <long long >(atoll (current.c_str ())); }
87+ return *this ;
88+ }
89+
90+ // TODO unsigned long long (_ULonglong)
91+ basic_stringstream& operator >>(unsigned long long & x)
92+ {
93+ static_assert (false == true , " unsigned 64-bit types not supported" );
94+ (void )x;
95+ return *this ;
96+ }
97+
98+ basic_stringstream& operator >>(float & x)
99+ {
62100 if (next ()) { x = static_cast <float >(atof (current.c_str ())); }
63101 return *this ;
64102 }
65- basic_stringstream& operator >>(rde::string& x) {
103+ basic_stringstream& operator >>(double & x)
104+ {
105+ if (next ()) { x = static_cast <double >(atof (current.c_str ())); }
106+ return *this ;
107+ }
108+ basic_stringstream& operator >>(long double & x)
109+ {
110+ if (next ()) { x = static_cast <double >(atof (current.c_str ())); }
111+ return *this ;
112+ }
113+
114+ basic_stringstream& operator >>(bool & x)
115+ {
116+ if (next ()) { x = static_cast <bool >(atoi (current.c_str ())); }
117+ return *this ;
118+ }
119+
120+ basic_stringstream& operator >>(rde::string& x)
121+ {
66122 if (next ()) { x = current; }
67123 return *this ;
68124 }
0 commit comments