00001
00002
00003
00004
00005
00006
00007
00008 #include <system/config.h>
00009
00010 #ifndef __ostream_h
00011 #define __ostream_h
00012
00013 __BEGIN_SYS
00014
00015 class OStream
00016 {
00017 public:
00018 OStream & operator<<(char c) {
00019 char buf[2];
00020 buf[0] = c;
00021 buf[1] = '\0';
00022 print(buf);
00023 return *this;
00024 }
00025 OStream & operator<<(unsigned char c) { return operator<<((char)c); }
00026
00027 OStream & operator<<(int i) {
00028 char buf[64];
00029 buf[itoa(i, buf)] = '\0';
00030 print(buf);
00031 return *this;
00032 }
00033 OStream & operator<<(short s) { return operator<<((int)s); }
00034 OStream & operator<<(long l) { return operator<<((int)l); }
00035
00036 OStream & operator<<(unsigned int u) {
00037 char buf[64];
00038 buf[utoa(u, buf)] = '\0';
00039 print(buf);
00040 return *this;
00041 }
00042 OStream & operator<<(unsigned short s) { return operator<<((unsigned)s); }
00043 OStream & operator<<(unsigned long l) { return operator<<((unsigned)l); }
00044
00045 OStream & operator<<(long long int u) {
00046 char buf[64];
00047 buf[llitoa(u, buf)] = '\0';
00048 print(buf);
00049 return *this;
00050 }
00051
00052 OStream & operator<<(unsigned long long int u) {
00053 char buf[64];
00054 buf[llutoa(u, buf)] = '\0';
00055 print(buf);
00056 return *this;
00057 }
00058
00059 OStream & operator<<(const void * p) {
00060 char buf[64];
00061 buf[ptoa(p, buf)] = '\0';
00062 print(buf);
00063 return *this;
00064 }
00065
00066 OStream & operator<<(const char * s) {
00067 print(s);
00068 return *this;
00069 }
00070
00071 private:
00072 void print(const char * s);
00073 int itoa(int i, char * s);
00074 int utoa(unsigned int u, char * s);
00075 int llitoa(long long int i, char * s);
00076 int llutoa(unsigned long long int u, char * s);
00077 int ptoa(const void * p, char * s);
00078
00079 private:
00080 static const char OStream::dec_digits[];
00081 static const char OStream::hex_digits[];
00082 };
00083
00084 extern OStream kout, kerr;
00085 static const char* endl = "\n";
00086
00087 __END_SYS
00088
00089 #endif