Block getWordBlock(std::string word, std::fstream& f, bool createIfReauired = false) { seekRW(f, 0); BlockOffset currentOffset = 0; Block b {readBlockFromFile(f)}; for(auto c : word) { unsigned int i = char2int(c); if (b.offsets[i] == 0 ) { if (!createIfReauired) { b.data=0; return b; } BlockOffset off = f.tellp(); Block newBlock {}; seekRW(f, 0, f.end); BlockOffset newCurrent = b.offsets[i] = writeBlockToFile(newBlock, f); seekRW(f, off); writeBlockToFile(b, f); seekRW(f, newCurrent); currentOffset = newCurrent; b = newBlock; } else { currentOffset = b.offsets[i]; seekRW(f, currentOffset); b = readBlockFromFile(f); } } return b; }
std::fstream& initializeFile(std::fstream& f, std::string fn) { f.close(); f.open( fn ,f.in | f.out | f.binary ); if (!f.is_open()) { f.open( fn , f.out | f.binary ); Block b {}; writeBlockToFile(b, f); f.close(); f.open( fn ,f.in | f.out | f.binary ); } return f; }
static void saveSequence(IOAdapter* io, const DNASequence& sequence, U2OpStatus& os) { writeHeaderToFile( io, sequence.getName( ), os ); CHECK_OP( os, ); const char *seq = sequence.seq.constData( ); const int len = sequence.seq.length( ); for ( int i = 0; i < len; i += SAVE_LINE_LEN ) { const int chunkSize = qMin( SAVE_LINE_LEN, len - i ); writeBlockToFile( io, seq + i, chunkSize, os ); CHECK_OP( os, ); } }
static void saveSequence( IOAdapter* io, const U2SequenceObject *sequence, U2OpStatus& os ) { writeHeaderToFile( io, sequence->getSequenceName( ), os ); CHECK_OP( os, ); const int len = sequence->getSequenceLength( ); for ( int i = 0; i < len; i += SAVE_LINE_LEN ) { int chunkSize = qMin( SAVE_LINE_LEN, len - i ); const QByteArray chunkContent = sequence->getSequenceData( U2Region( i, chunkSize ), os ); CHECK_OP( os, ); writeBlockToFile( io, chunkContent.constData( ), chunkSize, os ); CHECK_OP( os, ); } }
FileID addWord(std::string word, std::fstream& f, bool createIfReauired = true) { Block b = getWordBlock(word, f, createIfReauired); FileID fid {b.data}; if (!createIfReauired) return fid; if (fid == 0) fid = getNextID(); b.data = fid; writeBlockToFile(b, f); return fid; }