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

Exception.hpp

Go to the documentation of this file.
00001 //
00002 // FileFragments/Exception.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_EXCEPTION_HPP_INCLUDED
00023 #define FILEFRAGMENTS_EXCEPTION_HPP_INCLUDED
00024 
00025 namespace detail
00026 {
00027 
00028 // @class exception
00029 //       This is the general exception class used in this subsystem.
00030 //       All exceptions generated by any facility of this subsystem
00031 //       are guarantied to be derived from it, except for ::std::bad_alloc.
00032 //       This allows exception handling on per subsystem base if desired.
00033 class Exception : public ::std::exception
00034 {
00035 public:
00036     Exception(const char* message) throw() : msg_( message ) { }
00037     char const* what() const throw() { return msg_; }
00038     ~Exception() throw() { }
00039 private:
00040     const char* msg_;
00041 };
00042 
00043 template< class FragmentT > class BadFragment : public Exception
00044 {
00045 public:
00046     typedef FragmentT FragmentType;
00047     typedef typename FragmentType::SizeType SizeType;
00048     typedef typename FragmentType::PayloadType PayloadType;
00049     BadFragment(SizeType begin, SizeType end, const PayloadType& payload) throw()
00050     : Exception( "Invalid fragment" ), 
00051       begin_( begin ),
00052       end_( end ),
00053       payload_( payload )
00054     { }
00055     ~BadFragment() throw() { }
00056     SizeType begin() const { return begin_; }
00057     SizeType end() const { return end_; }
00058 private:
00059     SizeType begin_;
00060     SizeType end_;
00061     PayloadType payload_;
00062 };
00063 
00064 template< class FragmentT > class BadRange : public Exception
00065 {
00066 public:
00067     typedef FragmentT FragmentType;
00068     typedef typename FragmentType::SizeType FSizeType;
00069     BadRange(const FragmentType& invalidFragment, FSizeType limit) throw()
00070     : Exception( "fragment exceeds filesize" ),
00071         invalidFragment_( invalidFragment ), limit_( limit )
00072     { }
00073     ~BadRange() throw() { }
00074     FSizeType begin() const { return invalidFragment_.begin(); }
00075     FSizeType end() const { return invalidFragment_.end(); }
00076     FSizeType length() const
00077     {
00078         return invalidFragment_.end() - invalidFragment_.begin();
00079     }
00080     FSizeType limit() const { return limit_; }
00081     FragmentType& value() { return invalidFragment_; }
00082     const FragmentType& value() const { return invalidFragment_; }
00083 private:
00084     FragmentType invalidFragment_;
00085     FSizeType limit_;
00086 };
00087 
00088 } // namespace detail
00089 
00090 #endif // #ifndef FILEFRAGMENTS_EXCEPTION_HPP_INCLUDED

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