Example #1
0
inline typename List< FragmentT, ContainerT >::FSizeType
List< FragmentT, ContainerT >::insert(
    const typename List< FragmentT, ContainerT >::FragmentType& insertFragment)
{
    if( insertFragment.end() > limit() )
    {
//        throw BadRangeException( insertFragment, limit() );
        CString errorMsg;
        errorMsg.Format(
            _T( "FF::SimpleFragmentList - invalid arg for insert - " )
            _T( "List - size: %u - limit: %I64u - sum: %I64u - " )
            _T( "Fragment - begin: %I64u - end: %I64u" ), size(), limit(), sumLength(),
            insertFragment.begin(), insertFragment.end() );
        theApp.Message( MSG_ERROR, errorMsg );
        return 0;
    }
    if( insertFragment.length() == 0 ) return 0;
    ::std::pair< Iterator, Iterator > insertRange =
        equalRange( insertFragment );
    if( insertRange.first != insertRange.second )
    {
        FSizeType chgSum =
            Traits::mergeAndReplace( s_, insertRange, insertFragment );
        sumLength_ += chgSum;
        return chgSum;
    }
    else
    {
        s_.insert( insertRange.second, insertFragment );
        sumLength_ += insertFragment.length();
        return insertFragment.length();
    }
}
Example #2
0
inline typename List< FragmentT, ContainerT >::FSizeType
List< FragmentT, ContainerT >::insert(
    typename List< FragmentT, ContainerT >::Iterator where,
    const typename List< FragmentT, ContainerT >::FragmentType& insertFragment)
{
    Iterator tmp = where;
    CompareFragments< FragmentType > cmp;
    if( ( where == begin() || cmp( *--tmp, insertFragment ) )
        && ( where == end() || cmp( insertFragment, *where ) ) )
    {
        s_.insert( where, insertFragment );
        sumLength_ += insertFragment.length();
        return insertFragment.length();
    }
    else
    {
        return insert( insertFragment );
    }
}
Example #3
0
inline typename List< FragmentT, ContainerT >::FSizeType
List< FragmentT, ContainerT >::erase(
    const typename List< FragmentT, ContainerT >::FragmentType& eraseFragment)
{
    if( eraseFragment.end() > limit() )
    {
//        throw BadRangeException( eraseFragment, limit() );
        CString errorMsg;
        errorMsg.Format(
            _T( "FF::SimpleFragmentList - invalid arg for erase - " )
            _T( "List - size: %u - limit: %I64u - sum: %I64u - " )
            _T( "Fragment - begin: %I64i - end: %I64u" ), size(), limit(), sumLength(),
            eraseFragment.begin(), eraseFragment.end() );
        theApp.Message( MSG_ERROR, errorMsg );
        return 0;
    }
    if( eraseFragment.length() == 0 ) return 0;
    ::std::pair< Iterator, Iterator > eraseRange =
        overlappingRange( eraseFragment );
    if( eraseRange.first == eraseRange.second ) return 0;
    const FragmentType& frontFragment
        = eraseRange.first->begin() < eraseFragment.begin()
            ? FragmentType( *eraseRange.first,
                 eraseRange.first->begin(), eraseFragment.begin() )
            : FragmentType( *eraseRange.first, 0,
                ::std::numeric_limits< FSizeType >::max() );
    --eraseRange.second;
    const FragmentType& backFragment
        = eraseRange.second->end() > eraseFragment.end()
        ? FragmentType( *eraseRange.second,
                eraseFragment.end(), eraseRange.second->end() )
        : FragmentType( *eraseRange.second, 0,
                ::std::numeric_limits< FSizeType >::max() );
    const FSizeType oldSum = sumLength();
    ++eraseRange.second;
    for( ; eraseRange.first != eraseRange.second; )
    {
        sumLength_ -= eraseRange.first->length();
        s_.erase( eraseRange.first++ );
    }
    if( frontFragment.end() < ::std::numeric_limits< FSizeType >::max() )
    {
        s_.insert( eraseRange.second, frontFragment );
        sumLength_ += frontFragment.length();
    }
    if( backFragment.end() < ::std::numeric_limits< FSizeType >::max() )
    {
        s_.insert( eraseRange.second, backFragment );
        sumLength_ += backFragment.length();
    }
    return oldSum - sumLength();
}