本文整理汇总了C++中BString::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::clear方法的具体用法?C++ BString::clear怎么用?C++ BString::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BString
的用法示例。
在下文中一共展示了BString::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get
void Buffer::get(BString &value)
{
TSize size {0};
if ((_readPos + sizeof(size)) > _writePos) {
throw Error("Read out of range");
}
memcpy(&size, _readPos, sizeof(size));
_readPos += sizeof(size);
if ((_readPos + size) > _writePos) {
throw Error("Read out of range");
}
value.clear();
value.add((char*)_readPos, size);
_readPos += size;
}
示例2: _writeItem
bool Slice::_writeItem(File &putTmpFile, BString &buf, IndexEntry &ie)
{
if (_dataFd.seek(_size, SEEK_SET) != (off_t)_size) {
log::Fatal::L("Can't seek slice dataFile %u\n", _sliceID);
return false;
}
const ItemHeader &itemHeader = ie.header;
if (_dataFd.write(&itemHeader, sizeof(itemHeader)) != sizeof(itemHeader)) {
log::Fatal::L("Can't write header to slice dataFile %u\n", _sliceID);
return false;
}
auto leftSize = ie.header.size;
while (leftSize > 0) {
TItemSize chunkSize = MAX_BUF_SIZE;
if (chunkSize > leftSize)
chunkSize = leftSize;
buf.clear();
if (putTmpFile.read(buf.reserveBuffer(chunkSize), chunkSize) != (ssize_t)chunkSize) {
log::Fatal::L("Can't read data from put tmp file %u\n", _sliceID);
return false;
}
if (_dataFd.write(buf.c_str(), buf.size()) != (ssize_t)buf.size()) {
log::Fatal::L("Can't write data to slice dataFile %u\n", _sliceID);
return false;
}
leftSize -= chunkSize;
}
ie.pointer.sliceID = _sliceID;
ie.pointer.seek = _size;
if (_indexFd.write(&ie, sizeof(ie)) != sizeof(ie)) {
log::Fatal::L("Can't write index entry to slice indexFile %u\n", _sliceID);
return false;
}
_size = _dataFd.seek(0, SEEK_CUR);
return true;
}