CrystalSpace

Public API Reference

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

csutil/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 
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 

Generated for Crystal Space by doxygen 1.2.18