void UncompressedStream::read(void* ptr, size_t size) { size_t nUnused = (size_t) getUnusedLength(); char* unused = getUnused(); if (nUnused > 0) { // We have unused data from the last compressed read if (nUnused == size) { // Copy the unused data into the buffer memcpy(ptr, unused, nUnused); clearUnused(); } else if (nUnused < size) { // Copy the unused data into the buffer memcpy(ptr, unused, nUnused); // Still have data to read size -= nUnused; // Read the remaining data from the file int result = fread((char*) ptr + nUnused, 1, size, getFilePointer()); if ((size_t) result != size) throw BagIOException((format("Error reading from file + unused: wanted %1% bytes, read %2% bytes") % size % result).str()); advanceOffset(size); clearUnused(); } else { // nUnused_ > size memcpy(ptr, unused, size); setUnused(unused + size); setUnusedLength(nUnused - size); } } // No unused data - read from stream int result = fread(ptr, 1, size, getFilePointer()); if ((size_t) result != size) throw BagIOException((format("Error reading from file: wanted %1% bytes, read %2% bytes") % size % result).str()); advanceOffset(size); }
/** * Destroy a linked list. * * @param llist Ptr to the list to be destroyed. */ void List_Destroy(LinkList *list) { if(list) { clear(list); clearUnused(list); free(list->state); free(list); } }
void BZ2Stream::startRead() { bzfile_ = BZ2_bzReadOpen(&bzerror_, getFilePointer(), verbosity_, 0, getUnused(), getUnusedLength()); switch (bzerror_) { case BZ_OK: break; default: { BZ2_bzReadClose(&bzerror_, bzfile_); throw BagException("Error opening file for reading compressed stream"); } } clearUnused(); }
void toTemplateEdit::remove(void) { if (LastTemplate != TemplateMap.end()) { toTreeWidgetItem *item = findLast(); TemplateMap.erase(LastTemplate); LastTemplate = TemplateMap.end(); Name->setText(QString::null); Description->setText(QString::null); if (item) { connectList(false); clearUnused(Templates->firstChild(), ""); connectList(true); } } }
void toTemplateEdit::changeSelection(void) { bool update = false; if (LastTemplate != TemplateMap.end()) { if (Name->text() != (*LastTemplate).first || Description->text() != (*LastTemplate).second) { TemplateMap.erase(LastTemplate); TemplateMap[Name->text()] = Description->text(); allocateItem(); update = true; } } else if (!Name->text().isEmpty()) { TemplateMap[Name->text()] = Description->text(); allocateItem(); update = true; } LastTemplate = TemplateMap.end(); toTreeWidgetItem *item = Templates->selectedItem(); if (item) { QString str = name(item); LastTemplate = TemplateMap.find(str); if (LastTemplate != TemplateMap.end()) { Name->setText((*LastTemplate).first); Description->setText((*LastTemplate).second); Preview->setText((*LastTemplate).second); } else { Name->setText(QString::null); Description->clear(); Preview->setText(QString::null); } } else LastTemplate = TemplateMap.end(); clearUnused(Templates->firstChild(), ""); }
bool toTemplateEdit::clearUnused(toTreeWidgetItem *first, const QString &pre) { bool ret = false; while (first) { toTreeWidgetItem *delitem = first; QString str = pre; if (!str.isEmpty()) str += ":"; str += first->text(0).toLatin1(); if (first->firstChild() && clearUnused(first->firstChild(), str)) delitem = NULL; if (delitem && TemplateMap.find(str) != TemplateMap.end()) delitem = NULL; first = first->nextSibling(); if (!delitem) ret = true; else delete delitem; } return ret; }