Пример #1
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();
}
Пример #2
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();
    }
}
Пример #3
0
typename RangeT::size_type List< RangeT, TraitsT, ContainerT >::insert(
	typename List< RangeT, TraitsT, ContainerT >::iterator where, const RangeT& value)
{
	if ( value.end() > Traits::limit() )
	{
		qDebug( qPrintable(QString("ListError - insert(h) - size: %1 - limit: %2 - sum: %3 - \nRange - begin: %4 - end: %5")
			.arg(size()).arg(Traits::limit()).arg(Traits::length_sum()).arg(value.begin()).arg(value.end())) );
		return 0;
	}
	if ( value.size() == 0 ) return 0;
	iterator tmp( where );
	return ( where == begin() || ( --tmp )->end() < value.begin() )
			&& ( where == end() || value.end() < where->begin() )
		? Traits::simple_merge( m_set, where, value )
		: insert( value );
}
Пример #4
0
typename RangeT::size_type List< RangeT, TraitsT, ContainerT >::insert(
	typename List< RangeT, TraitsT, ContainerT >::iterator where, const RangeT& value)
{
	if ( value.end() > limit() )
	{
//		throw ListException( value, limit() );
		CString msg;
		msg.Format( _T( "ListError - insert(h) - size: %u - limit: %I64u - sum: %I64u - " )
			_T( "Range - begin: %I64u - end: %I64u" ),
			size(), limit(), Traits::length_sum(), value.begin(), value.end() );
		theApp.Message( MSG_ERROR, msg );
		return 0;
	}
	if ( value.size() == 0 ) return 0;
	iterator tmp( where );
	return ( where == begin() || ( --tmp )->end() < value.begin() )
			&& ( where == end() || value.end() < where->begin() )
		? Traits::simple_merge( m_set, where, value )
		: insert( value );
}