FastLED 3.9.15
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/gfx/crgb.h" // IWYU pragma: keep
6#include "fl/stl/move.h" // IWYU pragma: keep
7#include "fl/stl/string.h"
8#include "fl/stl/ios.h" // IWYU pragma: keep
9
10// Include cstdio for print function
11#include "fl/stl/cstdio.h"
12#include "fl/stl/noexcept.h"
13
14namespace fl {
15
16class ostream {
17public:
18 ostream() = default;
19
20 // Stream output operators that immediately print
21 ostream& operator<<(const char* str) FL_NOEXCEPT {
22 if (str) {
23 print(str);
24 }
25 return *this;
26 }
27
28 ostream& operator<<(const string& str) FL_NOEXCEPT {
29 print(str.c_str());
30 return *this;
31 }
32
34 char str[2] = {c, '\0'};
35 print(str);
36 return *this;
37 }
38
41 ostream& operator<<(fl::i16 n) FL_NOEXCEPT;
42 ostream& operator<<(fl::i32 n) FL_NOEXCEPT;
43 ostream& operator<<(fl::u32 n) FL_NOEXCEPT;
44
46 string temp;
47 temp.append(f);
48 print(temp.c_str());
49 return *this;
50 }
51
53 string temp;
54 temp.append(d);
55 print(temp.c_str());
56 return *this;
57 }
58
60 string temp;
61 temp.append(rgb);
62 print(temp.c_str());
63 return *this;
64 }
65
66 // Generic integer handler using SFINAE - handles all multi-byte integer types
67 // (including unsigned long on Windows) by casting to the appropriate fl:: type.
68 // Mirrors the pattern used by sstream.
69 template<typename T>
71 operator<<(T val) FL_NOEXCEPT {
72 using target_t = typename int_cast_detail::cast_target<T>::type;
73 string temp;
74 temp.append(static_cast<target_t>(val));
75 print(temp.c_str());
76 return *this;
77 }
78
79 // Get current formatting base (1=decimal, 16=hex, 8=octal)
80 int getBase() const FL_NOEXCEPT { return mBase; }
81
82 // Friend operators for manipulators
83 friend ostream& operator<<(ostream&, const hex_t&) FL_NOEXCEPT;
84 friend ostream& operator<<(ostream&, const dec_t&) FL_NOEXCEPT;
85 friend ostream& operator<<(ostream&, const oct_t&) FL_NOEXCEPT;
86
87private:
88 int mBase = 10; // Default to decimal
89};
90
91// Global cout instance for immediate output
92extern ostream cout;
93
94// Line ending manipulator
95struct endl_t {};
96extern const endl_t endl;
97
98// endl manipulator implementation
100 os << "\n";
101 return os;
102}
103
104// hex, dec, oct manipulator implementations
105// (declared as friend functions in ostream class, implemented in ostream.cpp)
106ostream& operator<<(ostream& os, const hex_t&) FL_NOEXCEPT;
107ostream& operator<<(ostream& os, const dec_t&) FL_NOEXCEPT;
108ostream& operator<<(ostream& os, const oct_t&) FL_NOEXCEPT;
109
110} // namespace fl
const char * c_str() const FL_NOEXCEPT
int mBase
Definition ostream.h:88
ostream & operator<<(float f) FL_NOEXCEPT
Definition ostream.h:45
int getBase() const FL_NOEXCEPT
Definition ostream.h:80
ostream()=default
ostream & operator<<(double d) FL_NOEXCEPT
Definition ostream.h:52
ostream & operator<<(const CRGB &rgb) FL_NOEXCEPT
Definition ostream.h:59
ostream & operator<<(const string &str) FL_NOEXCEPT
Definition ostream.h:28
ostream & operator<<(const char *str) FL_NOEXCEPT
Definition ostream.h:21
ostream & operator<<(char c) FL_NOEXCEPT
Definition ostream.h:33
string & append(const bitset_fixed< N > &bs) FL_NOEXCEPT
Definition string.h:284
Defines the 8-bit red, green, and blue (RGB) pixel type in the fl namespace.
unsigned char u8
Definition s16x16x4.h:132
signed char i8
Definition s16x16x4.h:131
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
const endl_t endl
void print(const char *str)
ostream & operator<<(ostream &os, const hex_t &) FL_NOEXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38