⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 message_queue_sequence.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 3 页
字号:

                if( NULL != l &&
                    m_entry == l->m_entry)
                {
                    // Terminal case

                    ::memcpy(o, &m_entryIndex[m_entry->rd_ptr()], n1);
                }
                else
                {
                    // Recursive case

                    ::memcpy(o, &m_entryIndex[m_entry->rd_ptr()], n1);
                    o += n1;

                    m_entry = nextEntry();

                    if(NULL != m_entry)
                    {
                        m_entryIndex    =   0;
                        m_entryLength   =   m_entry->length();

                        fast_copy(l, o);
                    }
                }
            }
            void fast_copy(size_type n, char* o)
            {
                size_type n1 = m_entryLength - m_entryIndex;

                if(n <= n1)
                {
                    // Asking for less than (or equal to) the capacity
                    // of the current entry.
                    //
                    // Advance the m_entryIndex member.
                    //
                    // This is the terminating case.

                    ::memcpy(o, &m_entryIndex[m_entry->rd_ptr()], n);

                    ACESTL_ASSERT(n <= m_entryLength - m_entryIndex);

                    m_entryIndex += n;

                    ACESTL_ASSERT(m_entryIndex <= m_entryLength);
                }
                else
                {
                    ::memcpy(o, &m_entryIndex[m_entry->rd_ptr()], n1);
                    o += n1;

                    m_entry = nextEntry();

                    ACESTL_MESSAGE_ASSERT("Attempt to walk off end of iterator's range", 0 == n || NULL != m_entry);

                    if(NULL != m_entry)
                    {
                        m_entryIndex    =   0;
                        m_entryLength   =   m_entry->length();

                        fast_copy(n - n1, o);
                    }
                }
            }

        // Implementation
        private:
            ACE_Message_Block   *nextEntry()
            {
                ACE_Message_Block   *entry  =   NULL;

                return m_mqi.advance() ? (m_mqi.next(entry), entry) : NULL;
            }

        // Not to be implemented
        private:
            shared_handle(class_type const&);
            class_type& operator =(class_type const&);
        };
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

    public:
        typedef iterator                                    class_type;
        /// The value type
        typedef char                                        value_type;

    private:
        iterator(sequence_type &mq)
            : m_handle(new shared_handle(mq))
        {}
    public:
        iterator()
            : m_handle(NULL)
        {}
        iterator(class_type const& rhs)
            : m_handle(rhs.m_handle)
        {
            if(NULL != m_handle)
            {
                m_handle->AddRef();
            }
        }
        ~iterator() stlsoft_throw_0()
        {
            if(NULL != m_handle)
            {
                m_handle->Release();
            }
        }

        class_type& operator =(class_type const& rhs)
        {
            shared_handle   *this_handle    =   m_handle;

            m_handle    =   rhs.m_handle;

            if(NULL != m_handle)
            {
                m_handle->AddRef();
            }

            if(NULL != this_handle)
            {
                this_handle->Release();
            }

            return *this;
        }

    public:
        class_type& operator ++()
        {
            ACESTL_ASSERT(NULL != m_handle);

            if(!m_handle->advance())
            {
                m_handle->Release();

                m_handle = NULL;
            }

            return *this;
        }

        class_type operator ++(int)
        {
            class_type  ret(*this);

            operator ++();

            return ret;
        }

        value_type& operator *()
        {
            ACESTL_ASSERT(NULL != m_handle);

            return m_handle->current();
        }

        value_type operator *() const
        {
            ACESTL_ASSERT(NULL != m_handle);

            return m_handle->current();
        }

    public:
        ss_bool_t equal(class_type const& rhs) const
        {
            return class_type::equal_(*this, rhs, iterator_category());
        }
        ss_bool_t operator ==(class_type const& rhs) const
        {
            return equal(rhs);
        }
        ss_bool_t operator !=(class_type const& rhs) const
        {
            return !equal(rhs);
        }

    private:
        static ss_bool_t equal_(class_type const& lhs, class_type const& rhs, stlsoft_ns_qual_std(input_iterator_tag))
        {
            // Input iterator
            return lhs.is_end_point() == rhs.is_end_point();
        }
