FastLED 3.9.15
Loading...
Searching...
No Matches
ostream.h
Go to the documentation of this file.
1#pragma once
2
3// allow-include-after-namespace
4
5// Forward declaration to avoid pulling in fl/io.h and causing fl/io.cpp to be compiled
6#ifndef FL_IO_H_INCLUDED
7namespace fl {
8 void print(const char* str);
9}
10#endif
11
12#include "fl/str.h"
13#include "fl/int.h"
14#include "fl/type_traits.h"
15#include "crgb.h"
16
17namespace fl {
18
19class ostream {
20public:
21 ostream() = default;
22
23 // Stream output operators that immediately print
24 ostream& operator<<(const char* str) {
25 if (str) {
26 print(str);
27 }
28 return *this;
29 }
30
31 ostream& operator<<(const string& str) {
32 print(str.c_str());
33 return *this;
34 }
35
37 char str[2] = {c, '\0'};
38 print(str);
39 return *this;
40 }
41
43 string temp;
44 temp.append(fl::i16(n));
45 print(temp.c_str());
46 return *this;
47 }
48
50 string temp;
51 temp.append(fl::u16(n));
52 print(temp.c_str());
53 return *this;
54 }
55
56 ostream& operator<<(fl::i16 n) {
57 string temp;
58 temp.append(n);
59 print(temp.c_str());
60 return *this;
61 }
62
63 ostream& operator<<(fl::i32 n) {
64 string temp;
65 temp.append(n);
66 print(temp.c_str());
67 return *this;
68 }
69
70 ostream& operator<<(fl::u32 n) {
71 string temp;
72 temp.append(n);
73 print(temp.c_str());
74 return *this;
75 }
76
77 ostream& operator<<(float f) {
78 string temp;
79 temp.append(f);
80 print(temp.c_str());
81 return *this;
82 }
83
84 ostream& operator<<(double d) {
85 string temp;
86 temp.append(d);
87 print(temp.c_str());
88 return *this;
89 }
90
91 ostream& operator<<(const CRGB& rgb) {
92 string temp;
93 temp.append(rgb);
94 print(temp.c_str());
95 return *this;
96 }
97
98 // Unified handler for fl:: namespace size-like unsigned integer types to avoid conflicts
99 // This handles fl::size and fl::u16 from the fl:: namespace only
100 template<typename T>
101 typename fl::enable_if<
104 ostream&
105 >::type operator<<(T n) {
106 string temp;
107 temp.append(fl::u32(n));
108 print(temp.c_str());
109 return *this;
110 }
111
112 // Generic template for other types that have string append support
113 // Note: This must come after the specific SFINAE template to avoid conflicts
114 template<typename T>
115 typename fl::enable_if<
118 ostream&
119 >::type operator<<(const T& value) {
120 string temp;
121 temp.append(value);
122 print(temp.c_str());
123 return *this;
124 }
125};
126
127// Global cout instance for immediate output
128extern ostream cout;
129
130// Line ending manipulator
131struct endl_t {};
132extern const endl_t endl;
133
134// endl manipulator implementation
135inline ostream& operator<<(ostream& os, const endl_t&) {
136 os << "\n";
137 return os;
138}
139
140} // namespace fl
const char * c_str() const
Definition str.h:326
ostream & operator<<(const string &str)
Definition ostream.h:31
ostream & operator<<(fl::i16 n)
Definition ostream.h:56
fl::enable_if< fl::is_same< T, fl::size >::value||fl::is_same< T, fl::u16 >::value, ostream & >::type operator<<(T n)
Definition ostream.h:105
ostream & operator<<(fl::i8 n)
Definition ostream.h:42
ostream()=default
ostream & operator<<(char c)
Definition ostream.h:36
ostream & operator<<(fl::i32 n)
Definition ostream.h:63
ostream & operator<<(double d)
Definition ostream.h:84
ostream & operator<<(const CRGB &rgb)
Definition ostream.h:91
ostream & operator<<(fl::u8 n)
Definition ostream.h:49
ostream & operator<<(fl::u32 n)
Definition ostream.h:70
ostream & operator<<(const char *str)
Definition ostream.h:24
ostream & operator<<(float f)
Definition ostream.h:77
fl::enable_if<!fl::is_same< T, fl::size >::value &&!fl::is_same< T, fl::u16 >::value, ostream & >::type operator<<(const T &value)
Definition ostream.h:119
string & append(const BitsetFixed< N > &bs)
Definition str.h:675
Defines the red, green, and blue (RGB) pixel struct.
ostream cout
Definition ostream.cpp:6
unsigned char u8
Definition int.h:17
const endl_t endl
Definition ostream.cpp:9
void print(const char *str)
Definition io.cpp:49
signed char i8
Definition int.h:16
ostream & operator<<(ostream &os, const endl_t &)
Definition ostream.h:135
IMPORTANT!
Definition crgb.h:20
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
static constexpr bool value
Definition type_traits.h:84