FastLED 3.10.8
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;
26 // Every member has an initializer so the defaulted constructor is
27 // constexpr: the global `fl::cin` (which embeds one of these) is then
28 // constant-initialized in .bss with no dynamic initializer, and
29 // --gc-sections drops its 256-byte buffer from sketches that never
30 // read from it.
31 char mBuffer[BUFFER_SIZE] = {};
32 fl::size mBufferLen = 0;
33 fl::size mPos = 0;
34 bool mFailed = false;
35
36 // Helper to read a line from input
38
39 // Helper to skip whitespace
41
42 // Helper to read until whitespace or end
43 bool readToken(string& token) FL_NO_EXCEPT;
44
45public:
47
48 // Check if stream is in good state
49 bool good() const FL_NO_EXCEPT { return !mFailed; }
50 bool fail() const FL_NO_EXCEPT { return mFailed; }
51 bool eof() const FL_NO_EXCEPT { return mPos >= mBufferLen && fl::available() == 0; }
52
53 // Clear error state
54 void clear() FL_NO_EXCEPT { mFailed = false; }
55
56 // Stream input operators
66
67 // Unified handler for fl:: namespace size-like unsigned integer types to avoid conflicts
68 // This only handles fl::size and fl::u16 from the fl:: namespace
69 template<typename T>
70 typename fl::enable_if<
75
76 // Get a line from input
77 istream_real& getline(string& str) FL_NO_EXCEPT;
78
79 // Get next character
80 int get() FL_NO_EXCEPT;
81
82 // Put back a character
84
85 // Peek at next character without consuming it
86 int peek() FL_NO_EXCEPT;
87};
88
89// Function to get singleton instance of istream_real (for better linker elimination)
91
92// Stub istream class that conditionally delegates to istream_real
93class istream {
94private:
95#if SKETCH_HAS_LARGE_MEMORY
96 istream_real mRealStream;
97#endif
98
99public:
101
102 // Check if stream is in good state
103 bool good() const FL_NO_EXCEPT {
104#if SKETCH_HAS_LARGE_MEMORY
105 return mRealStream.good();
106#else
107 return true; // Always good on memory-constrained platforms
108#endif
109 }
110
111 bool fail() const FL_NO_EXCEPT {
112#if SKETCH_HAS_LARGE_MEMORY
113 return mRealStream.fail();
114#else
115 return false; // Never fail on memory-constrained platforms
116#endif
117 }
118
119 bool eof() const FL_NO_EXCEPT {
120#if SKETCH_HAS_LARGE_MEMORY
121 return mRealStream.eof();
122#else
123 return true; // Always EOF on memory-constrained platforms
124#endif
125 }
126
127 // Clear error state
129#if SKETCH_HAS_LARGE_MEMORY
130 mRealStream.clear();
131#endif
132 }
133
134 // Stream input operators
136#if SKETCH_HAS_LARGE_MEMORY
137 mRealStream >> str;
138#else
139 // No-op on memory-constrained platforms
140 str.clear();
141#endif
142 return *this;
143 }
144
146#if SKETCH_HAS_LARGE_MEMORY
147 mRealStream >> c;
148#else
149 // No-op on memory-constrained platforms
150 c = '\0';
151#endif
152 return *this;
153 }
154
156#if SKETCH_HAS_LARGE_MEMORY
157 mRealStream >> n;
158#else
159 // No-op on memory-constrained platforms
160 n = 0;
161#endif
162 return *this;
163 }
164
166#if SKETCH_HAS_LARGE_MEMORY
167 mRealStream >> n;
168#else
169 // No-op on memory-constrained platforms
170 n = 0;
171#endif
172 return *this;
173 }
174
176#if SKETCH_HAS_LARGE_MEMORY
177 mRealStream >> n;
178#else
179 // No-op on memory-constrained platforms
180 n = 0;
181#endif
182 return *this;
183 }
184
186#if SKETCH_HAS_LARGE_MEMORY
187 mRealStream >> n;
188#else
189 // No-op on memory-constrained platforms
190 n = 0;
191#endif
192 return *this;
193 }
194
196#if SKETCH_HAS_LARGE_MEMORY
197 mRealStream >> n;
198#else
199 // No-op on memory-constrained platforms
200 n = 0;
201#endif
202 return *this;
203 }
204
206#if SKETCH_HAS_LARGE_MEMORY
207 mRealStream >> f;
208#else
209 // No-op on memory-constrained platforms
210 f = 0.0f;
211#endif
212 return *this;
213 }
214
216#if SKETCH_HAS_LARGE_MEMORY
217 mRealStream >> d;
218#else
219 // No-op on memory-constrained platforms
220 d = 0.0;
221#endif
222 return *this;
223 }
224
225 // Unified handler for fl:: namespace size-like unsigned integer types to avoid conflicts
226 template<typename T>
227 typename fl::enable_if<
230 istream&
232#if SKETCH_HAS_LARGE_MEMORY
233 mRealStream >> n;
234#else
235 // No-op on memory-constrained platforms
236 n = 0;
237#endif
238 return *this;
239 }
240
241 // Get a line from input
243#if SKETCH_HAS_LARGE_MEMORY
244 mRealStream.getline(str);
245#else
246 // No-op on memory-constrained platforms
247 str.clear();
248#endif
249 return *this;
250 }
251
252 // Get next character
254#if SKETCH_HAS_LARGE_MEMORY
255 return mRealStream.get();
256#else
257 // No-op on memory-constrained platforms
258 return -1;
259#endif
260 }
261
262 // Put back a character
264#if SKETCH_HAS_LARGE_MEMORY
265 mRealStream.putback(c);
266#else
267 FL_UNUSED(c);
268#endif
269 return *this;
270 }
271
272 // Peek at next character without consuming it
274#if SKETCH_HAS_LARGE_MEMORY
275 return mRealStream.peek();
276#else
277 // No-op on memory-constrained platforms
278 return -1;
279#endif
280 }
281};
282
283// Global cin instance for input (now uses the stub)
284extern istream cin;
285
286// Template implementation for istream_real
287template<typename T>
288typename fl::enable_if<
293 // Use existing fl::u32 parsing logic for both fl::size and fl::u16
294 // since they're both unsigned integer types that fit in fl::u32
295 fl::u32 temp;
296 (*this) >> temp;
297 n = static_cast<T>(temp);
298 return *this;
299}
300
301} // namespace fl
fl::size mBufferLen
Definition istream.h:32
bool fail() const FL_NO_EXCEPT
Definition istream.h:50
fl::size mPos
Definition istream.h:33
int peek() FL_NO_EXCEPT
char mBuffer[BUFFER_SIZE]
Definition istream.h:31
istream_real & getline(string &str) FL_NO_EXCEPT
void skipWhitespace() FL_NO_EXCEPT
bool good() const FL_NO_EXCEPT
Definition istream.h:49
istream_real & putback(char c) FL_NO_EXCEPT
bool readToken(string &token) FL_NO_EXCEPT
static const fl::size BUFFER_SIZE
Definition istream.h:25
void clear() FL_NO_EXCEPT
Definition istream.h:54
bool readLine() FL_NO_EXCEPT
bool eof() const FL_NO_EXCEPT
Definition istream.h:51
istream_real & operator>>(string &str) FL_NO_EXCEPT
int get() FL_NO_EXCEPT
istream_real() FL_NO_EXCEPT=default
void clear() FL_NO_EXCEPT
Definition istream.h:128
bool good() const FL_NO_EXCEPT
Definition istream.h:103
istream() FL_NO_EXCEPT=default
istream & operator>>(char &c) FL_NO_EXCEPT
Definition istream.h:145
istream & operator>>(string &str) FL_NO_EXCEPT
Definition istream.h:135
fl::enable_if< fl::is_same< T, fl::size >::value||fl::is_same< T, fl::u16 >::value, istream & >::type operator>>(T &n) FL_NO_EXCEPT
Definition istream.h:231
bool fail() const FL_NO_EXCEPT
Definition istream.h:111
istream & putback(char c) FL_NO_EXCEPT
Definition istream.h:263
istream & getline(string &str) FL_NO_EXCEPT
Definition istream.h:242
istream & operator>>(fl::i32 &n) FL_NO_EXCEPT
Definition istream.h:185
int get() FL_NO_EXCEPT
Definition istream.h:253
bool eof() const FL_NO_EXCEPT
Definition istream.h:119
istream & operator>>(fl::u32 &n) FL_NO_EXCEPT
Definition istream.h:195
istream & operator>>(fl::i8 &n) FL_NO_EXCEPT
Definition istream.h:155
istream & operator>>(fl::i16 &n) FL_NO_EXCEPT
Definition istream.h:175
istream & operator>>(fl::u8 &n) FL_NO_EXCEPT
Definition istream.h:165
istream & operator>>(float &f) FL_NO_EXCEPT
Definition istream.h:205
int peek() FL_NO_EXCEPT
Definition istream.h:273
istream & operator>>(double &d) FL_NO_EXCEPT
Definition istream.h:215
unsigned char u8
Definition s16x16x4.h:132
signed char i8
Definition s16x16x4.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS istream cin
int available() FL_NO_EXCEPT
istream_real & cin_real() FL_NO_EXCEPT
int peek() FL_NO_EXCEPT
Base definition for an LED controller.
#define FL_UNUSED(x)