OOStuBS - Technische Informatik II (TI-II)  2.4
o_stream.cc
gehe zur Dokumentation dieser Datei
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2  * Technische Informatik II *
3  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4  * *
5  * O _ S T R E A M *
6  * *
7 \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8 
9 #include "common/o_stream.h"
10 
11 O_Stream::O_Stream() : Stringbuffer(), fgColor(WHITE), bgColor(BLACK), blink(false), base(dec){
12 }
13 
15 }
16 
18  put(c);
19  return *this;
20 }
21 
22 O_Stream& O_Stream::operator << (unsigned char value) {
23  return *this << (char)value;
24 }
25 
27  return *this << (const char*)value;
28 }
29 
30 O_Stream& O_Stream::operator << (const char* string) {
31  while (*string)
32  put (*string++);
33  return *this;
34 }
35 
37  return *this << (long)value;
38 }
39 
40 O_Stream& O_Stream::operator << (unsigned short value) {
41  return *this << (unsigned long)value;
42 }
43 
44 
46  return *this << (long)value;
47 }
48 
49 
50 O_Stream& O_Stream::operator << (unsigned int value) {
51  return *this << (unsigned long)value;
52 
53 }
54 
56  // if value is negative a minus is outputed first
57  if (ival < 0) {
58  put ('-');
59  ival = -ival;
60  }
61  // than the absolute value of the digit is outputed
62  return *this << (unsigned long) ival;
63 }
64 
65 O_Stream& O_Stream::operator << (unsigned long ival) {
66  unsigned long div;
67  char digit;
68 
69  if (base == 8)
70  put ('0'); // oktal digits start with a NULL
71  else if (base == 16) {
72  put ('0'); // hexadezimal digits start with 0x
73  put ('x');
74  }
75 
76  // computes the max power of the choosen basis, that is smaler than the value
77  // of the digit
78  for (div = 1; ival/div >= (unsigned long) base; div *= base);
79 
80  // prints the digit character after character
81  for (; div > 0; div /= (unsigned long) base) {
82  digit = ival / div;
83  if (digit < 10)
84  put ('0' + digit);
85  else
86  put ('a' + digit - 10);
87  ival %= div;
88  }
89  return *this;
90 }
91 
93  Base oldbase = base;
94  base = hex;
95  *this << (unsigned long) ptr;
96  base = oldbase;
97  return *this;
98 }
99 
101  flush();
102  fgColor = color.color;
104  return *this;
105 }
106 
107 
109  flush();
110  bgColor = color.color;
112  return *this;
113 }
114 
115 
117  flush();
118  this->blink = blink.blink;
119  setAttributes(fgColor, bgColor, this->blink);
120  return *this;
121 }
122 
124  os << '\n';
125  os.flush ();
126  return os;
127 }
128 
129 
131  os.base = O_Stream::bin;
132  return os;
133 }
134 
135 
137  os.base = O_Stream::oct;
138  return os;
139 }
140 
141 
143  os.base = O_Stream::dec;
144  return os;
145 }
146 
147 
149  os.base = O_Stream::hex;
150  return os;
151 }
152 
154  return f(*this);
155 }