PageRenderTime 32ms CodeModel.GetById 29ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/test/debug.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 85 lines | 37 code | 10 blank | 38 comment | 0 complexity | d657de9a080c9fbd550b8caf8ec35a1a MD5 | raw file
 1/**
 2 * @file   debug.h
 3 * @author Nat Goodspeed
 4 * @date   2009-05-28
 5 * @brief  Debug output for unit test code
 6 * 
 7 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
 8 * Second Life Viewer Source Code
 9 * Copyright (C) 2010, Linden Research, Inc.
10 * 
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation;
14 * version 2.1 of the License only.
15 * 
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Lesser General Public License for more details.
20 * 
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 * 
25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
26 * $/LicenseInfo$
27 */
28
29#if ! defined(LL_DEBUG_H)
30#define LL_DEBUG_H
31
32#include <iostream>
33
34/*****************************************************************************
35*   Debugging stuff
36*****************************************************************************/
37// This class is intended to illuminate entry to a given block, exit from the
38// same block and checkpoints along the way. It also provides a convenient
39// place to turn std::cout output on and off.
40class Debug
41{
42public:
43    Debug(const std::string& block):
44        mBlock(block)
45    {
46        (*this)("entry");
47    }
48
49    ~Debug()
50    {
51        (*this)("exit");
52    }
53
54    void operator()(const std::string& status)
55    {
56#if defined(DEBUG_ON)
57        std::cout << mBlock << ' ' << status << std::endl;
58#endif
59    }
60
61private:
62    const std::string mBlock;
63};
64
65// It's often convenient to use the name of the enclosing function as the name
66// of the Debug block.
67#define DEBUG Debug debug(__FUNCTION__)
68
69// These BEGIN/END macros are specifically for debugging output -- please
70// don't assume you must use such for coroutines in general! They only help to
71// make control flow (as well as exception exits) explicit.
72#define BEGIN                                   \
73{                                               \
74    DEBUG;                                      \
75    try
76
77#define END                                     \
78    catch (...)                                 \
79    {                                           \
80        debug("*** exceptional ");              \
81        throw;                                  \
82    }                                           \
83}
84
85#endif /* ! defined(LL_DEBUG_H) */