FastLED 3.10.6
Loading...
Searching...
No Matches
istream.h
Go to the documentation of this file.
1
2
3#pragma once
4
7#include "fl/stl/int.h"
8
9// Note: fl/stl/cstdio.h intentionally NOT included directly — workaround
10// for zackees/zccache#619 (Windows PCH path-spelling drift defeats
11// `#pragma once` across the PCH boundary). istream.h only needs one
12// cstdio.h symbol — `fl::available()` — so forward-declare it here
13// and let consumers that need the full cstdio API include it themselves.
14#include "fl/stl/noexcept.h"
15#include "fl/stl/compiler_control.h" // IWYU pragma: keep - FL_UNUSED
16
17namespace fl {
19}
20
21namespace fl {
22
24private:
25 static const fl::size BUFFER_SIZE = 256;
27 fl::size mBufferLen = 0;
28 fl::size mPos = 0;
29 bool mFailed = false;
30
31 // Helper to read a line from input
32 bool readLine();
33
34 // Helper to skip whitespace
35 void skipWhitespace();
36
37 // Helper to read until whitespace or end
38 bool readToken(string& token);
39
40public:
42
43 // Check if stream is in good state
44 bool good() const { return !mFailed; }
45 bool fail() const { return mFailed; }
46 bool eof() const { return mPos >= mBufferLen && fl::available() == 0; }
47
48 // Clear error state
49 void clear() { mFailed = false; }
50
51 // Stream input operators
52 istream_real& operator>>(string& str);
53 istream_real& operator>>(char& c);
56 istream_real& operator>>(fl::i16& n);
57 istream_real& operator>>(fl::i32& n);
58 istream_real& operator>>(fl::u32& n);
59 istream_real& operator>>(float& f);
60 istream_real& operator>>(double& d);
61
62 // Unified handler for fl:: namespace size-like unsigned integer types to avoid conflicts
63 // This only handles fl::size and fl::u16 from the fl:: namespace
64 template<typename T>
65 typename fl::enable_if<
69 >::type operator>>(T& n);
70
71 // Get a line from input
72 istream_real& getline(string& str);
73
74 // Get next character
75 int get();
76
77 // Put back a character
78 istream_real& putback(char c);
79
80 // Peek at next character without consuming it
81 int peek();
82};
83
84// Function to get singleton instance of istream_real (for better linker elimination)
85istream_real& cin_real();
86
87// Stub istream class that conditionally delegates to istream_real
88class istream {
89private:
90#if SKETCH_HAS_LARGE_MEMORY
91 istream_real mRealStream;
92#endif
93
94public:
95 istream() FL_NO_EXCEPT = default;
96
97 // Check if stream is in good state
98 bool good() const {
99#if SKETCH_HAS_LARGE_MEMORY
100 return mRealStream.good();
101#else
102 return true; // Always good on memory-constrained platforms
103#endif
104 }
105
106 bool fail() const {
107#if SKETCH_HAS_LARGE_MEMORY
108 return mRealStream.fail();
109#else
110 return false; // Never fail on memory-constrained platforms
111#endif
112 }
113
114 bool eof() const {
115#if SKETCH_HAS_LARGE_MEMORY
116 return mRealStream.eof();
117#else
118 return true; // Always EOF on memory-constrained platforms
119#endif
120 }
121
122 // Clear error state
123 void clear() {
124#if SKETCH_HAS_LARGE_MEMORY
125 mRealStream.clear();
126#endif
127 }
128
129 // Stream input operators
130 istream& operator>>(string& str) {
131#if SKETCH_HAS_LARGE_MEMORY
132 mRealStream >> str;
133#else
134 // No-op on memory-constrained platforms
135 str.clear();
136#endif
137 return *this;
138 }
139
140 istream& operator>>(char& c) {
141#if SKETCH_HAS_LARGE_MEMORY
142 mRealStream >> c;
143#else
144 // No-op on memory-constrained platforms
145 c = '\0';
146#endif
147 return *this;
148 }
149
151#if SKETCH_HAS_LARGE_MEMORY
152 mRealStream >> n;
153#else
154 // No-op on memory-constrained platforms
155 n = 0;
156#endif
157 return *this;
158 }
159
161#if SKETCH_HAS_LARGE_MEMORY
162 mRealStream >> n;
163#else
164 // No-op on memory-constrained platforms
165 n = 0;
166#endif
167 return *this;
168 }
169
170 istream& operator>>(fl::i16& n) {
171#if SKETCH_HAS_LARGE_MEMORY
172 mRealStream >> n;
173#else
174 // No-op on memory-constrained platforms
175 n = 0;
176#endif
177 return *this;
178 }
179
180 istream& operator>>(fl::i32& n) {
181#if SKETCH_HAS_LARGE_MEMORY
182 mRealStream >> n;
183#else
184 // No-op on memory-constrained platforms
185 n = 0;
186#endif
187 return *this;
188 }
189
190 istream& operator>>(fl::u32& n) {
191#if SKETCH_HAS_LARGE_MEMORY
192 mRealStream >> n;
193#else
194 // No-op on memory-constrained platforms
195 n = 0;
196#endif
197 return *this;
198 }
199
200 istream& operator>>(float& f) {
201#if SKETCH_HAS_LARGE_MEMORY
202 mRealStream >> f;
203#else
204 // No-op on memory-constrained platforms
205 f = 0.0f;
206#endif
207 return *this;
208 }
209
210 istream& operator>>(double& d) {
211#if SKETCH_HAS_LARGE_MEMORY
212 mRealStream >> d;
213#else
214 // No-op on memory-constrained platforms
215 d = 0.0;
216#endif
217 return *this;
218 }
219
220 // Unified handler for fl:: namespace size-like unsigned integer types to avoid conflicts
221 template<typename T>
222 typename fl::enable_if<
225 istream&
227#if SKETCH_HAS_LARGE_MEMORY
228 mRealStream >> n;
229#else
230 // No-op on memory-constrained platforms
231 n = 0;
232#endif
233 return *this;
234 }
235
236 // Get a line from input
237 istream& getline(string& str) {
238#if SKETCH_HAS_LARGE_MEMORY
239 mRealStream.getline(str);
240#else
241 // No-op on memory-constrained platforms
242 str.clear();
243#endif
244 return *this;
245 }
246
247 // Get next character
248 int get() {
249#if SKETCH_HAS_LARGE_MEMORY
250 return mRealStream.get();
251#else
252 // No-op on memory-constrained platforms
253 return -1;
254#endif
255 }
256
257 // Put back a character
258 istream& putback(char c) {
259#if SKETCH_HAS_LARGE_MEMORY
260 mRealStream.putback(c);
261#else
262 FL_UNUSED(c);
263#endif
264 return *this;
265 }
266
267 // Peek at next character without consuming it
268 int peek() {
269#if SKETCH_HAS_LARGE_MEMORY
270 return mRealStream.peek();
271#else
272 // No-op on memory-constrained platforms
273 return -1;
274#endif
275 }
276};
277
278// Global cin instance for input (now uses the stub)
279extern istream cin;
280
281// Template implementation for istream_real
282template<typename T>
283typename fl::enable_if<
286 istream_real&
288 // Use existing fl::u32 parsing logic for both fl::size and fl::u16
289 // since they're both unsigned integer types that fit in fl::u32
290 fl::u32 temp;
291 (*this) >> temp;
292 n = static_cast<T>(temp);
293 return *this;
294}
295
296} // namespace fl
void clear(bool freeMemory=false) FL_NO_EXCEPT
bool fail() const
Definition istream.h:45
bool good() const
Definition istream.h:44
fl::size mBufferLen
Definition istream.h:27
fl::size mPos
Definition istream.h:28
istream_real & putback(char c)
char mBuffer[BUFFER_SIZE]
Definition istream.h:26
static const fl::size BUFFER_SIZE
Definition istream.h:25
istream_real & operator>>(string &str)
bool eof() const
Definition istream.h:46
bool readToken(string &token)
istream_real & getline(string &str)
istream_real() FL_NO_EXCEPT=default
int peek()
Definition istream.h:268
istream & operator>>(fl::u8 &n)
Definition istream.h:160
bool good() const
Definition istream.h:98
istream() FL_NO_EXCEPT=default
fl::enable_if< fl::is_same< T, fl::size >::value||fl::is_same< T, fl::u16 >::value, istream & >::type operator>>(T &n)
Definition istream.h:226
istream & operator>>(double &d)
Definition istream.h:210
istream & operator>>(char &c)
Definition istream.h:140
istream & operator>>(fl::i32 &n)
Definition istream.h:180
bool eof() const
Definition istream.h:114
istream & getline(string &str)
Definition istream.h:237
bool fail() const
Definition istream.h:106
istream & operator>>(fl::i16 &n)
Definition istream.h:170
void clear()
Definition istream.h:123
int get()
Definition istream.h:248
istream & operator>>(fl::u32 &n)
Definition istream.h:190
istream & operator>>(float &f)
Definition istream.h:200
istream & operator>>(fl::i8 &n)
Definition istream.h:150
istream & putback(char c)
Definition istream.h:258
istream & operator>>(string &str)
Definition istream.h:130
#define FL_UNUSED(x)
int available()
unsigned char u8
Definition stdint.h:131
FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS istream cin
InputGamut g FL_NO_EXCEPT
Definition rgbw.h:121
istream_real & cin_real()
signed char i8
Definition stdint.h:130
Base definition for an LED controller.
Definition crgb.hpp:179