Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

PayloadTraits.hpp

Go to the documentation of this file.
00001 //
00002 // FileFragments/PayloadTraits.hpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 } // namespace detail
00076 
00077 #endif // #ifndef FILEFRAGMENTS_PAYLOADTRAITS_HPP_INCLUDED

Generated on Thu Dec 15 10:39:42 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2