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