int QModelKeyframed::AddFrame(QFrame *pFrame) { unsigned int Index = GetNextIndex(); m_pFrames[Index] = pFrame; m_NumElements++; return (Index); }
bool TextSearch::FindTextInPage(int pageNo) { if (str::IsEmpty(findText)) return false; if (!pageNo) pageNo = findPage; findPage = pageNo; const WCHAR *found; int length; do { if (!anchor) found = GetNextIndex(pageText, findIndex, forward); else if (forward) found = (caseSensitive ? StrStr : StrStrI)(pageText + findIndex, anchor); else found = StrRStrI(pageText, pageText + findIndex, anchor); if (!found) return false; findIndex = (int)(found - pageText) + (forward ? 1 : 0); length = MatchLen(found); } while (length <= 0); int offset = (int)(found - pageText); StartAt(pageNo, offset); SelectUpTo(pageNo, offset + length); findIndex = offset + (forward ? length : 0); // try again if the found text is completely outside the page's mediabox if (result.len == 0) return FindTextInPage(pageNo); return true; }
int QMesh::AddPrimitive(QPrimitive *pPrimitive) { unsigned int Index = GetNextIndex(); m_pPrimitives[Index] = pPrimitive; m_NumElements++; return (Index); }
int QFrame::AddMesh(QMesh *pMesh) { unsigned int Index = GetNextIndex(); pMesh->m_pEngine = m_pEngine; m_pMeshes[Index] = pMesh; m_NumElements++; return (Index); }
void CMainWnd::OnPlayNext() { int nNext = GetNextIndex(); if (nNext == OPEN_NONE) return; BOOL fPlay = MAP_GetStatus(m_hMap) != MAP_STATUS_STOP; Open(nNext); if (fPlay) Play(); }
// // Add old packet // void Server::Session::AddOldPkt(Packet &pkt) { // Is the buffer full ? if (oldPkts[oldPktsIndex]) { // Blow away oldest packet oldPkts[oldPktsIndex]->Destroy(); } // Add this packet oldPkts[oldPktsIndex] = &pkt; // Adjust index oldPktsIndex = GetNextIndex(oldPktsIndex); }
int QFontManager::Create2D(char *Name, int Size) { QFont *pFont; switch(m_pEngine->m_Renderer) { case RENDER_OPENGL: pFont = new QFontOpenGL(m_pEngine); break; case RENDER_DIRECTX: pFont = new QFontDirectX(m_pEngine); break; } pFont->Create2D(Name,Size); unsigned int Index = GetNextIndex(); m_pFontList[Index] = pFont; m_NumElements++; return (Index); }
std::vector<int> CPatternManager::Pattern::FindPatternAt(std::vector<int> color_list, int i, StepType t) { std::vector<int> result; int cur_index = i; int color = -1; for (int index = 0; index < pattern.size(); index++) { ItemType itype = static_cast<ItemType> (pattern[index]); cur_index = GetNextIndex(cur_index, t, true); switch (itype) { case MustMatch: { if (cur_index == -1) { result.clear(); return result; } if (color == -1) { color = color_list[cur_index]; result.push_back(cur_index); break; } if (color != color_list[cur_index]) { result.clear(); return result; } result.push_back(cur_index); break; } case WildCard: break; } } return result; }
// MLTSampler Method Definitions Float MLTSampler::Get1D() { int index = GetNextIndex(); EnsureReady(index); return X[index].value; }
unsigned long Measurement::GetNextDataBulk() { FILE_LOG(logDEBUG3) << "Measurement::GetNextDataBulk"; unsigned long i, j, index; short *overflow; uint32_t traces_asked_for, length_of_trace_fetched; // unsigned long length_of_trace_askedfor, length_of_trace_fetched; Timing t; // std::cerr << "(GetNextDataBulk: " << GetNextIndex() << ", " << GetMaxTracesToFetch() << ")\n"; // it makes no sense to read any further: we are already at the end if(GetNextIndex() >= GetNTraces()) { std::cerr << "Stop fetching data from ociloscope." << std::endl; return 0UL; } /* try { for(i=0; i<GetNumberOfChannels(); i++) { if(GetChannel(i)->IsEnabled()) { delete [] data[i]; data[i] = new short[GetMaxTracesToFetch()*GetLength()]; } } } catch(...) { std::cerr << "Unable to allocate memory in Measurement::AllocateMemoryBlock." << std::endl; throw; } /**/ traces_asked_for = GetMaxTracesToFetch(); if(GetNextIndex() + traces_asked_for > GetNTraces()) { traces_asked_for = GetNTraces() - GetNextIndex(); } // allocate buffers for(i=0; i<GetNumberOfChannels(); i++) { if(GetChannel(i)->IsEnabled()) { FILE_LOG(logDEBUG4) << "Measurement::GetNextDataBulk - memset data[i]" << GetLength()*traces_asked_for*sizeof(short); memset(data[i], 0, GetLength()*traces_asked_for*sizeof(short)); FILE_LOG(logDEBUG4) << "done"; } for(j=0; j<traces_asked_for; j++) { index = j+GetNextIndex(); if(GetChannel(i)->IsEnabled()) { if(data_allocated[i] == false) { throw "Unable to get data. Memory is not allocated."; } if(GetSeries() == PICO_4000) { // GetPicoscope()->SetStatus(ps4000SetDataBufferBulk( // GetHandle(), // handle // (PS4000_CHANNEL)i, // channel // data[i], // *buffer // GetMaxTraceLengthToFetch())); // bufferLength GetPicoscope()->SetStatus(ps4000SetDataBufferBulk( GetHandle(), // handle (PS4000_CHANNEL)i, // channel &data[i][j*GetLength()], // *buffer GetLength(), // bufferLength index)); // waveform } else { // unsigned long dj = (j+GetNextIndex()/GetMaxTracesToFetch())%traces_asked_for; // std::cerr << "-- (set data buffer bulk: [" << i << "][" << dj // << "], len:" << GetLength() << ", index:" << index // << ", from:" << GetNextIndex() // << ", to:" << GetNextIndex()+traces_asked_for-1 << "\n"; GetPicoscope()->SetStatus(ps6000SetDataBufferBulk( GetHandle(), // handle (PS6000_CHANNEL)i, // channel &data[i][j*GetLength()], // *buffer GetLength(), // bufferLength index, // waveform PS6000_RATIO_MODE_NONE)); // downSampleRatioMode } if(GetPicoscope()->GetStatus() != PICO_OK) { std::cerr << "Unable to set memory for channel." << std::endl; throw Picoscope::PicoscopeException(GetPicoscope()->GetStatus()); } } } } // fetch data // length_of_trace_fetched = length_of_trace_askedfor; std::cerr << "Get data for traces " << GetNextIndex() << "-" << GetNextIndex()+traces_asked_for << " (" << 100.0*(GetNextIndex()+traces_asked_for)/GetNTraces() << "%) ... "; overflow = new short[traces_asked_for]; memset(overflow, 0, traces_asked_for*sizeof(short)); // std::cerr << "-- x1\n"; t.Start(); // std::cerr << "length of buffer: " << data_length[0] << ", length of requested trace: " << length_of_trace_askedfor << " ... "; if(GetSeries() == PICO_4000) { length_of_trace_fetched = GetLength(); GetPicoscope()->SetStatus(ps4000GetValuesBulk( GetHandle(), // handle &length_of_trace_fetched, // *noOfSamples // TODO: start index GetNextIndex(), // fromSegmentIndex GetNextIndex()+traces_asked_for-1, // toSegmentIndex // this could also be min(GetMaxTraceLengthToFetch(),wholeLength-startindex) overflow)); // *overflow } else { // TODO: not sure about this ... length_of_trace_fetched = GetLength(); GetPicoscope()->SetStatus(ps6000GetValuesBulk( GetHandle(), // handle &length_of_trace_fetched, // *noOfSamples // TODO: start index GetNextIndex(), // fromSegmentIndex GetNextIndex()+traces_asked_for-1, // toSegmentIndex // this could also be min(GetMaxTraceLengthToFetch(),wholeLength-startindex) 1, // downSampleRatio PS6000_RATIO_MODE_NONE, // downSampleRatioMode overflow)); // *overflow } t.Stop(); // std::cerr << "-- x2\n"; if(GetPicoscope()->GetStatus() != PICO_OK) { std::cerr << "Unable to set memory for channel." << std::endl; throw Picoscope::PicoscopeException(GetPicoscope()->GetStatus()); } for(i=0; i<traces_asked_for; i++) { for(j=0; i<GetNumberOfChannels(); i++) { if(overflow[i] & (1<<j)) { FILE_LOG(logWARNING) << "Warning: Overflow on channel " << (char)('A'+j) << " of trace " << i+GetNextIndex() << ".\n"; } } } delete [] overflow; // if(length_of_trace_fetched != length_of_trace_askedfor) { // std::cerr << "Warning: The number of read samples was smaller than requested.\n"; // } // getting timestamps int64_t *timestamps; PS6000_TIME_UNITS *timeunits; timestamps = new int64_t[traces_asked_for]; timeunits = new PS6000_TIME_UNITS[traces_asked_for]; if(GetSeries() == PICO_4000) { // NOT YET IMPLEMENTED } else { FILE_LOG(logDEBUG2) << "ps6000GetValuesTriggerTimeOffsetBulk64(handle=" << GetHandle() << ", *timestamps, *timeunits, fromSegmentIndex=" << GetNextIndex() << ", toSegmentIndex=" << GetNextIndex()+traces_asked_for-1 << ")"; GetPicoscope()->SetStatus(ps6000GetValuesTriggerTimeOffsetBulk64( GetHandle(), // handle timestamps, // *times timeunits, // *timeUnits GetNextIndex(), // fromSegmentIndex GetNextIndex()+traces_asked_for-1)); // toSegmentIndex } if(GetPicoscope()->GetStatus() != PICO_OK) { std::cerr << "Unable to get timestamps." << std::endl; throw Picoscope::PicoscopeException(GetPicoscope()->GetStatus()); } // for(i=0; i<traces_asked_for; i++) { // std::cerr << "time " << i << ": " << timestamps[i] << "\n"; // } SetRate(traces_asked_for, timestamps[0], timeunits[0], timestamps[traces_asked_for-1], timeunits[traces_asked_for-1]); // if(timeunits[0] != timeunits[traces_asked_for-1]) { // FILE_LOG(logWARNING) << "time unit of the first and last sample differ; rate is not reliable; TIMING seems to be broken anyway"; // } delete [] timestamps; delete [] timeunits; std::cerr << "OK ("<< t.GetSecondsDouble() <<"s)\n"; // std::cerr << "length of trace fetched: " << length_of_trace_fetched << "\n"; // std::cerr << "total length: " << traces_asked_for*length_of_trace_fetched << "\n"; SetLengthFetched(traces_asked_for*length_of_trace_fetched); // std::cerr << "-- next index is now " << GetNextIndex() << ", will be set to " << GetNextIndex() + traces_asked_for << "\n"; SetNextIndex(GetNextIndex()+traces_asked_for); // std::cerr << "-- next index is now " << GetNextIndex() << "\n"; // std::cerr << "-- return value " << traces_asked_for << "\n"; return traces_asked_for; }
// TODO: we might want to use multiple buffers at the same time // returns the length of data // TODO: the first part only needs to be called once; so we should move the code at the end of RunBlock // unless we want to alternate between allocated memory (to enable parallel readouts) unsigned long Measurement::GetNextData() { FILE_LOG(logDEBUG3) << "Measurement::GetNextData"; int i; short overflow=0; uint32_t length_of_trace_askedfor, length_of_trace_fetched; Timing t; // it makes no sense to read any further: we are already at the end if(GetNextIndex() >= GetLength()) { std::cerr << "Stop fetching data from osciloscope." << std::endl; return 0UL; } length_of_trace_askedfor = GetMaxTraceLengthToFetch(); if(GetNextIndex() + length_of_trace_askedfor > GetLength()) { length_of_trace_askedfor = GetLength() - GetNextIndex(); } // allocate buffers for(i=0; i<GetNumberOfChannels(); i++) { if(GetChannel(i)->IsEnabled()) { if(data_allocated[i] == false) { throw "Unable to get data. Memory is not allocated."; } if(GetSeries() == PICO_4000) { FILE_LOG(logDEBUG2) << "ps4000SetDataBuffer(handle=" << GetHandle() << ", channel=" << i << ", *buffer=<data[i]>, bufferLength=" << GetMaxTraceLengthToFetch() << ")"; GetPicoscope()->SetStatus(ps4000SetDataBuffer( GetHandle(), // handle (PS4000_CHANNEL)i, // channel data[i], // *buffer GetMaxTraceLengthToFetch())); // bufferLength } else { FILE_LOG(logDEBUG2) << "ps6000SetDataBuffer(handle=" << GetHandle() << ", channel=" << i << ", *buffer=<data[i]>, bufferLength=" << GetMaxTraceLengthToFetch() << ", downSampleRatioMode=PS6000_RATIO_MODE_NONE)"; GetPicoscope()->SetStatus(ps6000SetDataBuffer( GetHandle(), // handle (PS6000_CHANNEL)i, // channel data[i], // *buffer GetMaxTraceLengthToFetch(), // bufferLength PS6000_RATIO_MODE_NONE)); // downSampleRatioMode } if(GetPicoscope()->GetStatus() != PICO_OK) { std::cerr << "Unable to set memory for channel." << std::endl; throw Picoscope::PicoscopeException(GetPicoscope()->GetStatus()); } } } // fetch data length_of_trace_fetched = length_of_trace_askedfor; std::cerr << "Get data for points " << GetNextIndex() << "-" << GetNextIndex()+length_of_trace_askedfor << " (" << 100.0*(GetNextIndex()+length_of_trace_askedfor)/GetLength() << "%) ... "; t.Start(); // std::cerr << "length of buffer: " << data_length[0] << ", length of requested trace: " << length_of_trace_askedfor << " ... "; if(GetSeries() == PICO_4000) { FILE_LOG(logDEBUG2) << "ps4000GetValues(handle=" << GetHandle() << ", startIndex=" << GetNextIndex() << ", *noOfSamples=" << length_of_trace_fetched << ", downSampleRatio=1, downSampleRatioMode=PS4000_RATIO_MODE_NONE, segmentIndex=0, *overflow)"; GetPicoscope()->SetStatus(ps4000GetValues( GetHandle(), // handle // TODO: start index GetNextIndex(), // startIndex // this could also be min(GetMaxTraceLengthToFetch(),wholeLength-startindex) &length_of_trace_fetched, // *noOfSamples 1, // downSampleRatio PS4000_RATIO_MODE_NONE, // downSampleRatioMode 0, // segmentIndex &overflow)); // *overflow FILE_LOG(logDEBUG2) << "-> length_of_trace_fetched=" << length_of_trace_fetched << "\n"; } else { FILE_LOG(logDEBUG2) << "ps6000GetValues(handle=" << GetHandle() << ", startIndex=" << GetNextIndex() << ", *noOfSamples=" << length_of_trace_fetched << ", downSampleRatio=1, downSampleRatioMode=PS6000_RATIO_MODE_NONE, segmentIndex=0, *overflow)"; GetPicoscope()->SetStatus(ps6000GetValues( GetHandle(), // handle // TODO: start index GetNextIndex(), // startIndex // this could also be min(GetMaxTraceLengthToFetch(),wholeLength-startindex) &length_of_trace_fetched, // *noOfSamples 1, // downSampleRatio PS6000_RATIO_MODE_NONE, // downSampleRatioMode 0, // segmentIndex &overflow)); // *overflow FILE_LOG(logDEBUG2) << "-> length_of_trace_fetched=" << length_of_trace_fetched << "\n"; } t.Stop(); if(GetPicoscope()->GetStatus() != PICO_OK) { std::cerr << "Unable to set memory for channel." << std::endl; throw Picoscope::PicoscopeException(GetPicoscope()->GetStatus()); } if(overflow) { for(i=0; i<GetNumberOfChannels(); i++) { if(overflow & (1<<i)) { std::cerr << "Warning: Overflow on channel " << (char)('A'+i) << ".\n"; } } } if(length_of_trace_fetched != length_of_trace_askedfor) { std::cerr << "Warning: The number of read samples was smaller than requested.\n"; } std::cerr << "OK ("<< t.GetSecondsDouble() <<"s)\n"; SetLengthFetched(length_of_trace_fetched); SetNextIndex(GetNextIndex()+length_of_trace_fetched); return length_of_trace_fetched; }
// MLTSampler Method Definitions Float MLTSampler::Get1D() { ProfilePhase _(Prof::GetSample); int index = GetNextIndex(); EnsureReady(index); return X[index].value; }
void ParseOBJFile(const char *pFilePtr) { const char *pToken = GetNextToken(pFilePtr); while(*pToken != 0) { if(!MFString_CaseCmp(pToken, "o")) { const char *pName = GetRestOfLine(pFilePtr); pModel->name = pName; } else if(!MFString_CaseCmp(pToken, "g")) { const char *pName = GetRestOfLine(pFilePtr); if(!vertsInGroup) { // we'll just rename the current subobject, since theres nothing in it.. F3DSubObject &sub = pModel->GetMeshChunk()->subObjects[subObject]; sub.name = pName; } else { // probably wanna copy vertex data in at this point.. // and subtract the min from each of the components indices.. CopyDataIntoSubobject(subObject); ++subObject; matSub = 0; minVertIndex = -1; minUVIndex = -1; minNormIndex = -1; maxVertIndex = -1; maxUVIndex = -1; maxNormIndex = -1; vertsInGroup = false; vertsInMatSub = false; F3DSubObject &sub = pModel->GetMeshChunk()->subObjects[subObject]; sub.name = pName; } } else if(!MFString_CaseCmp(pToken, "v")) { const char *pX = GetNextToken(pFilePtr); const char *pY = GetNextToken(pFilePtr); const char *pZ = GetNextToken(pFilePtr); pFilePtr = MFSeekNewline(pFilePtr); MFVector v; v.x = (float)atof(pX); v.y = (float)atof(pY); v.z = (float)atof(pZ); v.w = 1.0f; verts.push(v); } else if(!MFString_CaseCmp(pToken, "vt")) { const char *pU = GetNextToken(pFilePtr); const char *pV = GetNextToken(pFilePtr); pFilePtr = MFSeekNewline(pFilePtr); MFVector v; v.x = (float)atof(pU); v.y = (float)atof(pV); v.z = 0.0f; v.w = 1.0f; uvs.push(v); } else if(!MFString_CaseCmp(pToken, "vn")) { const char *pX = GetNextToken(pFilePtr); const char *pY = GetNextToken(pFilePtr); const char *pZ = GetNextToken(pFilePtr); pFilePtr = MFSeekNewline(pFilePtr); MFVector v; v.x = (float)atof(pX); v.y = (float)atof(pY); v.z = (float)atof(pZ); v.w = 1.0f; normals.push(v); } else if(!MFString_CaseCmp(pToken, "f")) { vertsInGroup = true; vertsInMatSub = true; F3DSubObject &sub = pModel->GetMeshChunk()->subObjects[subObject]; const char *pRestOfLine = GetRestOfLine(pFilePtr); int firstVert = (int)sub.matSubobjects[matSub].vertices.size(); pToken = GetNextToken(pRestOfLine); while(*pToken) { const char *pPos = GetNextIndex(pToken); const char *pUV = GetNextIndex(pToken); const char *pNorm = GetNextIndex(pToken); int posid = atoi(pPos); int texid = atoi(pUV); int normid = atoi(pNorm); if(posid < 0) posid = (int)verts.size() - posid; else posid = posid - 1; if(texid < 0) texid = (int)uvs.size() - texid; else texid = texid - 1; if(normid < 0) normid = (int)normals.size() - normid; else normid = normid - 1; minVertIndex = minVertIndex == -1 ? posid : MFMin(minVertIndex, posid); minUVIndex = minUVIndex == -1 ? texid : MFMin(minUVIndex, texid); minNormIndex = minNormIndex == -1 ? normid : MFMin(minNormIndex, normid); maxVertIndex = minVertIndex == -1 ? posid : MFMax(maxVertIndex, posid); maxUVIndex = maxUVIndex == -1 ? texid : MFMax(maxUVIndex, texid); maxNormIndex = maxNormIndex == -1 ? normid : MFMax(maxNormIndex, normid); int vi = (int)sub.matSubobjects[matSub].vertices.size(); int f = vi - firstVert; F3DVertex &vert = sub.matSubobjects[matSub].vertices[firstVert + f]; vert.position = posid; vert.uv[0] = texid; vert.normal = normid; // add a triangle if we are up to the third vert or beyond if(f >= 2) { F3DTriangle &tri = sub.matSubobjects[matSub].triangles.push(); tri.v[0] = firstVert; tri.v[1] = vi-1; tri.v[2] = vi; } pToken = GetNextToken(pRestOfLine); } } else if(!MFString_CaseCmp(pToken, "usemtl")) { F3DSubObject &sub = pModel->GetMeshChunk()->subObjects[subObject]; if(vertsInGroup && vertsInMatSub) { ++matSub; vertsInMatSub = false; } const char *pName = GetRestOfLine(pFilePtr); sub.matSubobjects[matSub].materialIndex = GetMaterialID(pName); } else if(!MFString_CaseCmp(pToken, "mtllib")) { // load material info? //.. pFilePtr = MFSeekNewline(pFilePtr); } else if(pToken[0] == '#') { pFilePtr = MFSeekNewline(pFilePtr); } else { MFDebug_Warn(2, MFStr("Unknown token encountered in obj file '%s'!", pToken)); pFilePtr = MFSeekNewline(pFilePtr); } pToken = GetNextToken(pFilePtr); } // want to copy vertex data into the last subobject at this point... if(vertsInGroup) { CopyDataIntoSubobject(subObject); } }
LogEntry* LogManager::CreateEntry(uint64_t term,Commond* cmd,EventBase* ev){ LogEntry* entry = new LogEntry(this,GetNextIndex(),term,cmd,ev); return entry; }