1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/*
* OpenLink Generic OLE DB Provider
*
* asserts.h
*
* $Id$
*
* Assertion Routines
*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2018 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
*/
#ifndef _ASSERTS_H_
#define _ASSERTS_H_
//-----------------------------------------------------------------------------
// Debugging macros
//-----------------------------------------------------------------------------
// Ensure "DEBUG" is set if "_DEBUG" is set.
#ifdef _DEBUG
# ifndef DEBUG
# define DEBUG 1
# endif
#else
# ifndef DEBUG
# define DEBUG 0
# endif
#endif
// Ensure no previous versions of our macros.
#ifdef assert
# undef assert
#endif
#ifdef Assert
# undef Assert
#endif
#ifdef ASSERT
# undef ASSERT
#endif
#ifdef TRACE
# undef TRACE
#endif
#ifdef LOGCALL
# undef LOGCALL
#endif
#if DEBUG
//-----------------------------------------------------------------------------
// Global function prototypes -- helper stuff
//-----------------------------------------------------------------------------
// The assert and trace macros below calls these.
void OLEDB_Assert(LPSTR expression, LPSTR filename, long linenum);
void OLEDB_Trace(const char *szPath, int iLine, const char *format, ...);
void OLEDB_Log(const char *format, ...);
void OLEDB_LogFlat(const char *format, ...);
LPSTR StringFromPropID(REFIID riid, DBPROPID propID);
LPSTR StringFromGuid(REFIID riid);
LPSTR StringFromVariant(const VARIANT& v);
class LogIndent
{
public:
static int iNesting;
LogIndent()
{
iNesting++;
}
~LogIndent()
{
iNesting--;
clear();
}
LPSTR
StringFromPropID(REFIID riid, DBPROPID propID)
{
LPSTR string = ::StringFromPropID(riid, propID);
return insert(string);
}
LPSTR
StringFromGuid(REFIID rguid)
{
LPSTR string = ::StringFromGuid(rguid);
return insert(string);
}
LPSTR StringFromVariant(const VARIANT* variant);
private:
LPSTR
insert(LPSTR string)
{
LPSTR duplicate = strdup(string);
if (duplicate == NULL)
return "?";
strings.push_front(duplicate);
return duplicate;
}
void
clear()
{
while(!strings.empty())
{
LPSTR string = strings.front();
free(string);
strings.pop_front();
}
}
std::list<LPSTR> strings;
};
#define assert(x) { if ( ! (x) ) OLEDB_Assert( #x, __FILE__, __LINE__ ); }
#define Assert(x) assert(x)
#define ASSERT(x) assert(x)
#define VERIFY(x) assert(x)
#define TRACE(x) OLEDB_Trace##x
#define LOG(x) OLEDB_Log##x
#define LOGFLAT(x) OLEDB_LogFlat##x
#define LOGCALL(x) class LogIndent xyzTemp; OLEDB_Log##x
#define STRINGFROMPROPID(x) xyzTemp.StringFromPropID(x)
#define STRINGFROMGUID(x) xyzTemp.StringFromGuid(x)
#define STRINGFROMVARIANT(x) xyzTemp.StringFromVariant(x)
#define DEBUGCODE(p) p
#else // DEBUG
#define assert(x) ((void)0)
#define Assert(x) ((void)0)
#define ASSERT(x) ((void)0)
#define VERIFY(x) ((void)(x))
#define TRACE(x)
#define LOG(x)
#define LOGFLAT(x)
#define LOGCALL(x)
#define STRINGFROMPROPID(x)
#define STRINGFROMGUID(x)
#define STRINGFROMVARIANT(x)
#define DEBUGCODE(p)
#endif // DEBUG
#endif
|