CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

indprint.h

00001 /*
00002     Copyright (C) 2002 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_INDPRINT_H__
00020 #define __CS_INDPRINT_H__
00021 
00022 #include <stdarg.h>
00023 #include "csextern.h"
00024 
00028 class CS_CSUTIL_EXPORT csIndPrint
00029 {
00030 private:
00031   int cur_indent_level;
00032 
00033 public:
00034   csIndPrint () : cur_indent_level (0) { }
00035 
00037   void Up (int amount = 1) { cur_indent_level -= amount; }
00039   void Down (int amount = 1) { cur_indent_level += amount; }
00041   void Reset (int amount = 0) { cur_indent_level = amount; }
00042 
00044   void Print (char* msg, ...)
00045   {
00046     int i = cur_indent_level;
00047     while (i >= 20) { printf ("                    "); i -= 20; }
00048     while (i >= 4) { printf ("    "); i -= 4; }
00049     while (i >= 0) { printf (" "); i--; }
00050     va_list arg;
00051     va_start (arg, msg);
00052     vprintf (msg, arg);
00053     va_end (arg);
00054     fflush (stdout);
00055   }
00056 };
00057 
00064 class CS_CSUTIL_EXPORT csIndPrintDown
00065 {
00066 private:
00067   csIndPrint& indprint;
00068   int amount;
00069 
00070 public:
00072   csIndPrintDown (csIndPrint& ip, int amount = 1) : indprint (ip)
00073   {
00074     csIndPrintDown::amount = amount;
00075     ip.Down (amount);
00076   }
00077   ~csIndPrintDown ()
00078   {
00079     indprint.Up (amount);
00080   }
00081 };
00082 
00083 #endif // __CS_INDPRINT_H__
00084 

Generated for Crystal Space by doxygen 1.3.9.1