📄 btdocument.h
字号:
#ifndef _BTDOCUMENT_H__
#define _BTDOCUMENT_H__
#include <vector>
#include <map>
#include <set>
#include <string>
#include<list>
using namespace std;
class BTSession;
class BTDocument{
typedef enum{
empty = 0,
whole,
partial
}DocState;
public:
#define DEFAULT_POPULARITY 1
static map<string, BTDocument*> mDocumentListBykey;
static map<int, BTDocument*> mDocumentListByID;
static int mNextAvailableId;
static int getNextAvailableId(void);
static BTDocument* getDocumentByKey(string);
static BTDocument* getDocumentByID(int);
public:
unsigned int mSize;
string mkey;
int mId;
int mPopularity;
DocState mState;
unsigned int mPieceLength;
unsigned int mLastPieceLength;
unsigned int mBlockLength;
unsigned int mPieceNum;
unsigned int mLeftPieceNum;
vector<bool>* mPieces;
map<unsigned int, unsigned int> mPartialList;
set< unsigned int> mDownloadingSet;
BTSession* mSession;
public:
BTDocument( string key, unsigned int size, int popularity = DEFAULT_POPULARITY );
~BTDocument( void );
void setSession( BTSession* session);
bool inPartialList( unsigned int index){
map< unsigned int, unsigned int>::iterator aIt = mPartialList.find(index);
if( aIt != mPartialList.end())
return true;
else
return false;
};
bool inDownLoadingSet( unsigned int index){
set< unsigned int>::iterator aIt = mDownloadingSet.find(index);
if( aIt != mDownloadingSet.end())
return true;
else
return false;
};
void addPiecedownloading( unsigned int index){
if( index > mPieceNum)
return;
mDownloadingSet.insert(index);
};
void removePiecedownloading(unsigned int index){
if( index > mPieceNum)
return;
mDownloadingSet.erase(index);
};
bool finishPiece(unsigned int index);
unsigned int getPieceProgress( unsigned int index){
map<unsigned int, unsigned int>::iterator aIt = mPartialList.find(index);
int len;
if(aIt != mPartialList.end()){
len = aIt ->second;
return len;
}
else
return 0;
};
bool setPieceProgress( unsigned int index, unsigned int offset){
if( index > mPieceNum)
return false;
mPartialList.erase(index);
mPartialList.insert(map< unsigned int, unsigned int>::value_type(index, offset));
return true;
};
bool addPieceProgress( unsigned int index, unsigned int addlen);
void removePieceProgress( unsigned int index){
mPartialList.erase(index);
};
unsigned int getLeftSize(void);
unsigned int getLeftPieceNum(void){
return mLeftPieceNum;
};
double getFinishedPercent(void);
void setWhole(void);
unsigned int getPieceLength( unsigned int);
bool isWhole(void){
if( mState == whole)
return true;
else
return false;
};
bool isEmpty(void){
if( mState == empty)
return true;
else
return false;
};
bool havePiece( unsigned int index){
if( index >= mPieceNum )
return false;
if( (*mPieces)[index])
return true;
else
return false;
}
vector<bool>* getPieces(void){
return mPieces;
};
vector<unsigned int>* morePieces(vector<bool>* peerPieces);
unsigned int getHavePiecesNum(void){
return mPieceNum - mLeftPieceNum;
};
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -