From: Patrik Gornicz Date: Wed, 2 Sep 2009 06:23:12 +0000 (-0400) Subject: created BEAR_CASSERT and renamed dassert to BEAR_DASSERT X-Git-Url: http://gitweb.pgornicz.com/?a=commitdiff_plain;h=14ed7dccece974659d8adfa55d8ff2b3d4b07026;p=libbear.git created BEAR_CASSERT and renamed dassert to BEAR_DASSERT --- diff --git a/lib/include/bear/Array.h b/lib/include/bear/Array.h index 632ff72..e4d6479 100644 --- a/lib/include/bear/Array.h +++ b/lib/include/bear/Array.h @@ -115,8 +115,8 @@ void bear::Array::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::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::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::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::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::getLength() const +{ + if ( isEmpty() ) + { + return 0; + } + else + { + return mod( m_pTail - m_pHead, m_uiAllocated ) + 1; + } +} + +template < class Item > const Item& bear::Array::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::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::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::pushBack(const Item& i) template < class Item > void bear::Array::popFront() { - bear::DASSERT(!isEmpty()); + BEAR_DASSERT(!isEmpty()); if( m_pHead == m_pTail ) { @@ -288,7 +301,7 @@ void bear::Array::popFront() template < class Item > void bear::Array::popBack() { - bear::DASSERT(!isEmpty()); + BEAR_DASSERT(!isEmpty()); if( m_pHead == m_pTail ) { @@ -311,27 +324,13 @@ void bear::Array::clear() } } - -template < class Item > -unsigned int bear::Array::getLength() const -{ - if ( isEmpty() ) - { - return 0; - } - else - { - return mod( m_pTail - m_pHead, m_uiAllocated ) + 1; - } -} - template < class Item > void bear::Array::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::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::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::withinBounds Item* pBoundedValue = reinterpret_cast(uiBoundedValue); // sanity checks - bear::DASSERT(pMinBound <= pBoundedValue); - bear::DASSERT(pMaxBound > pBoundedValue); + BEAR_DASSERT(pMinBound <= pBoundedValue); + BEAR_DASSERT(pMaxBound > pBoundedValue); return pBoundedValue; } diff --git a/lib/include/bear/debug.h b/lib/include/bear/debug.h index 446151f..949757d 100644 --- a/lib/include/bear/debug.h +++ b/lib/include/bear/debug.h @@ -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 struct cassert_typedef_dummy; + template struct CASSERT_FAILURE; + template <> struct CASSERT_FAILURE {}; + +} // namespace bear + +#include + +#define BEAR_CASSERT(f) typedef struct bear::cassert_typedef_dummy)> cassert_typedef +#define BEAR_DASSERT(f) ((f) ? (void)0 : bear::debug::printTrace(), assert(f)) + + #endif // DEBUG_H diff --git a/lib/src/debug.cpp b/lib/src/debug.cpp index e56ade4..b0102a0 100644 --- a/lib/src/debug.cpp +++ b/lib/src/debug.cpp @@ -22,7 +22,6 @@ using std::cerr; using std::cout; using std::endl; -#include #include #include @@ -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 ***** diff --git a/lib/src/locks/Lock.cpp b/lib/src/locks/Lock.cpp index 8b3ff05..270b53e 100644 --- a/lib/src/locks/Lock.cpp +++ b/lib/src/locks/Lock.cpp @@ -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); } diff --git a/physics/src/Entities/Polygon.cpp b/physics/src/Entities/Polygon.cpp index d93cd32..e261e99 100644 --- a/physics/src/Entities/Polygon.cpp +++ b/physics/src/Entities/Polygon.cpp @@ -29,7 +29,7 @@ using namespace bear; Polygon::Polygon(const Array& 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); diff --git a/physics/src/collisionManager.cpp b/physics/src/collisionManager.cpp index 2242a88..338de43 100644 --- a/physics/src/collisionManager.cpp +++ b/physics/src/collisionManager.cpp @@ -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(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; diff --git a/physics/src/entityManager.cpp b/physics/src/entityManager.cpp index 68c4508..4bb5fee 100644 --- a/physics/src/entityManager.cpp +++ b/physics/src/entityManager.cpp @@ -75,7 +75,7 @@ void manager::clean() void manager::add(Entity* pe) { - DASSERT(pe != NULL); + BEAR_DASSERT(pe != NULL); { Particle* pp = dynamic_cast(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 ); diff --git a/physics/src/input/inputManager.cpp b/physics/src/input/inputManager.cpp index 1ba4147..b7569b9 100644 --- a/physics/src/input/inputManager.cpp +++ b/physics/src/input/inputManager.cpp @@ -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;