1

initial reformat, still has misformats

This commit is contained in:
churl
2022-04-25 14:24:56 +02:00
parent 67fce9ff2d
commit 263563c105
20 changed files with 295 additions and 317 deletions

View File

@ -23,11 +23,11 @@
#include "lib/OutStream.h"
// NOTE: I added this, stream manipulators with arg
OutStream& OutStream::operator << (const fillw& w) {
OutStream& OutStream::operator<<(const fillw& w) {
this->fill_width = w.w;
return *this;
}
OutStream& OutStream::operator << (const fillc& c) {
OutStream& OutStream::operator<<(const fillc& c) {
this->fill_char = c.c;
return *this;
}
@ -70,27 +70,27 @@ void OutStream::fill_use_char() {
//
// Zeichen und Zeichenketten in Stream ausgeben
//
OutStream& OutStream::operator << (char c) {
OutStream& OutStream::operator<<(char c) {
put(c);
if (c != '\n') {
// endl() doesn't has access to StringBuffer::put(), so ignore \n here
this->fill_finalize(); // NOTE: I added this
this->fill_finalize(); // NOTE: I added this
}
return *this;
}
// TODO: shouldn't this be printed as number?
OutStream& OutStream::operator << (unsigned char c) {
return *this << (char) c;
OutStream& OutStream::operator<<(unsigned char c) {
return *this << (char)c;
}
OutStream& OutStream::operator << (char* string) {
OutStream& OutStream::operator<<(char* string) {
char* pos = string;
while (*pos) {
put (*pos);
put(*pos);
pos++;
}
this->fill_finalize(); // NOTE: I added this
this->fill_finalize(); // NOTE: I added this
return *this;
}
@ -98,74 +98,75 @@ OutStream& OutStream::operator << (char* string) {
// Ganzer Zahlen im Zahlensystem zur Basis base in Stream ausgeveb
// Alle vorzeichenbehafteten Datentypen werden als long dargestellt,
// Alle vorzeichenlosen als unsigned long.
OutStream& OutStream::operator << (short ival) {
return *this << (long) ival;
OutStream& OutStream::operator<<(short ival) {
return *this << (long)ival;
}
OutStream& OutStream::operator << (unsigned short ival) {
return *this << (unsigned long) ival;
OutStream& OutStream::operator<<(unsigned short ival) {
return *this << (unsigned long)ival;
}
OutStream& OutStream::operator << (int ival) {
return *this << (long) ival;
OutStream& OutStream::operator<<(int ival) {
return *this << (long)ival;
}
OutStream& OutStream::operator << (unsigned int ival) {
return *this << (unsigned long) ival;
OutStream& OutStream::operator<<(unsigned int ival) {
return *this << (unsigned long)ival;
}
// Darstellung eine vorzeichenbehafteten ganzen Zahl.
OutStream& OutStream::operator << (long ival) {
OutStream& OutStream::operator<<(long ival) {
// Bei negativen Werten wird ein Minuszeichen ausgegeben.
if (ival < 0) {
put ('-');
put('-');
ival = -ival;
}
// Dann wird der Absolutwert als vorzeichenlose Zahl ausgegeben.
return *this << (unsigned long) ival;
return *this << (unsigned long)ival;
}
// Darstellung einer vorzeichenlosen ganzen Zahl.
OutStream& OutStream::operator << (unsigned long ival) {
OutStream& OutStream::operator<<(unsigned long ival) {
unsigned long div;
char digit;
if (base == 8) {
put ('0'); // oktale Zahlen erhalten eine fuehrende Null
put('0'); // oktale Zahlen erhalten eine fuehrende Null
} else if (base == 16) {
put ('0'); // hexadezimale Zahlen ein "0x"
put ('x');
put('0'); // hexadezimale Zahlen ein "0x"
put('x');
}
// Bestimmung der groessten Potenz der gewaehlten Zahlenbasis, die
// noch kleiner als die darzustellende Zahl ist.
for (div = 1; ival/div >= (unsigned long) base; div *= base);
for (div = 1; ival / div >= (unsigned long)base; div *= base)
;
// ziffernweise Ausgabe der Zahl
for (; div > 0; div /= (unsigned long) base) {
for (; div > 0; div /= (unsigned long)base) {
digit = ival / div;
if (digit < 10) {
put ('0' + digit);
put('0' + digit);
} else {
put ('a' + digit - 10);
put('a' + digit - 10);
}
ival %= div;
}
this->fill_finalize(); // NOTE: I added this
this->fill_finalize(); // NOTE: I added this
return *this;
}
// Darstellung eines Zeigers als hexadezimale ganze Zahl
OutStream& OutStream::operator << (void* ptr) {
OutStream& OutStream::operator<<(void* ptr) {
int oldbase = base;
base = 16;
*this << (unsigned long) ptr;
*this << (unsigned long)ptr;
base = oldbase;
return *this;
}
}
// Aufruf einer Manipulatorfunktion
OutStream& OutStream::operator << (OutStream& (*f) (OutStream&)) {
OutStream& OutStream::operator<<(OutStream& (*f)(OutStream&)) {
return f(*this);
}
@ -180,33 +181,32 @@ OutStream& OutStream::operator << (OutStream& (*f) (OutStream&)) {
// zu beeinflussen, z.B durch die Wahl des Zahlensystems.
// Fuege einen Zeilenumbruch in die Ausgabe ein.
OutStream& endl (OutStream& os) {
OutStream& endl(OutStream& os) {
os << '\n';
os.flush();
return os;
}
// Waehlt das binaere Zahlensystem aus.
OutStream& bin (OutStream& os) {
OutStream& bin(OutStream& os) {
os.base = 2;
return os;
}
// Waehlt das oktale Zahlensystem aus.
OutStream& oct (OutStream& os) {
OutStream& oct(OutStream& os) {
os.base = 8;
return os;
}
// Waehlt das dezimale Zahlensystem aus.
OutStream& dec (OutStream& os) {
OutStream& dec(OutStream& os) {
os.base = 10;
return os;
}
// Waehlt das hexadezimale Zahlensystem aus.
OutStream& hex (OutStream& os) {
OutStream& hex(OutStream& os) {
os.base = 16;
return os;
}

View File

@ -30,76 +30,74 @@ class OutStream;
// TODO: Should this only work for the next << ?
class fillw {
public:
fillw(unsigned char w) : w(w) {};
unsigned char w;
fillw(unsigned char w) : w(w) {};
unsigned char w;
};
class fillc {
public:
fillc(char c) : c(c) {};
char c;
fillc(char c) : c(c) {};
char c;
};
class OutStream : public StringBuffer {
private:
OutStream(const OutStream &copy); // Verhindere Kopieren
OutStream(const OutStream& copy); // Verhindere Kopieren
// NOTE: I added this
unsigned char fill_used; // indicates how many characters are already used by the text internally
void fill_use_char(); // recognizes that one char from the print width has been used up
void fill_finalize(); // does the filling after text has been written to buffer
// NOTE: I added this
unsigned char fill_used; // indicates how many characters are already used by the text internally
void fill_use_char(); // recognizes that one char from the print width has been used up
void fill_finalize(); // does the filling after text has been written to buffer
public:
int base; // Basis des Zahlensystems: z.B. 2, 8, 10 oder 16
int base; // Basis des Zahlensystems: z.B. 2, 8, 10 oder 16
// NOTE: I added this
unsigned char fill_width;
char fill_char; // fill character for fixed width
// NOTE: I added this
unsigned char fill_width;
char fill_char; // fill character for fixed width
OutStream () : StringBuffer () {
base = 10; // initial Dezimalsystem
fill_width = 0; // no fixed width
fill_used = 0;
fill_char = ' '; // fill with spaces
}
OutStream() : StringBuffer() {
base = 10; // initial Dezimalsystem
fill_width = 0; // no fixed width
fill_used = 0;
fill_char = ' '; // fill with spaces
}
void flush() override = 0; // weiterhin undefiniert aber public
void flush() override = 0; // weiterhin undefiniert aber public
// NOTE: I added this
void put(char c) override;
// NOTE: I added this
void put(char c) override;
// OPERATOR << : Umwandlung des angegebenen Datentypes in eine
// Zeichenkette.
// OPERATOR << : Umwandlung des angegebenen Datentypes in eine
// Zeichenkette.
// Darstellung eines Zeichens (trivial)
OutStream& operator << (char c);
OutStream& operator << (unsigned char c);
// Darstellung eines Zeichens (trivial)
OutStream& operator<<(char c);
OutStream& operator<<(unsigned char c);
// Darstellung einer nullterminierten Zeichenkette
OutStream& operator << (char* string);
// Darstellung einer nullterminierten Zeichenkette
OutStream& operator<<(char* string);
// Darstellung ganzer Zahlen im Zahlensystem zur Basis base
OutStream& operator << (short ival);
OutStream& operator << (unsigned short ival);
OutStream& operator << (int ival);
OutStream& operator << (unsigned int ival);
OutStream& operator << (long ival);
OutStream& operator << (unsigned long ival);
// Darstellung ganzer Zahlen im Zahlensystem zur Basis base
OutStream& operator<<(short ival);
OutStream& operator<<(unsigned short ival);
OutStream& operator<<(int ival);
OutStream& operator<<(unsigned int ival);
OutStream& operator<<(long ival);
OutStream& operator<<(unsigned long ival);
// Darstellung eines Zeigers als hexadezimale ganze Zahl
OutStream& operator << (void* ptr);
// Darstellung eines Zeigers als hexadezimale ganze Zahl
OutStream& operator<<(void* ptr);
// NOTE: I added this, set fixed output width
OutStream &operator << (const fillw &w);
OutStream &operator << (const fillc &c);
// NOTE: I added this, set fixed output width
OutStream& operator<<(const fillw& w);
OutStream& operator<<(const fillc& c);
// Aufruf einer Manipulatorfunktion
OutStream& operator << (OutStream& (*f) (OutStream&));
// Aufruf einer Manipulatorfunktion
OutStream& operator<<(OutStream& (*f)(OutStream&));
};
//
// Manipulatorfunktionen
//
@ -111,18 +109,18 @@ public:
// zu beeinflussen, z.B durch die Wahl des Zahlensystems.
// Zeilenumbruch in Ausgabe einfuegen.
OutStream& endl (OutStream& os);
OutStream& endl(OutStream& os);
// Waehle binaeres Zahlensystem aus.
OutStream& bin (OutStream& os);
OutStream& bin(OutStream& os);
// Waehle oktales Zahlensystem aus.
OutStream& oct (OutStream& os);
OutStream& oct(OutStream& os);
// Waehle dezimales Zahlensystem aus.
OutStream& dec (OutStream& os);
OutStream& dec(OutStream& os);
// Waehle hexadezimales Zahlensystem aus.
OutStream& hex (OutStream& os);
OutStream& hex(OutStream& os);
#endif

View File

@ -18,7 +18,6 @@
#include "lib/StringBuffer.h"
/*****************************************************************************
* Methode: StringBuffer::put *
*---------------------------------------------------------------------------*
@ -29,10 +28,9 @@
* Parameter: *
* c: Einzufuegendes Zeichen. *
*****************************************************************************/
void StringBuffer::put (char c) {
void StringBuffer::put(char c) {
buffer[pos] = c;
pos++;
if (pos == sizeof (buffer))
flush ();
}
if (pos == sizeof(buffer))
flush();
}

View File

@ -19,9 +19,9 @@
#define __StringBuffer_include__
class StringBuffer {
private:
StringBuffer(const StringBuffer &copy); // Verhindere Kopieren
StringBuffer(const StringBuffer& copy); // Verhindere Kopieren
// Alle Variablen und Methoden dieser Klasse sind "protected",
// da die abgeleiteten Klassen einen direkten Zugriff auf den
@ -34,15 +34,14 @@ protected:
int pos;
// StringBuffer: Im Konstruktor wird der Puffer als leer markiert.
StringBuffer () : pos(0) {}
StringBuffer() : pos(0) {}
// NOTE: I changed this
// NOTE: I changed this
// Fuegt ein Zeichen in den Puffer ein. Wenn der Puffer
virtual void put (char c);
virtual void put(char c);
// Methode zur Ausgabe des Pufferinhalts
virtual void flush () = 0;
virtual void flush() = 0;
};
#endif