TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: DARIN MCBRIDE
date: 1997-08-31 09:50:00
subject: safequeue [2/6]

>>>>>>>>>> CSplit: Version 2.2 >>>>>>>>>>
>>>>>>>>>> CSplit: Begin part 2/6 >>>>>>>>>>
    const value_type& front() const { SemUse su(m_msContainer); return \
\
_front(); }
    void push(const value_type& x)
    {
        assert(roomleft() > 1);
        SemUse su(m_msContainer);
        DoPush(x);
    }
    void push(value_type const* start, value_type const* finish)
    {
        assert(roomleft() > finish - start + 1);
        SemUse su(m_msContainer);
        if (m_iEnd > m_iBegin)
            for (; m_iEnd != BufferEnd() && start != finish; ++m_iEnd)
            {
                m_iEnd[-1] = *start++;
            }
        for (; m_iEnd != m_iBegin && start != finish; ++m_iEnd)
        {
            m_iEnd[-1] = *start++;
        }
    }
    void push(value_type const* start, size_type len)
    {
        push(start, start + len);
    }
    void pop() { SemUse su(m_msContainer); DoPop(); }
    void pop(value_type& x) { SemUse su(m_msContainer); x = _front(); \
\
DoPop(); }
    // returns number successfully "popped"
    int  pop(value_type* start, size_type len)
    {
        SemUse su(m_msContainer);
        assert(len <= size());
        size_type n = 0;
        if (m_iBegin > m_iEnd)
            for (; m_iBegin != BufferEnd() && n < len; ++m_iBegin, ++n)
            {
                *start++ = *m_iBegin;
            }
        for (; n < len; ++m_iBegin, ++n)
        {
            assert(m_iBegin != m_iEnd);
            *start++ = *m_iBegin;
        }
        return n;
    }
    // returns a pointer to one after the last item popped
    value_type* pop(value_type* start, value_type* end)
    {
        return start + pop(start, end - start);
    }
    // quick clear:
    void clear()
    {
        m_iBegin = m_pBuffer;
        m_iEnd = m_iBegin + 1;
    }
    SafeQueue(int size = 4096 / sizeof(T))
        : m_pBuffer(new T[size]), m_stBufferSize(size), \
\
m_iBegin(m_pBuffer), m_iEnd(m_iBegin + 1)
    { assert (size > 1); m_msContainer.Create(); }
    ~SafeQueue() { delete[] m_pBuffer; }
protected:
    T*        m_pBuffer;
    size_type m_stBufferSize;
    const iterator BufferEnd() const { return m_pBuffer + \
\
m_stBufferSize; }
    volatile iterator m_iBegin;
    volatile iterator m_iEnd;
>>>>>>>>>> CSplit: End part 2/6 crc: 9bcd >>>>>>>>>>
--- FastEcho 1.46
---------------
* Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.