paulbergmann_mpstubs/object/outputstream.cc

77 lines
1.4 KiB
C++

#include "outputstream.h"
OutputStream& OutputStream::operator<<(char c) {
put(c);
return *this;
}
OutputStream& OutputStream::operator<<(unsigned char c) {
put(static_cast<char>(c));
return *this;
}
OutputStream& OutputStream::operator<< (const char* string) {
// check for sufficient space
// string length = sizeof(string)/sizeof(char)
// max size of buffer = sizeof(buffer)/sizeof(char)
// next position = pos
if (sizeof(string)/sizeof(char) <= (sizeof(buffer)/sizeof(char)) - pos) {
for (int i = 0; i < sizeof(string)/sizeof(char); i++) {
put(string[i]);
}
}
}
OutputStream& OutputStream::operator<< (bool b) {
if (b) {
OutputStream::operator<<("True");
}
else {
OutputStream::operator<<("False");
}
return *this;
}
OutputStream& OutputStream::operator<< (short ival) {
if (base = 2) {
}
return *this;
}
OutputStream& OutputStream::operator<< (const void* ptr) {
return *this;
}
OutputStream& OutputStream::operator<< (OutputStream& (*f) (OutputStream&)) {
return f(*this);
}
OutputStream& bin(OutputStream& os) {
os -> base = 2;
return os;
}
OutputStream& hex(OutputStream& os) {
os -> base = 16;
return os;
}
OutputStream& oct(OutputStream& os) {
os -> base = 8;
return os;
}
OutputStream& dec(OutputStream& os) {
os -> base = 10;
return os;
}
OutputStream& endl(OutputStream& os) {
os << "\n";
os.flush();
return os;
}