/** ** File ......... Piece.cpp ** Published .... 2005-06-14 ** Author ....... grymse@alhem.net **/ /* Copyright (C) 2005 Anders Hedstrom This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef _WIN32 #pragma warning(disable:4786) #endif #include "Session.h" #include "Piece.h" Piece::Piece(size_t nr,size_t piece_length) :m_nr(nr) ,m_piece_length(piece_length) { } Piece::~Piece() { } void Piece::Write(Session *sess,size_t offset, size_t length, unsigned char *ptr) { } void Piece::ClearComplete() { while (m_complete.size()) { slice_m::iterator it = m_complete.begin(); m_complete.erase(it); } } void Piece::ClearRequested() { while (m_requested.size()) { slice_m::iterator it = m_requested.begin(); m_requested.erase(it); } } void Piece::save_slice_m(FILE *fil,slice_m& ref) { size_t q = ref.size(); fwrite(&q, sizeof(size_t), 1, fil); for (slice_m::iterator it = ref.begin(); it != ref.end(); it++) { size_t offset = (*it).first; size_t length = (*it).second; fwrite(&offset, sizeof(size_t), 1, fil); fwrite(&length, sizeof(size_t), 1, fil); } } void Piece::load_slice_m(FILE *fil,slice_m& ref) { size_t q; fread(&q, sizeof(size_t), 1, fil); while (q--) { size_t offset, length; fread(&offset, sizeof(size_t), 1, fil); fread(&length, sizeof(size_t), 1, fil); ref[offset] = length; } }