templates for << chaining + new manipulators
This commit is contained in:
@ -25,16 +25,21 @@
|
||||
*****************************************************************************/
|
||||
void CGA_Stream::flush() {
|
||||
print(buffer, pos, attribute(this->color_bg, this->color_fg, this->blink));
|
||||
|
||||
// Flushing resets attributes
|
||||
this->blink = false;
|
||||
this->color_bg = CGA::BLACK;
|
||||
this->color_fg = CGA::LIGHT_GREY;
|
||||
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
// NOTE: I added this
|
||||
// TODO
|
||||
// CGA_Stream& CGA_Stream::operator<<(const fgc& fg) {
|
||||
// this->color_fg = fg.fg;
|
||||
// return *this;
|
||||
// }
|
||||
// CGA_Stream& CGA_Stream::operator<<(const bgc& bg) {
|
||||
// this->color_bg = bg.bg;
|
||||
// return *this;
|
||||
// Alternative way to write the templates which keeps definition separated
|
||||
// Usable for our case but somehow defeats the purpose of templates
|
||||
// template<typename T>
|
||||
// T& operator<<(T& os, const fgc& fg) {
|
||||
// os.color_fg = fg.fg;
|
||||
// return os;
|
||||
// }
|
||||
|
||||
// template CGA_Stream& operator<<<CGA_Stream>(CGA_Stream&, const fgc&);
|
||||
|
||||
@ -53,9 +53,19 @@ public:
|
||||
void flush() override;
|
||||
|
||||
// NOTE: I added this
|
||||
// TODO: Problem: Implementing this here breaks the << chaining
|
||||
// CGA_Stream& operator<<(const fgc&);
|
||||
// CGA_Stream& operator<<(const bgc&);
|
||||
template<typename T>
|
||||
friend T& operator<<(T& os, const fgc& fg) {
|
||||
os.flush();
|
||||
os.color_fg = fg.fg;
|
||||
return os;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
friend T& operator<<(T& os, const bgc& bg) {
|
||||
os.flush();
|
||||
os.color_fg = bg.bg;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user