I'm creating a library that easily adds a bunch of debugging features to c++ programms. At the moment I have these features:

- A more useful assert dialouge.
- Pointer validation using IsBadReadPtr/IsBadWritePtr.
- Memory leak tracking.

I'm trying to think of other features I could add to this. What other features are common features in debug libraries?

buffer overruns

How does this class look?
It's designed so that if you think you're having/going to have a buffer overrun,
you can wrap it around your buffer to check when.
Assert is a macro for that custom assert dialouge i wrote above.

template< typename T >
class CBufferWatcher {
	CDataWatcher<T*> m_pBuffer;
	int m_nSize;
	int m_nIndex;
public:
	CBufferWatcher( void )
	{
		Set( NULL, 0 );
	}

	CBufferWatcher( T *buffer, int size )
	{
		Set( buffer, size );
	}

	void Set( T *buffer, int size )
	{
		m_pBuffer = buffer;
		m_nSize = size;
		m_nIndex = 0;
	}

	bool IsValidIndex( int n )
	{
		return ( n >= 0 && n <= m_nSize - 1 );
	}

	T &operator[]( int n ) { Assert( IsValidIndex( n ) ); return m_pBuffer[n]; }

	T &operator++( void ) { Increment( ); }
	T &operator++( int ) { Increment( ); }
	T &operator--( void ) { Decrement( ); }
	T &operator--( int ) { Decrement( ); }

	void Increment( void )
	{
		Assert( IsValidIndex( m_nIndex + 1) );

		m_pBuffer++;
		m_nIndex++;
	}

	void Decrement( void )
	{
		Assert( IsValidIndex( m_nIndex - 1 ) );
		m_pBuffer--;
		m_nIndex--;
	}

	T *operator->( void ) { return m_pBuffer; }
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.