blocxx

FuncNamePrinter.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2005, Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2006, Novell, Inc. All rights reserved.
00004 * 
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions are met:
00007 * 
00008 *     * Redistributions of source code must retain the above copyright notice,
00009 *       this list of conditions and the following disclaimer.
00010 *     * Redistributions in binary form must reproduce the above copyright
00011 *       notice, this list of conditions and the following disclaimer in the
00012 *       documentation and/or other materials provided with the distribution.
00013 *     * Neither the name of 
00014 *       Vintela, Inc., 
00015 *       nor Novell, Inc., 
00016 *       nor the names of its contributors or employees may be used to 
00017 *       endorse or promote products derived from this software without 
00018 *       specific prior written permission.
00019 * 
00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030 * POSSIBILITY OF SUCH DAMAGE.
00031 *******************************************************************************/
00032 
00033 
00039 #ifndef BLOCXX_FUNC_NAME_PRINTER_HPP
00040 #define BLOCXX_FUNC_NAME_PRINTER_HPP
00041 #include "blocxx/BLOCXX_config.h"
00042 #include "blocxx/Format.hpp"
00043 #include <stdio.h>
00044 #include <unistd.h>
00045 
00046 // The classes and functions defined in this file are not meant for general
00047 // use, they are internal implementation details.  They may change at any time.
00048 
00049 // For printing function names during debug
00050 #ifdef BLOCXX_PRINT_FUNC_DEBUG
00051 #define PRINT_FUNC_NAME BLOCXX_FuncNamePrinter fnp##__LINE__ (__PRETTY_FUNCTION__)
00052 
00053 #define PRINT_FUNC_NAME_ARGS1(a) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a)
00054 #define PRINT_FUNC_NAME_ARGS2(a, b) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b)
00055 #define PRINT_FUNC_NAME_ARGS3(a, b, c) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b, c)
00056 #define PRINT_FUNC_NAME_ARGS4(a, b, c, d) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b, c, d)
00057 #define PRINT_FUNC_NAME_ARGS5(a, b, c, d, e) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b, c, d, e)
00058 #define PRINT_FUNC_NAME_ARGS6(a, b, c, d, e, f) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b, c, d, e, f)
00059 #define PRINT_FUNC_NAME_ARGS7(a, b, c, d, e, f, g) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b, c, d, e, f, g)
00060 #define PRINT_FUNC_NAME_ARGS8(a, b, c, d, e, f, g, h) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b, c, d, e, f, g, h)
00061 #define PRINT_FUNC_NAME_ARGS9(a, b, c, d, e, f, g, h, i) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b, c, d, e, f, g, h, i)
00062 #define PRINT_FUNC_NAME_ARGS10(a, b, c, d, e, f, g, h, i, j) BLOCXX_FuncNamePrinter fnp##__LINE__ ( __PRETTY_FUNCTION__ , a, b, c, d, e, f, g, h, i, j)
00063 #else
00064 #define PRINT_FUNC_NAME_ARGS1(a)
00065 #define PRINT_FUNC_NAME_ARGS2(a, b)
00066 #define PRINT_FUNC_NAME_ARGS3(a, b, c)
00067 #define PRINT_FUNC_NAME_ARGS4(a, b, c, d)
00068 #define PRINT_FUNC_NAME_ARGS5(a, b, c, d, e)
00069 #define PRINT_FUNC_NAME_ARGS6(a, b, c, d, e, f)
00070 #define PRINT_FUNC_NAME_ARGS7(a, b, c, d, e, f, g)
00071 #define PRINT_FUNC_NAME_ARGS8(a, b, c, d, e, f, g, h)
00072 #define PRINT_FUNC_NAME_ARGS9(a, b, c, d, e, f, g, h, i)
00073 #define PRINT_FUNC_NAME_ARGS10(a, b, c, d, e, f, g, h, i, j)
00074 #define PRINT_FUNC_NAME
00075 #endif /* #ifdef BLOCXX_PRINT_FUNC_DEBUG */
00076 
00077 namespace BLOCXX_NAMESPACE
00078 {
00079 
00080 class FuncNamePrinter
00081 {
00082 private:
00083    const char* m_funcName;
00084 public:
00085    
00086    FuncNamePrinter(const char* funcName) : m_funcName(funcName)
00087    {
00088       fprintf(stderr, "%d Entering: %s\n", getpid(), funcName);
00089    }
00090    template<typename A>
00091       FuncNamePrinter(const char* funcName, const A& a) : m_funcName(funcName)
00092       {
00093          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00094             Format("(%1)", a).c_str());
00095       }
00096    template<typename A, typename B>
00097       FuncNamePrinter(const char* funcName, const A& a, const B& b) : m_funcName(funcName)
00098       {
00099          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00100             Format("(%1, %2)", a, b).c_str());
00101       }
00102    template<typename A, typename B, typename C>
00103       FuncNamePrinter(const char* funcName, const A& a, const B& b, const C& c) : m_funcName(funcName)
00104       {
00105          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00106             Format("(%1, %2, %3)", a, b, c).c_str());
00107       }
00108    template<typename A, typename B, typename C, typename D>
00109       FuncNamePrinter(const char* funcName, const A& a, const B& b, const C& c, const D& d) : m_funcName(funcName)
00110       {
00111          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00112             Format("(%1, %2, %3, %4)", a, b, c, d).c_str());
00113       }
00114    template<typename A, typename B, typename C, typename D, typename E>
00115       FuncNamePrinter(const char* funcName, const A& a, const B& b, const C& c, const D& d, const E& e) : m_funcName(funcName)
00116       {
00117          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00118             Format("(%1, %2, %3, %4, %5)", a, b, c, d, e).c_str());
00119       }
00120    template<typename A, typename B, typename C, typename D, typename E, typename F>
00121       FuncNamePrinter(const char* funcName, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f) : m_funcName(funcName)
00122       {
00123          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00124             Format("(%1, %2, %3, %4, %5, %6)", a, b, c, d, e, f).c_str());
00125       }
00126    template<typename A, typename B, typename C, typename D, typename E, typename F,
00127    typename G>
00128       FuncNamePrinter(const char* funcName, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g) : m_funcName(funcName)
00129       {
00130          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00131             Format("(%1, %2, %3, %4, %5, %6, %7)", a, b, c, d, e, f, g).c_str());
00132       }
00133    template<typename A, typename B, typename C, typename D, typename E, typename F,
00134    typename G, typename H>
00135       FuncNamePrinter(const char* funcName, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g, const H& h) : m_funcName(funcName)
00136       {
00137          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00138             Format("(%1, %2, %3, %4, %5, %6, %7, %8)", a, b, c, d, e, f, g, h).c_str());
00139       }
00140    template<typename A, typename B, typename C, typename D, typename E, typename F,
00141    typename G, typename H, typename I>
00142       FuncNamePrinter(const char* funcName, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g, const H& h, const I& i) : m_funcName(funcName)
00143       {
00144          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00145             Format("(%1, %2, %3, %4, %5, %6, %7, %8, %9)", a, b, c, d, e, f, g, h, i).c_str());
00146       }
00147    template<typename A, typename B, typename C, typename D, typename E, typename F,
00148    typename G, typename H, typename I, typename J>
00149       FuncNamePrinter(const char* funcName, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g, const H& h, const I& i, const J& j) : m_funcName(funcName)
00150       {
00151          fprintf(stderr, "%d Entering: %s\n\t%s\n", getpid(), funcName, 
00152             Format("(%1, %2, %3, %4, %5, %6, %7, %8, %9)", a, b, c, d, e, f, g, h, Format("%1, %2", i, j)).c_str());
00153       }
00154    ~FuncNamePrinter()
00155       { fprintf(stderr, "%d Leaving:  %s\n", getpid(), m_funcName); }
00156 }; // class FuncNamePrinter
00157 
00158 } // end namespace BLOCXX_NAMESPACE
00159 
00160 #endif //#define BLOCXX_FUNC_NAME_PRINTER_HPP