本文整理汇总了C++中DVector::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ DVector::clear方法的具体用法?C++ DVector::clear怎么用?C++ DVector::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DVector
的用法示例。
在下文中一共展示了DVector::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendBuffer
bool D_bjmak::sendBuffer(QVector<FileID>& ids, qint64 bufferSize){
//QString idsBuffer;
//QString hashBuffer;
//QString dataBuffer;
std::cout << "sending buffer of " << ids.size() << std::endl;
server->connectionPtr->sendMsg("NEXT");
const int hashBufferSize = bufferSize / bsize_;
DVector hashBuffer;
hashBuffer.reserve(hashBufferSize);
DVector dataBuffer;
hashBuffer.reserve(bufferSize);
DVector idsBuffer;
hashBuffer.reserve(3000000);
int blockCount;
int fd;
bool isCleared = true;
for(int i = 0; i < ids.size(); ++i){
if (!ids[i].isREG()){
idsBuffer.push_back(ids[i].toString());
//cout << "added not reg " << ids[i].getFullPath().toStdString() << endl;
continue;
}
DVector tmpHashBuffer;
DVector tmpDataBuffer;
if ( (dataBuffer.size()+ids[i].getSize()) > bufferSize ){
blockCount = (bufferSize-dataBuffer.size()) / bsize_;
isCleared = false;
}
else{
blockCount = ids[i].getSize() / bsize_;
if ( (ids[i].getSize() % bsize_) != 0 )
++blockCount;
}
fd = open(ids[i].getFullPath().toStdString().c_str(), O_RDONLY);
if (fd == -1){
cout << "error " << strerror(errno) << endl;
writeLog.warning() << "Error open file <" << ids[i].getFullPath()
<< "> " << strerror(errno)
<< DebusLogger::endl;
continue;
}
if (!getHashesAndData(fd, tmpDataBuffer, tmpHashBuffer, blockCount)){
cout << "error " << strerror(errno) << endl;
writeLog.warning() << "Error read file <" << ids[i].getFullPath()
<< "> " << strerror(errno)
<< DebusLogger::endl;
continue;
}
idsBuffer.push_back(ids[i].toString());
//cout << "added reg " << ids[i].getFullPath().toStdString() << endl;
//idsBuffer.push_back(ids[i].toQString());
hashBuffer.push_back(tmpHashBuffer);
dataBuffer.push_back(tmpDataBuffer);
if (isCleared)
close(fd);
}
cout << "Sending idsbuffer " << idsBuffer.size() << endl;
server->connectionPtr->sendMsg(idsBuffer.data(), idsBuffer.size());
cout << "Sending hashBuffer " << hashBuffer.size() << endl;
server->connectionPtr->sendMsg(hashBuffer.data(), hashBuffer.size());
server->connectionPtr->recvMsg();
DVector reply;
reply.push_back(server->connectionPtr->dataToVector());
cout << "Received reply size " << reply.size() << endl;
DVector newDataBuffer;
newDataBuffer = this->getDataBufferFromReply(reply, hashBuffer, dataBuffer);
cout << "sending data size " << newDataBuffer.size() << endl;
server->connectionPtr->sendMsg(newDataBuffer.data(), newDataBuffer.size());
if (!isCleared){
int clearedBlockCount = blockCount;
blockCount = ids.last().getSize() / bsize_;
if ( (ids.last().getSize() % bsize_) != 0 )
++blockCount;
blockCount -= clearedBlockCount;
while(blockCount){
int i;
if (blockCount*bsize_ > bufferSize)
i = bufferSize/bsize_;
//.........这里部分代码省略.........