Logo
~Apps~
~Projects~
~Contact~


Piece.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2005  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 #ifdef _WIN32
00024 #pragma warning(disable:4786)
00025 #endif
00026 #include "Session.h"
00027 #include "Piece.h"
00028 
00029 
00030 
00031 
00032 Piece::Piece(size_t nr,size_t piece_length)
00033 :m_nr(nr)
00034 ,m_piece_length(piece_length)
00035 {
00036 }
00037 
00038 
00039 Piece::~Piece()
00040 {
00041 }
00042 
00043 
00044 void Piece::Write(Session *sess,size_t offset, size_t length, unsigned char *ptr)
00045 {
00046 }
00047 
00048 
00049 void Piece::ClearComplete()
00050 {
00051         while (m_complete.size())
00052         {
00053                 slice_m::iterator it = m_complete.begin();
00054                 m_complete.erase(it);
00055         }
00056 }
00057 
00058 
00059 void Piece::ClearRequested()
00060 {
00061         while (m_requested.size())
00062         {
00063                 slice_m::iterator it = m_requested.begin();
00064                 m_requested.erase(it);
00065         }
00066 }
00067 
00068 
00069 void Piece::save_slice_m(FILE *fil,slice_m& ref)
00070 {
00071         size_t q = ref.size();
00072         fwrite(&q, sizeof(size_t), 1, fil);
00073         for (slice_m::iterator it = ref.begin(); it != ref.end(); it++)
00074         {
00075                 size_t offset = (*it).first;
00076                 size_t length = (*it).second;
00077                 fwrite(&offset, sizeof(size_t), 1, fil);
00078                 fwrite(&length, sizeof(size_t), 1, fil);
00079         }
00080 }
00081 
00082 
00083 void Piece::load_slice_m(FILE *fil,slice_m& ref)
00084 {
00085         size_t q;
00086         fread(&q, sizeof(size_t), 1, fil);
00087         while (q--)
00088         {
00089                 size_t offset, length;
00090                 fread(&offset, sizeof(size_t), 1, fil);
00091                 fread(&length, sizeof(size_t), 1, fil);
00092                 ref[offset] = length;
00093         }
00094 }
00095 
00096 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4