00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_INDPRINT_H__
00020 #define __CS_INDPRINT_H__
00021
00022 #include <stdarg.h>
00023
00027 class csIndPrint
00028 {
00029 private:
00030 int cur_indent_level;
00031
00032 public:
00033 csIndPrint () : cur_indent_level (0) { }
00034
00036 void Up (int amount = 1) { cur_indent_level -= amount; }
00038 void Down (int amount = 1) { cur_indent_level += amount; }
00040 void Reset (int amount = 0) { cur_indent_level = amount; }
00041
00043 void Print (char* msg, ...)
00044 {
00045 int i = cur_indent_level;
00046 while (i >= 20) { printf (" "); i -= 20; }
00047 while (i >= 4) { printf (" "); i -= 4; }
00048 while (i >= 0) { printf (" "); i--; }
00049 va_list arg;
00050 va_start (arg, msg);
00051 vprintf (msg, arg);
00052 va_end (arg);
00053 fflush (stdout);
00054 }
00055 };
00056
00063 class csIndPrintDown
00064 {
00065 private:
00066 csIndPrint& indprint;
00067 int amount;
00068
00069 public:
00071 csIndPrintDown (csIndPrint& ip, int amount = 1) : indprint (ip)
00072 {
00073 csIndPrintDown::amount = amount;
00074 ip.Down (amount);
00075 }
00076 ~csIndPrintDown ()
00077 {
00078 indprint.Up (amount);
00079 }
00080 };
00081
00082 #endif // __CS_INDPRINT_H__
00083