indent.hxx

Go to the documentation of this file.
00001 /*
00002  *   xyzzy
00003  *   Copyright (C) 2007    Karl W. Pfalzer
00004  *
00005  *   This program is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU General Public License
00007  *   as published by the Free Software Foundation; either version 2
00008  *   of the License, or (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with this program; if not, write to the
00017  *   Free Software Foundation, Inc.
00018  *   51 Franklin Street, Fifth Floor
00019  *   Boston, MA  02110-1301, USA.
00020  */
00021 
00022 #if !defined(_xyzzy_indent_hxx_)
00023 #    define  _xyzzy_indent_hxx_
00024 
00025 #include <string>
00026 
00027 namespace xyzzy
00028 {
00029     class TIndent
00030     {
00031     public:
00032         TIndent(int indentAmt = 4);
00033         
00034         TIndent(const TIndent &s, bool indent = true);
00035 
00036         operator const char*() const
00037         {
00038             return m_indent.c_str();
00039         }
00040 
00041     private:
00042         static int  st_indentAmt;
00043         static bool st_notUsedYet;
00044 
00045         std::string m_indent;
00046     };
00047 };
00048 
00049 /*
00050   Following macros used as:
00051  
00052     TIndent start;
00053     ...
00054     // "indent" will be declared as "const char*" by BEGIN_INDENT() macro
00055     // for subsequent used.
00056     //
00057     BEGIN_INDENT(indent, start);
00058     ...
00059     cerr << indent << ...;
00060     ...
00061     END_INDENT(start);
00062  */
00063 
00064 #define BEGIN_INDENT(_indent,_indentRef)                    \
00065     xyzzy::TIndent __indentSaved(_indentRef, false);\
00066     _indentRef = xyzzy::TIndent(__indentSaved);     \
00067     const char *_indent = _indentRef
00068 
00069 #define END_INDENT(_indentRef) _indentRef = xyzzy::TIndent(__indentSaved,false)
00070 
00071 #endif  //#    define  _xyzzy_indent_hxx_

Generated on Thu Mar 22 13:51:07 2007 for anvil by  doxygen 1.5.1