created BEAR_CASSERT and renamed dassert to BEAR_DASSERT
authorPatrik Gornicz <Gornicz.P@gmail.com>
Wed, 2 Sep 2009 06:23:12 +0000 (02:23 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Wed, 2 Sep 2009 06:23:12 +0000 (02:23 -0400)
lib/include/bear/Array.h
lib/include/bear/debug.h
lib/src/debug.cpp
lib/src/locks/Lock.cpp
physics/src/Entities/Polygon.cpp
physics/src/collisionManager.cpp
physics/src/entityManager.cpp
physics/src/input/inputManager.cpp

index 632ff72..e4d6479 100644 (file)
@@ -115,8 +115,8 @@ void bear::Array<Item>::init
 )
 {
   // Sanity checks
-  bear::DASSERT(0 < uiStartSize);
-  bear::DASSERT(1 < uiSizeMultiplier);
+  BEAR_DASSERT(0 < uiStartSize);
+  BEAR_DASSERT(1 < uiSizeMultiplier);
 
   m_uiStartSize       = uiStartSize;
   m_uiSizeMultiplier  = uiSizeMultiplier;
@@ -124,7 +124,7 @@ void bear::Array<Item>::init
   m_uiAllocated       = 0;
 
   // If this fires you have memory leaks
-  bear::DASSERT(NULL == m_pArrayItems);
+  BEAR_DASSERT(NULL == m_pArrayItems);
   m_pArrayItems       = NULL;
 
   m_pHead             = NULL;
@@ -160,7 +160,7 @@ void bear::Array<Item>::alloc(unsigned int uiSize)
     allocForce(uiSize);
   }
 
-  bear::DASSERT(m_uiAllocated >= uiSize);
+  BEAR_DASSERT(m_uiAllocated >= uiSize);
 
   // TODO: return error when new fails
 }
@@ -179,8 +179,8 @@ void bear::Array<Item>::trim()
   }
 
   // Sanity checks
-  bear::DASSERT(uiSize == getLength());
-  bear::DASSERT(uiSize == m_uiAllocated);
+  BEAR_DASSERT(uiSize == getLength());
+  BEAR_DASSERT(uiSize == m_uiAllocated);
 }
 
 template < class Item >
@@ -188,21 +188,34 @@ bool bear::Array<Item>::isEmpty() const
 {
   if ( NULL == m_pHead )
   {
-    bear::DASSERT(NULL == m_pTail);
+    BEAR_DASSERT(NULL == m_pTail);
     return true;
   }
   else
   {
-    bear::DASSERT(NULL != m_pTail);
+    BEAR_DASSERT(NULL != m_pTail);
     return false;
   }
 }
 
 template < class Item >
+unsigned int bear::Array<Item>::getLength() const
+{
+  if ( isEmpty() )
+  {
+    return 0;
+  }
+  else
+  {
+    return mod( m_pTail - m_pHead, m_uiAllocated ) + 1;
+  }
+}
+
+template < class Item >
 const Item& bear::Array<Item>::getAt(unsigned int uiIndex) const
 {
   // This is very bad. Fix your code
-  DASSERT(uiIndex < getLength());
+  BEAR_DASSERT(uiIndex < getLength());
 
   return *withinBounds( m_pHead + uiIndex, m_pArrayItems, m_pArrayItems + m_uiAllocated );
 }
@@ -211,10 +224,10 @@ template < class Item >
 const Item& bear::Array<Item>::getFront() const
 {
   // This is very bad. Fix your code
-  bear::DASSERT(!isEmpty());
+  BEAR_DASSERT(!isEmpty());
 
   // sanity check
-  //bear::DASSERT(m_pHead <= m_uiAllocated);
+  //BEAR_DASSERT(m_pHead <= m_uiAllocated);
 
   return *m_pHead;
 }
@@ -223,10 +236,10 @@ template < class Item >
 const Item& bear::Array<Item>::getBack() const
 {
   // This is very bad. Fix your code
-  bear::DASSERT(!isEmpty());
+  BEAR_DASSERT(!isEmpty());
 
   // sanity check
-  //bear::DASSERT(m_pTail <= m_uiAllocated);
+  //BEAR_DASSERT(m_pTail <= m_uiAllocated);
 
   return *m_pTail;
 }