#if 0
        static ss_bool_t equal_(class_type const& lhs, class_type const& rhs, stlsoft_ns_qual_std(forward_iterator_tag));
            // Forward or above
            if(is_end_point())
            {
                return rhs.is_end_point();
            }
            else
            {
                if(rhs.is_end_point())
                {
                    return false;
                }
                else
                {
                    ACESTL_ASSERT(NULL != m_handle);
                    ACESTL_ASSERT(NULL != rhs.m_handle);
                }
            }
#endif /* 0 */

    private:
        ss_bool_t is_end_point() const
        {
            return NULL == m_handle || m_handle->is_end_point();
        }

    private:
        void fast_copy(char const* f, char const* l)
        {
            if(f != l)
            {
                ACESTL_ASSERT(NULL != m_handle);

                m_handle->fast_copy(f, l, static_cast<size_type>(l - f));
            }
        }
        void fast_copy(class_type const& l, char* o)
        {
            if(*this != l)
            {
                ACESTL_ASSERT(NULL != m_handle);

                m_handle->fast_copy(l.m_handle, o);
            }
        }
        void fast_copy(size_type n, char* o)
        {
            if(0 != n)
            {
                ACESTL_ASSERT(NULL != m_handle);

                m_handle->fast_copy(n, o);
            }
        }

    private:
        shared_handle   *m_handle;
    };
/// @}

// Construction
public:
    /// Create an instance representing the given environment variable
    ss_explicit_k message_queue_sequence(sequence_type &mq)
        : m_mq(mq)
    {}

/// \name Iteration
/// @{
public:
    /// Begins the iteration
    ///
    /// \return An iterator representing the start of the sequence
    iterator begin()
    {
        return iterator(m_mq);
    }
    /// Ends the iteration
    ///
    /// \return An iterator representing the end of the sequence
    iterator end()
    {
        return iterator();
    }
/// @}

/// \name Attributes
/// @{
public:
    /// Returns the number of bytes in the message queue
    size_type size() const
    {
        return m_mq.message_length() /* - 1 */;
    }
    /// Indicates whethere there are any bytes in the message queue
    as_bool_t empty() const
    {
        return const_cast<sequence_type&>(m_mq).is_empty();
    }
/// @}

/// \name Operations
/// @{
public:
    static char* fast_copy(iterator f, iterator l, char* o)
    {
#if defined(ACESTL_MQS_NO_FAST_COPY_TO)
        for(; f != l; ++f, ++o)
        {
            *o = *f;
        }
#else /* ? ACESTL_MQS_NO_FAST_COPY_TO */
        f.fast_copy(l, o);
#endif /* ACESTL_MQS_NO_FAST_COPY_TO */

        return o;
    }
    static char* fast_copy(iterator f, size_type n, char* o)
    {
#if defined(ACESTL_MQS_NO_FAST_COPY_TO)
        for(; 0 != n; ++f, ++o, --n)
        {
            *o = *f;
        }
#else /* ? ACESTL_MQS_NO_FAST_COPY_TO */
        f.fast_copy(n, o);
#endif /* ACESTL_MQS_NO_FAST_COPY_TO */

        return o;
    }

    static iterator fast_copy(char const* f, char const* l, iterator o)
    {
#if defined(ACESTL_MQS_NO_FAST_COPY_FROM)
        for(; f != l; ++f, ++o)
        {
            *o = *f;
        }
#else /* ? ACESTL_MQS_NO_FAST_COPY_FROM */
        o.fast_copy(f, l);
#endif /* ACESTL_MQS_NO_FAST_COPY_FROM */

        return o;
    }
/// @}

/// \name Members
/// @{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -