kdebug.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KDEBUG_H
00005 #define FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KDEBUG_H
00006 /**************************************************************************************
00007 
00008  Copyright (C) 2001 - 2010 Autodesk, Inc. and/or its licensors.
00009  All Rights Reserved.
00010 
00011  The coded instructions, statements, computer programs, and/or related material 
00012  (collectively the "Data") in these files contain unpublished information 
00013  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00014  Canada and United States of America federal copyright law and by international 
00015  treaties. 
00016  
00017  The Data may not be disclosed or distributed to third parties, in whole or in
00018  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00019 
00020  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00021  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00022  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00023  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00024  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00025  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00026  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00027  
00028  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00029  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00030  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00031  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00032  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00033  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00034  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00035  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00036  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00037  OR DAMAGE. 
00038 
00039 **************************************************************************************/
00040 
00041 #include <fbxfilesdk/fbxfilesdk_def.h>
00042 
00043 #include <fbxfilesdk/components/kbaselib/klib/ktime.h>
00044 
00045 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00046 
00047 
00052 
00055     #define  K_NO_TRACE          0  
00056 
00059     #define  K_ASSERT_ONLY_TRACE 1   
00060 
00063     #define  K_NORMAL_TRACE      3   
00064 
00067     #define  K_ALL_TRACE         4  
00068 
00073     #define  K_DEFAULT_TRACE     20          
00074 
00076 
00077     // Functions prototypes
00078     KFBX_DLL   void KRegisterAssertStubFct(int (*pFct)(const char *pFileName, const char *pFunctionName, kULong pLineNumber, 
00079                                                         const char *pMessage,  bool pAbortEnabled));
00080     KFBX_DLL   void* KGetAssertStubFct();
00081     KFBX_DLL   void KAssertFailed( const char *pFileName, const char *pFunctionName, kULong pLineNumber, const char *pMessage=NULL,bool *pHideForEver=NULL );
00082     KFBX_DLL   void KAssertFailedWithLevel( const char *pFileName, const char *pFunctionName, kULong pLineNumber, 
00083                                             kULong pLevel, const char *pMessage=NULL,bool *pHideForEver=NULL );
00084 
00085     KFBX_DLL   void ShowLastError( char* pOperation );
00086 
00087     KFBX_DLL   void KTraceFnc(char* pStr, ... );
00088     inline void KNoTraceFnc( char* /*pStr*/, ... ) {}
00089 
00090     KFBX_DLL    bool KIsAssertDisplayed();
00091 
00094     #define KAlwaysTrace    KTraceFnc
00095 
00098     #define KSTRINGITIZE(a) (a)
00099 
00100     // Macros
00101     #ifdef _DEBUG
00102 
00103         #ifndef __MWERKS__
00104             #define __func__    KSTRINGITIZE("")
00105         #endif
00106 
00107         #undef KFBX_ASSERT_NAMESPACE
00108 
00109         #if !defined(FBXFILESDK_NAMESPACE_USE)
00110         #   define KFBX_ASSERT_NAMESPACE(a)     a
00111         #else
00112         #   define KFBX_ASSERT_NAMESPACE(a)     FBXFILESDK_NAMESPACE::a
00113         #endif
00114 
00115         #define K_ASSERT( pCondition )   \
00116                             if( !(pCondition) )\
00117                             {\
00118                                 static bool sHideForEver=false; \
00119                                 if (!sHideForEver) KFBX_ASSERT_NAMESPACE(KAssertFailed)( KSTRINGITIZE(__FILE__), __func__, __LINE__, KSTRINGITIZE(#pCondition),&sHideForEver ); \
00120                             }((void)0)
00121 
00122         #define K_ASSERT_MSG_NOW( pMessage )   \
00123                             { \
00124                                 static bool sHideForEver=false; \
00125                                 if (!sHideForEver) KFBX_ASSERT_NAMESPACE(KAssertFailed)( KSTRINGITIZE(__FILE__), __func__, __LINE__,  pMessage,&sHideForEver ); \
00126                             }((void)0)
00127 
00128         #define K_ASSERT_MSG( pCondition, pMessage )   \
00129                             if( !(pCondition) )\
00130                             {\
00131                                 static bool sHideForEver=false; \
00132                                 if (!sHideForEver) KFBX_ASSERT_NAMESPACE(KAssertFailed)( KSTRINGITIZE(__FILE__), __func__, __LINE__,  pMessage,&sHideForEver ); \
00133                             }((void)0)
00134 
00135         #define K_ASSERT_MSG_NOT_IMPLEMENTED \
00136                             { \
00137                                 static bool sHideForEver=false; \
00138                                 if (!sHideForEver) KFBX_ASSERT_NAMESPACE(KAssertFailed)( KSTRINGITIZE(__FILE__), __func__, __LINE__,  "Not implemented",&sHideForEver ); \
00139                             }((void)0)
00140 
00141         template <bool x> struct k_static_assert_type;
00142         template<> struct k_static_assert_type<true>  { enum { value = 1  }; };
00143         // will force a compile error when attempting to do an array of this size
00144         template<> struct k_static_assert_type<false> { enum { value = -1 }; };   
00145 
00146         #define K_STATIC_ASSERT( pCondition )  \
00147                             typedef char build_break_if_false[ k_static_assert_type<(bool)(pCondition)>::value ];
00148 
00149         // To debug in both Debug only
00150         #define KTrace          KTraceFnc
00151 
00152 
00153     #else
00154         #define K_ASSERT( pCondition )                              ((void)0)
00155         #define K_ASSERT_MSG_NOW( pMessage )                        ((void)0)
00156         #define K_ASSERT_MSG(pCondition,  pMessage )                ((void)0)
00157         #define K_ASSERT_MSG_NOT_IMPLEMENTED                        ((void)0)
00158         #define K_STATIC_ASSERT( pCondition )
00159         // To debug in both Debug only
00160         #define KTrace          KNoTraceFnc
00161 
00162 
00163     #endif    
00164 
00165     struct KDebugTimeEvent {
00166         KTime   EventTime;
00167         KTime   EventWantedtime;
00168         int    Id;
00169         int    ToId;
00170         float  Color[3];
00171         char  InternalComment[52];
00172         int    UserId;
00173         char* Comment;
00174     };
00175 
00176     enum { KTRACE_SYNC=-1,KTRACE_START=-1,KTRACE_END=-2 };
00177 
00178     KFBX_DLL   void KTimerTrace_Start();
00179     KFBX_DLL   int  KTimerTrace_GetId(char* pName, bool pProfile=false);
00180     KFBX_DLL   int  KTimerTrace (int pId,KTime pTime,KTime pScheduledTime,int LastId,float R,float G,float B,char* pStr,bool pCopy=false);
00181     KFBX_DLL   int  KTimerPrintf(int pId,KTime pTime,KTime pScheduledTime,int LastId,float R,float G,float B,char* pStr, ...);
00182     KFBX_DLL   void KTimerTrace_Stop();
00183     KFBX_DLL   void KTimerTrace_Release();
00184     KFBX_DLL   int   KTimerTrace_GetEventCount();
00185     KFBX_DLL   KDebugTimeEvent *KTimerTrace_GetEvent(int pIndex);
00186 
00187     KFBX_DLL   int      KTimerTrace_GetIdCount();
00188     KFBX_DLL   char* KTimerTrace_GetIdName(int pId);
00189 
00193 #define K_CHECKRTNV( condition, value )     \
00194     if( !(condition) ){                     \
00195         K_ASSERT_MSG_NOW( #condition );     \
00196         return value;                       \
00197     } 
00198 
00202 #define K_CHECKRTN( condition )             \
00203     if( !(condition) ){                     \
00204         K_ASSERT_MSG_NOW( #condition );     \
00205         return;                             \
00206     } 
00207 
00208 // Type traits for class KArrayTemplate
00209 template<typename T> struct KFbxIncompatibleWithKArrayTemplate {
00210     enum {value = 0};
00211 };
00212 
00213 
00214 #define KFBX_INCOMPATIBLE_WITH_KARRAYTEMPLATE_TEMPLATE(T)       \
00215     struct KFbxIncompatibleWithKArrayTemplate< T > {            \
00216         union {                                                 \
00217             T t();                                              \
00218         } catcherr;                                             \
00219         enum {value = 1};                                       \
00220     }
00221 
00222 #define KFBX_INCOMPATIBLE_WITH_KARRAYTEMPLATE(T)                \
00223     template<> KFBX_INCOMPATIBLE_WITH_KARRAYTEMPLATE_TEMPLATE(T)
00224 
00225 
00226 #define KFBX_IS_INCOMPATIBLE_WITH_KARRAYTEMPLATE(T) ((bool) KFbxIncompatibleWithKArrayTemplate<T>::value)
00227 
00228 
00229 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00230 
00231 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KDEBUG_H
00232