@@ -272,7 +285,7 @@ void bear::Array<Item>::pushBack(const Item& i)
 template < class Item >
 void bear::Array<Item>::popFront()
 {
-  bear::DASSERT(!isEmpty());
+  BEAR_DASSERT(!isEmpty());
 
   if( m_pHead == m_pTail )
   {
@@ -288,7 +301,7 @@ void bear::Array<Item>::popFront()
 template < class Item >
 void bear::Array<Item>::popBack()
 {
-  bear::DASSERT(!isEmpty());
+  BEAR_DASSERT(!isEmpty());
 
   if( m_pHead == m_pTail )
   {
@@ -311,27 +324,13 @@ void bear::Array<Item>::clear()
   }
 }
 
-
-template < class Item >
-unsigned int bear::Array<Item>::getLength() const
-{
-  if ( isEmpty() )
-  {
-    return 0;
-  }
-  else
-  {
-    return mod( m_pTail - m_pHead, m_uiAllocated ) + 1;
-  }
-}
-
 template < class Item >
 void bear::Array<Item>::allocFirstTime(unsigned int uiSize)
 {
   // santiy checks
-  bear::DASSERT(0 == m_uiAllocated);
-  bear::DASSERT(NULL == m_pArrayItems);
-  bear::DASSERT(isEmpty());
+  BEAR_DASSERT(0 == m_uiAllocated);
+  BEAR_DASSERT(NULL == m_pArrayItems);
+  BEAR_DASSERT(isEmpty());
 
   if(0 < uiSize)
   {
@@ -348,8 +347,8 @@ void bear::Array<Item>::allocWhenNeeded(unsigned int uiSize)
 {
   unsigned int uiSizeNeeded = (0 == m_uiAllocated) ? m_uiStartSize : m_uiAllocated;
 
-  bear::DASSERT(0 < m_uiStartSize);
-  bear::DASSERT(1 < m_uiSizeMultiplier);
+  BEAR_DASSERT(0 < m_uiStartSize);
+  BEAR_DASSERT(1 < m_uiSizeMultiplier);
 
   while ( uiSizeNeeded < uiSize )
   {
@@ -398,8 +397,8 @@ void bear::Array<Item>::allocForce(unsigned int uiSize)
     }
 
     // santiy checks
-    bear::DASSERT(pNewTail == getPrevTail(pNewItem, uiNewAllocated, pNewArrayItems));
-    bear::DASSERT(pOldTail == getPrevTail(pOldItem, uiOldAllocated, pOldArrayItems));
+    BEAR_DASSERT(pNewTail == getPrevTail(pNewItem, uiNewAllocated, pNewArrayItems));
+    BEAR_DASSERT(pOldTail == getPrevTail(pOldItem, uiOldAllocated, pOldArrayItems));
 
     delete pOldArrayItems;
     pOldArrayItems = NULL;
@@ -473,8 +472,8 @@ Item*    bear::Array<Item>::withinBounds
   Item*         pBoundedValue   = reinterpret_cast<Item*>(uiBoundedValue);
 
   // sanity checks
-  bear::DASSERT(pMinBound <= pBoundedValue);
-  bear::DASSERT(pMaxBound >  pBoundedValue);
+  BEAR_DASSERT(pMinBound <= pBoundedValue);
+  BEAR_DASSERT(pMaxBound >  pBoundedValue);
 
   return pBoundedValue;
 }
index 446151f..949757d 100644 (file)
@@ -23,7 +23,6 @@
 #define NULL 0
 #endif
 
-
 namespace bear
 {
 
@@ -35,10 +34,24 @@ namespace bear
         void printTrace();
     }
 
-    void DASSERT(bool fAssert);
     void DPF(int iLevel, const char* pstr);
 
 } // namespace bear
 
 
+namespace bear
+{
+
+    template <int I>  struct cassert_typedef_dummy;
+    template <bool B> struct CASSERT_FAILURE;
+    template <>       struct CASSERT_FAILURE<true> {};
+
+} // namespace bear
+
+#include <assert.h>
+
+#define BEAR_CASSERT(f)   typedef struct bear::cassert_typedef_dummy<sizeof(bear::CASSERT_FAILURE<f>)> cassert_typedef
+#define BEAR_DASSERT(f)   ((f) ? (void)0 : bear::debug::printTrace(), assert(f))
+
+
 #endif // DEBUG_H
index e56ade4..b0102a0 100644 (file)
@@ -22,7 +22,6 @@ using std::cerr;
 using std::cout;
 using std::endl;
 
-#include <assert.h>
 #include <execinfo.h>
 #include <stdlib.h>
 
@@ -61,11 +60,11 @@ void bear::debug::printTrace()
     {
         Autolock lock(&muDPF);
 
-        cout << "Obtained " << size << " stack frames." << endl;
+        cerr << "Obtained " << size << " stack frames." << endl;
 
         for (int i = 0; i < size; i++)
         {
-            cout << strings[i] << endl;
+            cerr << strings[i] << endl;
         }
     }
 
@@ -81,18 +80,4 @@ void bear::DPF(int iLevel, const char* pstr)
     cout << pstr << endl;
 }
 
-void bear::DASSERT(bool fAssert)
-{
-  if(!fAssert)
-  {
-    bear::debug::printTrace();
-  }
-
-//#ifdef DEBUG
-    assert(fAssert);
-//#else
-//  (void)fAssert;
-//#endif
-}
-
 /// ***** Private Methods *****
index 8b3ff05..270b53e 100644 (file)
@@ -46,15 +46,15 @@ bool Lock::isValid()
 
 void Lock::lock()
 {
-    DASSERT(isValid());
+    BEAR_DASSERT(isValid());
 
     SDL_mutexP(m_pSDL_mutex);
     m_uiThreadID = SDL_ThreadID();
 }
 void Lock::unlock()
 {
-    DASSERT(isValid());
+    BEAR_DASSERT(isValid());
 
-    DASSERT(m_uiThreadID == SDL_ThreadID());
+    BEAR_DASSERT(m_uiThreadID == SDL_ThreadID());
     SDL_mutexV(m_pSDL_mutex);
 }
index d93cd32..e261e99 100644 (file)
@@ -29,7 +29,7 @@ using namespace bear;
 Polygon::Polygon(const Array<Vector2>& points, const float* color)
     : PhysicsEntity(Vector2(0,0)), m_points(points), m_color(color)
 {
-    DASSERT(0 < points.getLength());
+    BEAR_DASSERT(0 < points.getLength());
 
     createBindingBox();
     centerPosition();
@@ -49,7 +49,7 @@ void Polygon::draw() const
 /// ***** Private Class Methods *****
 void Polygon::createBindingBox()
 {
-    DASSERT(0 < m_points.getLength());
+    BEAR_DASSERT(0 < m_points.getLength());
 
     m_maxP = m_points.getAt(0);
     m_minP = m_points.getAt(0);
index 2242a88..338de43 100644 (file)
@@ -96,7 +96,7 @@ void clearEntities()
 
 void placeEntity(PhysicsEntity* ppe)
 {
-    DASSERT(ppe != NULL);
+    BEAR_DASSERT(ppe != NULL);
 
     Vector2 vecMin;
     Vector2 vecMax;
@@ -184,7 +184,7 @@ void updateEntities()
 
 void applyCollision(PhysicsEntity* ppe1, PhysicsEntity* ppe2)
 {
-    DASSERT(ppe1 != NULL && ppe2 != NULL);
+    BEAR_DASSERT(ppe1 != NULL && ppe2 != NULL);
 
     {// Ball vs Ball
         Ball* pb1 = dynamic_cast<Ball*>(ppe1);
@@ -224,7 +224,7 @@ void applyCollision(PhysicsEntity* ppe1, PhysicsEntity* ppe2)
 
 void applyCollision(Ball* pb1, Ball* pb2)
 {
-    DASSERT(pb1 != NULL && pb2 != NULL);
+    BEAR_DASSERT(pb1 != NULL && pb2 != NULL);
 
     CollisionInfo   cInfo;
 
@@ -257,7 +257,7 @@ void applyCollision(Ball* pb1, Ball* pb2)
 
 void applyCollision(Polygon* pPoly, Ball* pBall)
 {
-    DASSERT(pPoly != NULL && pBall != NULL);
+    BEAR_DASSERT(pPoly != NULL && pBall != NULL);
 
     CollisionInfo   cInfo;
 
index 68c4508..4bb5fee 100644 (file)
@@ -75,7 +75,7 @@ void manager::clean()
 
 void manager::add(Entity* pe)
 {
-    DASSERT(pe != NULL);
+    BEAR_DASSERT(pe != NULL);
 
     {
         Particle* pp = dynamic_cast<Particle*>(pe);
@@ -99,7 +99,7 @@ void manager::add(Entity* pe)
 }
 void manager::remove(Entity* pe)
 {
-    DASSERT(pe != NULL);
+    BEAR_DASSERT(pe != NULL);
 
     {
         Autolock lock( &muSetPart );
index 1ba4147..b7569b9 100644 (file)
@@ -71,7 +71,7 @@ void input::update()
           case wasR:  newKeyState = isR;    break;
           case isP:   newKeyState = isP;    break;
           case wasP:  newKeyState = isP;    break;
-          default:    DASSERT(false);       return;
+          default:    BEAR_DASSERT(false);       return;
         }
 
         keyState[i] = newKeyState;