Changeset 3753


Ignore:
Timestamp:
Jan 2, 2015, 2:44:59 AM (7 years ago)
Author:
sam
Message:

base: improve assert messages in the array class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/base/array.h

    r3697 r3753  
    22// Lol Engine
    33//
    4 // Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2010-2015 Sam Hocevar <sam@hocevar.net>
    55//            (c) 2013-2014 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
    66//   This program is free software; you can redistribute it and/or
     
    134134        /* Allow array[0] even if size is zero so that people can
    135135         * always use &array[0] to get a pointer to the data. */
    136         ASSERT(n >= 0);
    137         ASSERT(n < m_count || (!n && !m_count));
     136        ASSERT(n >= 0 && (n < m_count || (!n && !m_count)),
     137               "cannot access index %lld in array of size %lld",
     138               (long long int)n, (long long int)m_count);
    138139        return m_data[n];
    139140    }
     
    141142    inline element_t const& operator[](ptrdiff_t n) const
    142143    {
    143         ASSERT(n >= 0);
    144         ASSERT(n < m_count || (!n && !m_count));
     144        ASSERT(n >= 0 && (n < m_count || (!n && !m_count)),
     145               "cannot access index %lld in array of size %lld",
     146               (long long int)n, (long long int)m_count);
    145147        return m_data[n];
    146148    }
     
    206208    inline void Insert(T const &x, ptrdiff_t pos)
    207209    {
    208         ASSERT(pos >= 0);
    209         ASSERT(pos <= m_count);
     210        ASSERT(pos >= 0 && pos <= m_count,
     211               "cannot insert at index %lld in array of size %lld",
     212               (long long int)pos, (long long int)m_count);
    210213
    211214        if (m_count >= m_reserved)
     
    223226    inline bool InsertUnique(T const &x, ptrdiff_t pos)
    224227    {
    225         ASSERT(pos >= 0);
    226         ASSERT(pos <= m_count);
     228        ASSERT(pos >= 0 && pos <= m_count,
     229               "cannot insert at index %lld in array of size %lld",
     230               (long long int)pos, (long long int)m_count);
    227231
    228232        if (Find(x) != INDEX_NONE)
     
    285289    void Swap(ptrdiff_t pos1, ptrdiff_t pos2)
    286290    {
    287         ASSERT(pos1 >= 0);
    288         ASSERT(pos2 >= 0);
    289         ASSERT(pos1 < m_count);
    290         ASSERT(pos2 < m_count);
     291        ASSERT(pos1 >= 0 && pos1 <= m_count,
     292               "cannot swap index %lld in array of size %lld",
     293               (long long int)pos1, (long long int)m_count);
     294        ASSERT(pos2 >= 0 && pos2 <= m_count,
     295               "cannot swap index %lld in array of size %lld",
     296               (long long int)pos2, (long long int)m_count);
    291297
    292298        if (pos1 != pos2)
     
    297303    {
    298304        ASSERT(todelete >= 0);
    299         ASSERT(pos - todelete >= -m_count - 1);
    300         ASSERT(pos + todelete <= m_count);
     305        ASSERT(pos - todelete >= -m_count - 1 && pos + todelete <= m_count,
     306               "cannot remove %lld elements at %lld in array of size %lld",
     307               (long long int)todelete, (long long int)pos,
     308               (long long int)m_count);
     309
    301310        if (pos < 0)
    302311            pos = m_count + pos;
     
    312321    {
    313322        ASSERT(todelete >= 0);
    314         ASSERT(pos - todelete >= -m_count - 1);
    315         ASSERT(pos + todelete <= m_count);
     323        ASSERT(pos - todelete >= -m_count - 1 && pos + todelete <= m_count,
     324               "cannot remove %lld elements at %lld in array of size %lld",
     325               (long long int)todelete, (long long int)pos,
     326               (long long int)m_count);
     327
    316328        if (pos < 0)
    317329            pos = m_count + pos;
     
    486498    inline void Insert(ptrdiff_t pos, T... args)
    487499    {
    488         ASSERT(pos >= 0);
    489         ASSERT(pos <= this->m_count);
     500        ASSERT(pos >= 0 && pos <= this->m_count,
     501               "cannot insert at index %lld in array of size %lld",
     502               (long long int)pos, (long long int)this->m_count);
    490503
    491504        if (this->m_count >= this->m_reserved)
Note: See TracChangeset for help on using the changeset viewer.