本文整理汇总了C++中OutputBuffer::usedSize方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputBuffer::usedSize方法的具体用法?C++ OutputBuffer::usedSize怎么用?C++ OutputBuffer::usedSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputBuffer
的用法示例。
在下文中一共展示了OutputBuffer::usedSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addMsScans
// Add scans from the raw data file
// addMs2 enables/disables extraction of data from MS2 scans
int addMsScans(sqlite3 *db, const char *inputRawFileName, const char * outputFileName, Engine::Readers::RawData * pRawData, bool addMs2Peaks) {
createPeaksTable(db, inputRawFileName, addMs2Peaks);
// Prepare statement
const char *insertStatement = "INSERT INTO peaks (scan, peak_count, peaks) VALUES (?1, ?2, ?3);";
sqlite3_stmt *pStatement=NULL;
int rc = sqlite3_prepare_v2(db, insertStatement, strlen(insertStatement), &pStatement, NULL);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error when preparing insert statement.\n");
exit(1);
}
OutputBuffer buf;
try {
int percentDone = 0;
int numScans = pRawData->GetNumScans();
std::vector<double> mzs;
std::vector<double> intensities;
for(int i=pRawData->GetFirstScanNum(); i<=pRawData->GetLastScanNum(); i=pRawData->GetNextScanNum(i)) {
int msLevel = pRawData->GetMSLevel(i);
// MS level 1 indicates a survey (FTMS) scan
bool addThisScan = (msLevel==1) || (msLevel==2 && addMs2Peaks);
if(addThisScan) {
pRawData->GetRawData(&mzs, &intensities, i);
int scanNumber = i;
int numPeaks = mzs.size();
int numPeaksStored = 0;
// About 20% speedup - allocating what we need in advance
buf.ensureBufferHasSpace(numPeaks*2*sizeof(TJavaFloat));
// OUTPUT: m/z, intensity float pairs
std::vector<double>::iterator mzIt = mzs.begin();
std::vector<double>::iterator intIt = intensities.begin();
bool wasZero = false;
bool zeroStored = false;
TJavaFloat previousMass = 0.0;
while(mzIt!=mzs.end()) {
TJavaFloat newIntensity = (TJavaFloat)*intIt;
TJavaFloat newMass = (TJavaFloat)*mzIt;
bool isZero = newIntensity==(TJavaFloat)0.0;
// Skip long sequences of zeros. Retain only beginning and trailing zero for graph plotting
if(!wasZero) {
// Store current value
buf.addJavaFloat(newMass);
buf.addJavaFloat(newIntensity);
numPeaksStored++;
if(isZero) { // !wasZero, isZero
wasZero=true;
zeroStored=true;
}
} else { // wasZero
if(!isZero) {
wasZero=false;
if(!zeroStored) {
// Store the previous zero
buf.addJavaFloat(previousMass);
buf.addJavaFloat((TJavaFloat)0.0);
numPeaksStored++;
}
// Store current value
buf.addJavaFloat(newMass);
buf.addJavaFloat(newIntensity);
numPeaksStored++;
} else { // wasZero && isZero
// The current zero is not getting stored
zeroStored=false;
previousMass = newMass;
// Keep going, do not store anything
}
}
mzIt++;
intIt++;
}
// Store the last zero (if it did not get stored) to terminate our graph neatly
if(!zeroStored) {
buf.addJavaFloat(previousMass);
buf.addJavaFloat((TJavaFloat)0.0);
numPeaksStored++;
}
cse(sqlite3_bind_int(pStatement, 1, i));
cse(sqlite3_bind_int(pStatement, 2, numPeaksStored));
cse(sqlite3_bind_blob(pStatement, 3, buf.get(), buf.usedSize(), SQLITE_TRANSIENT));
rc = sqlite3_step(pStatement);
if(rc!=SQLITE_DONE) {
throw 1;
}
cse(sqlite3_reset(pStatement));
//.........这里部分代码省略.........