Torque3D Documentation / _generateds / platformAssert.h

platformAssert.h

Engine/source/platform/platformAssert.h

More...

Classes:

Public Defines

define
AssertFatal(x, y) (x)
define
AssertISV(x, y) ((!(x) && ::(::, __FILE__, __LINE__,  y)) ? ::() : ()0)                                                                  \
define
AssertWarn(x, y) (x)

Public Functions

const char *
avar(const char * in_msg, ... )

Detailed Description

Public Defines

AssertFatal(x, y) (x)
AssertISV(x, y) ((!(x) && ::(::, __FILE__, __LINE__,  y)) ? ::() : ()0)                                                                  \

Assert (In Shipping Version) that the statement x is true, otherwise halt.

If the statement x is true, continue processing.

If the statement x is false, log the file and line where the assert occurred, the message y and exit the program displaying a dialog containing the message y. These asserts are present in both OPTIMIZED and DEBUG builds.

This assert should only be used for rare conditions where the application cannot continue execution without seg-faulting and you want to display a nice exit message.

AssertWarn(x, y) (x)

Public Functions

avar(const char * in_msg, ... )

Sprintf style string formating into a fixed temporary buffer. Parameters:

in_msg

sprintf style format string

return:

pointer to fixed buffer containing formatted string

Example:
U8 a = 5;
S16 b = -10;
char *output = avar("hello %s! a=%u, b=%d", "world");
ouput = "hello world! a=5, b=-10"

warning:

avar uses a static fixed buffer. Treat the buffer as volatile data and use it immediately. Other functions my use avar too and clobber the buffer.

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _PLATFORMASSERT_H_
 25#define _PLATFORMASSERT_H_
 26
 27#ifndef _PLATFORM_H_
 28#include "platform/platform.h"
 29#endif
 30
 31class PlatformAssert
 32{
 33public:
 34   enum Type 
 35   {
 36      Warning   = 3,
 37      Fatal     = 2,
 38      Fatal_ISV = 1
 39   };
 40
 41private:
 42   static PlatformAssert *platformAssert;
 43   bool processing;
 44   bool ignoreAll;
 45
 46   virtual bool displayMessageBox(const char *title, const char *message, bool retry);
 47   virtual bool process(Type         assertType,
 48                const char*  filename,
 49                U32          lineNumber,
 50                const char*  message);
 51
 52   PlatformAssert();
 53   virtual ~<a href="/coding/class/classplatformassert/">PlatformAssert</a>();
 54
 55public:
 56   static void create( PlatformAssert* newAssertClass = NULL );
 57   static void destroy();
 58   static bool processAssert(Type         assertType,
 59                             const char*  filename,
 60                             U32          lineNumber,
 61                             const char*  message);
 62   static char *message(const char *message, ...);
 63   static bool processingAssert();
 64};
 65
 66
 67#ifdef TORQUE_ENABLE_ASSERTS
 68/*!
 69   Assert that the statement x is true, and continue processing.
 70
 71   If the statment x is true, continue processing.
 72
 73   If the statement x is false, log the file and line where the assert occured,
 74   the message y and continue processing.
 75
 76   These asserts are only present in DEBUG builds.
 77   */
 78#define AssertWarn(x, y) (void)(!!(x) || ::PlatformAssert::processAssert(::PlatformAssert::Warning, __FILE__, __LINE__,  y))
 79
 80   /*!
 81      Helper macro called when AssertFatal failed.
 82      Used for help static code analyzers.
 83   */
 84   #ifndef ON_FAIL_ASSERTFATAL
 85      #define ON_FAIL_ASSERTFATAL
 86   #endif
 87
 88/*!
 89   Assert that the statement x is true, otherwise halt.
 90
 91   If the statement x is true, continue processing.
 92
 93   If the statement x is false, log the file and line where the assert occured,
 94   the message y and displaying a dialog containing the message y. The user then
 95   has the option to halt or continue causing the debugger to break.
 96
 97   These asserts are only present in DEBUG builds.
 98
 99   This assert is very useful for verifying data as well as function entry and
100   exit conditions.
101   */
102#define AssertFatal(x, y) ((!(x) && ::PlatformAssert::processAssert(::PlatformAssert::Fatal, __FILE__, __LINE__,  y)) ? ::Platform::debugBreak() : (void)0)                                                                  \
103
104#else
105
106#define AssertFatal(x, y) TORQUE_UNUSED(x)
107#define AssertWarn(x, y)  TORQUE_UNUSED(x)
108
109#endif
110
111/*!
112   Assert (In Shipping Version) that the statement x is true, otherwise halt.
113
114   If the statement x is true, continue processing.
115
116   If the statement x is false, log the file and line where the assert occurred,
117   the message y and exit the program displaying a dialog containing the message y.
118   These asserts are present in both OPTIMIZED and DEBUG builds.
119
120   This assert should only be used for rare conditions where the application cannot continue
121   execution without seg-faulting and you want to display a nice exit message.
122 */
123#define AssertISV(x, y) ((!(x) && ::PlatformAssert::processAssert(::PlatformAssert::Fatal_ISV, __FILE__, __LINE__,  y)) ? ::Platform::debugBreak() : (void)0)                                                                  \
124
125/*!
126   Sprintf style string formating into a fixed temporary buffer.
127   @param   in_msg sprintf style format string
128   @returns pointer to fixed buffer containing formatted string
129
130   \b Example:
131   \code
132   U8 a = 5;
133   S16 b = -10;
134   char *output = avar("hello %s! a=%u, b=%d", "world");
135   ouput = "hello world! a=5, b=-10"
136   \endcode
137
138   @warning avar uses a static fixed buffer.  Treat the buffer as volatile data
139   and use it immediately.  Other functions my use avar too and clobber the buffer.
140 */
141const char* avar(const char *in_msg, ...);
142
143
144
145#endif // _PLATFORM_ASSERT_H_
146
147