FastLED 3.10.6
Loading...
Searching...
No Matches
ostream.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/int.h"
5#include "fl/stl/move.h" // IWYU pragma: keep
6#include "fl/stl/string.h"
7#include "fl/stl/ios.h" // IWYU pragma: keep
8
9// Include cstdio for print function
10#include "fl/stl/cstdio.h"
11#include "fl/stl/noexcept.h"
12
13namespace fl {
14
15struct CRGB;
16
17class ostream {
18public:
19 ostream() = default;
20
21 // Stream output operators that immediately print
22 ostream& operator<<(const char* str) FL_NO_EXCEPT {
23 if (str) {
24 print(str);
25 }
26 return *this;
27 }
28
29 ostream& operator<<(const string& str) FL_NO_EXCEPT {
30 print(str.c_str());
31 return *this;
32 }
33
35 char str[2] = {c, '\0'};
36 print(str);
37 return *this;
38 }
39
45
47 string temp;
48 temp.append(f);
49 print(temp.c_str());
50 return *this;
51 }
52
54 string temp;
55 temp.append(d);
56 print(temp.c_str());
57 return *this;
58 }
59
60 // Defined out-of-line in ostream.cpp.hpp so this header does not pull in
61 // crgb.h (and through it ease.h, the fixed-point types and sin32).
63
64 // Generic integer handler using SFINAE - handles all multi-byte integer types
65 // (including unsigned long on Windows) by casting to the appropriate fl:: type.
66 // Mirrors the pattern used by sstream.
67 template<typename T>
70 using target_t = typename int_cast_detail::cast_target<T>::type;
71 string temp;
72 temp.append(static_cast<target_t>(val));
73 print(temp.c_str());
74 return *this;
75 }
76
77 // Get current formatting base (1=decimal, 16=hex, 8=octal)
78 int getBase() const FL_NO_EXCEPT { return mBase; }
79
80 // Friend operators for manipulators
84
85private:
86 int mBase = 10; // Default to decimal
87};
88
89// Global cout instance for immediate output.
90// `cout` is a public API global — users write `fl::cout << x;` by name.
91// Migration to `Singleton<ostream>::instance()` would break source
92// compat (`cout()` at call sites). Kept as a global; allowlist marker
93// on the definition site in ostream.cpp.hpp.
94extern ostream cout;
95
96// Line ending manipulator — empty marker struct, public API surface
97// (`cout << endl`), same source-compat constraint as the other
98// manipulators. Definition in ostream.cpp.hpp is allowlisted.
99struct endl_t {};
100extern const endl_t endl;
101
102// endl manipulator implementation
104 os << "\n";
105 return os;
106}
107
108// hex, dec, oct manipulator implementations
109// (declared as friend functions in ostream class, implemented in ostream.cpp)
110ostream& operator<<(ostream& os, const hex_t&) FL_NO_EXCEPT;
111ostream& operator<<(ostream& os, const dec_t&) FL_NO_EXCEPT;
112ostream& operator<<(ostream& os, const oct_t&) FL_NO_EXCEPT;
113
114} // namespace fl
const char * c_str() const FL_NO_EXCEPT
int mBase
Definition ostream.h:86
ostream & operator<<(const string &str) FL_NO_EXCEPT
Definition ostream.h:29
ostream & operator<<(const char *str) FL_NO_EXCEPT
Definition ostream.h:22
ostream()=default
ostream & operator<<(float f) FL_NO_EXCEPT
Definition ostream.h:46
int getBase() const FL_NO_EXCEPT
Definition ostream.h:78
ostream & operator<<(double d) FL_NO_EXCEPT
Definition ostream.h:53
ostream & operator<<(char c) FL_NO_EXCEPT
Definition ostream.h:34
string & append(const bitset_fixed< N > &bs) FL_NO_EXCEPT
Definition string.h:293
typename fl::conditional< IsSigned, typename fl::conditional< Size==1, fl::i8, typename fl::conditional< Size==2, fl::i16, typename fl::conditional< Size==4, fl::i32, typename fl::conditional< Size==8, fl::i64, fl::i64 >::type >::type >::type >::type, typename fl::conditional< Size==1, fl::u16, typename fl::conditional< Size==2, fl::u16, typename fl::conditional< Size==4, fl::u32, typename fl::conditional< Size==8, fl::u64, fl::u64 >::type >::type >::type >::type >::type type
ostream cout
unsigned char u8
Definition stdint.h:131
const endl_t endl
void print(const char *str)
ostream & operator<<(ostream &os, const hex_t &) FL_NO_EXCEPT
InputGamut g FL_NO_EXCEPT
Definition rgbw.h:121
signed char i8
Definition stdint.h:130
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NO_EXCEPT
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38