FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
empty_streams.h
Go to the documentation of this file.
1 // Copyright 2016-2021 Jean-Francois Poilpret
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
25 #ifndef EMPTYSTREAMS_HH
26 #define EMPTYSTREAMS_HH
27 
28 #include <stddef.h>
29 #include "ios.h"
30 #include "flash.h"
31 #include "utilities.h"
32 
33 namespace streams
34 {
70  {
71  public:
73  null_ostream() = default;
74  null_ostream(const null_ostream&) = delete;
75  null_ostream& operator=(const null_ostream&) = delete;
76 
77  void setf(ios::fmtflags flags UNUSED) {}
78 
79  void setf(ios::fmtflags flags UNUSED, ios::fmtflags mask UNUSED) {}
80 
81  void unsetf(ios::fmtflags flags UNUSED) {}
82 
83  void fill(char fill UNUSED) {}
84 
85  void width(uint8_t width UNUSED) {}
86 
87  void precision(uint8_t precision UNUSED) {}
88 
89  void flush() {}
90  void put(char val UNUSED) {}
91  void write(const char* content UNUSED, size_t size UNUSED) {}
92  void write(const char* str UNUSED) {}
93  void write(const flash::FlashStorage* str UNUSED) {}
94 
95  null_ostream& operator<<(const void* ptr UNUSED)
96  {
97  return *this;
98  }
99  null_ostream& operator<<(bool val UNUSED)
100  {
101  return *this;
102  }
103  null_ostream& operator<<(char val UNUSED)
104  {
105  return *this;
106  }
107  null_ostream& operator<<(const char* str UNUSED)
108  {
109  return *this;
110  }
111  null_ostream& operator<<(int val UNUSED)
112  {
113  return *this;
114  }
115  null_ostream& operator<<(unsigned int val UNUSED)
116  {
117  return *this;
118  }
119  null_ostream& operator<<(long val UNUSED)
120  {
121  return *this;
122  }
123  null_ostream& operator<<(unsigned long val UNUSED)
124  {
125  return *this;
126  }
127  null_ostream& operator<<(double val UNUSED)
128  {
129  return *this;
130  }
131 
132  typedef void (*Manipulator)(null_ostream&);
133  null_ostream& operator<<(Manipulator func UNUSED)
134  {
135  return *this;
136  }
138  };
139 
141  void bin(null_ostream& stream UNUSED) {}
142  void oct(null_ostream& stream UNUSED) {}
143  void dec(null_ostream& stream UNUSED) {}
144  void hex(null_ostream& stream UNUSED) {}
145  void flush(null_ostream& stream UNUSED) {}
146  void endl(null_ostream& stream UNUSED) {}
147  void skipws(null_ostream& stream UNUSED) {}
148  void noskipws(null_ostream& stream UNUSED) {}
149  void boolalpha(null_ostream& stream UNUSED) {}
150  void noboolalpha(null_ostream& stream UNUSED) {}
151  void showbase(null_ostream& stream UNUSED) {}
152  void noshowbase(null_ostream& stream UNUSED) {}
153  void showpos(null_ostream& stream UNUSED) {}
154  void noshowpos(null_ostream& stream UNUSED) {}
155  void uppercase(null_ostream& stream UNUSED) {}
156  void nouppercase(null_ostream& stream UNUSED) {}
157  void unitbuf(null_ostream& stream UNUSED) {}
158  void nounitbuf(null_ostream& stream UNUSED) {}
159  void left(null_ostream& stream UNUSED) {}
160  void right(null_ostream& stream UNUSED) {}
161  void fixed(null_ostream& stream UNUSED) {}
162  void scientific(null_ostream& stream UNUSED) {}
164 }
165 
166 #endif /* EMPTYSTREAMS_HH */
167 
streams::showpos
void showpos(FSTREAM &stream)
Set the ios::showpos format flag for stream.
Definition: ios.h:849
streams::ios_base::fmtflags
uint16_t fmtflags
Bitmask type to represent stream format flags.
Definition: ios.h:209
streams::showbase
void showbase(FSTREAM &stream)
Set the ios::showbase format flag for stream.
Definition: ios.h:821
streams::noshowbase
void noshowbase(FSTREAM &stream)
Clear the ios::showbase format flag for stream.
Definition: ios.h:836
streams::oct
void oct(FSTREAM &stream)
Manipulator for an output or input stream, which will set the base, used to represent (output) or int...
Definition: ios.h:756
streams::fixed
void fixed(FSTREAM &stream)
Set the ios::floatfield format flag for stream to ios::fixed.
Definition: ios.h:982
streams::noshowpos
void noshowpos(FSTREAM &stream)
Clear the ios::showpos format flag for stream.
Definition: ios.h:862
streams::endl
void endl(FSTREAM &stream)
Manipulator for an output stream, which will insert a new-line character and flush the stream buffer.
Definition: streams.h:722
streams::hex
void hex(FSTREAM &stream)
Manipulator for an output or input stream, which will set the base, used to represent (output) or int...
Definition: ios.h:774
streams::scientific
void scientific(FSTREAM &stream)
Set the ios::floatfield format flag for stream to ios::scientific.
Definition: ios.h:1000
streams::boolalpha
void boolalpha(FSTREAM &stream)
Set the ios::boolalpha format flag for stream.
Definition: ios.h:788
streams::nounitbuf
void nounitbuf(FSTREAM &stream)
Clear the ios::unitbuf format flag for stream.
Definition: ios.h:922
streams::skipws
void skipws(FSTREAM &stream)
Manipulator for an input stream, which will activate whitespace discarding before formatted input ope...
Definition: ios.h:729
streams::right
void right(FSTREAM &stream)
Set the ios::adjustfield format flag for stream to ios::right, thus adjusting next output to the righ...
Definition: ios.h:948
UNUSED
#define UNUSED
Specific GCC attribute to declare an argument or variable unused, so that the compiler does not emit ...
Definition: defines.h:45
utilities.h
General utilities API that have broad application in programs.
ios.h
C++-like std::iostream facilities.
streams::dec
void dec(FSTREAM &stream)
Manipulator for an output or input stream, which will set the base, used to represent (output) or int...
Definition: ios.h:765
streams::noskipws
void noskipws(FSTREAM &stream)
Manipulator for an input stream, which will deactivate whitespace discarding before formatted input o...
Definition: ios.h:738
streams
Defines C++-like streams API, based on circular buffers for input or output.
Definition: empty_streams.h:34
streams::null_ostream
Implements an empty formatted output that does nothing.
Definition: empty_streams.h:70
streams::bin
void bin(FSTREAM &stream)
Manipulator for an output or input stream, which will set the base, used to represent (output) or int...
Definition: ios.h:747
streams::uppercase
void uppercase(FSTREAM &stream)
Set the ios::uppercase format flag for stream.
Definition: ios.h:877
streams::noboolalpha
void noboolalpha(FSTREAM &stream)
Clear the ios::boolalpha format flag for stream.
Definition: ios.h:801
streams::left
void left(FSTREAM &stream)
Set the ios::adjustfield format flag for stream to ios::left, thus adjusting next output to the left.
Definition: ios.h:935
streams::nouppercase
void nouppercase(FSTREAM &stream)
Clear the ios::uppercase format flag for stream.
Definition: ios.h:892
streams::unitbuf
void unitbuf(FSTREAM &stream)
Set the ios::unitbuf format flag for stream.
Definition: ios.h:906
streams::flush
void flush(FSTREAM &stream)
Manipulator for an output stream, which will flush the stream buffer.
Definition: streams.h:713
flash.h
Flash memory utilities.