00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FILEFRAGMENTS_PAYLOADTRAITS_HPP_INCLUDED
00023 #define FILEFRAGMENTS_PAYLOADTRAITS_HPP_INCLUDED
00024
00025 namespace detail
00026 {
00027
00028 template<>
00029 struct PayloadTraits< EmptyType >
00030 {
00031 typedef EmptyType PayloadType;
00032 static const bool allowEmptyFragments = true;
00033 template< typename OffsetType >
00034 static bool equals(const Fragment< EmptyType, OffsetType >& lhs,
00035 const Fragment< EmptyType, OffsetType >& rhs)
00036 {
00037 return true;
00038 }
00039 template< class ContainerType, typename OffsetType >
00040 static typename Fragment< EmptyType, OffsetType >::SizeType
00041 mergeAndReplace(ContainerType& s, ::std::pair
00042 <
00043 typename List
00044 <
00045 Fragment< EmptyType, OffsetType >,
00046 ContainerType
00047 >::Iterator,
00048 typename List
00049 <
00050 Fragment< EmptyType, OffsetType >,
00051 ContainerType
00052 >::Iterator
00053 >& range, const Fragment< EmptyType, OffsetType >& toMerge)
00054 {
00055 typedef Fragment< EmptyType, OffsetType > FragmentType;
00056 typedef typename FragmentType::SizeType FSizeType;
00057 if( range.first->begin() <= toMerge.begin()
00058 && range.first->end() >= toMerge.end() ) return 0;
00059 FSizeType chgSum = 0;
00060 FSizeType low = ::std::min( range.first->begin(), toMerge.begin() );
00061 FSizeType high;
00062 for( ; range.first != range.second; )
00063 {
00064 high = range.first->end();
00065 chgSum -= range.first->length();
00066 s.erase( range.first++ );
00067 }
00068 high = ::std::max( high, toMerge.end() );
00069 s.insert( range.second, FragmentType( low, high ) );
00070 chgSum += high - low;
00071 return chgSum;
00072 }
00073 };
00074
00075 }
00076
00077 #endif // #ifndef FILEFRAGMENTS_PAYLOADTRAITS_HPP_INCLUDED