int main() { unsigned char pos = getInitialPosition(); int arr[256]; while(1) { arr[pos] = getNextValue(); arr[pos + 1] = getNextValue(); pos += 2; } return 0; }
bool XMLRPC::bytesToString(std::string* _destination) { // Clear the destination before adding any chars. #if HAVE_STRING_CLEAR == 1 _destination->clear(); #else _destination->erase(_destination->begin(), _destination->end()); #endif XMLRPC_VALUE v = getNextValue(); if(XMLRPC_GetValueType(v) != xmlrpc_string) { return 0; } const char* s = XMLRPC_GetValueString(v); if(s == 0) { return false; } _destination->append(s); return true; }
bool XMLRPC::getBytes(t_byteP* _bytes, t_uint &_size) { *_bytes = 0; _size = 0; BTG_ICHECK(genericSDTDeserialize<t_uint>(&_size)); if(_size == 0) { return true; } XMLRPC_VALUE v = getNextValue(); if(XMLRPC_GetValueType(v) != xmlrpc_base64) { return 0; } // Determine size and get pointer _size = XMLRPC_GetValueStringLen(v); const char *p = XMLRPC_GetValueBase64(v); // Copy from xmlrpc-epi internal buffer to new buffer *_bytes = new t_byte[_size]; for (t_uint i=0; i < _size; i++) { (*_bytes)[i] = p[i]; } return true; }
bool XMLRPC::bytesToBool(bool & _destination) { XMLRPC_VALUE v = getNextValue(); if(XMLRPC_GetValueType(v) != xmlrpc_boolean) { return 0; } int res = XMLRPC_GetValueBoolean(v); switch (res) { case 0: _destination = false; break; case 1: _destination = true; break; default: return false; } success(); return true; }
void Spinner::handleNextButtonAction(ActionEventDetails* const e) { boost::any NewValue(getNextValue()); if(!NewValue.empty()) { setValue(NewValue); } }
void NavMap::readPolyFile() { std::ifstream poly("navMap.1.poly"); std::ifstream node("navMap.1.node"); std::ifstream ele("navMap.1.ele"); std::string bufferLine; int i = 0; vertex.clear(); while(std::getline(node, bufferLine)) { if(bufferLine[0] == '#') { i++; continue; } if(i == 0) { int sizeOf = std::atoi(bufferLine.substr(0, bufferLine.find(" ")).c_str()); vertex.reserve(sizeOf); for(int i = 0; i < sizeOf; i++) vertex.push_back(Vector::ZERO); } else { int f = 0; int n = std::atoi(getNextValue(bufferLine, f).c_str()); float x = static_cast<float>(std::atof(getNextValue(bufferLine, f).c_str())); float y = static_cast<float>(std::atof(getNextValue(bufferLine, f).c_str())); vertex[n - 1] = Vector(x, y); } i++; } poly.close(); i = 0; lines.clear(); meshes.clear(); while(std::getline(ele, bufferLine)) { if(bufferLine[0] == '#') { i++; continue; } if(i == 0) { int sizeOf = std::atoi(bufferLine.substr(0, bufferLine.find(" ")).c_str()); lines.reserve(sizeOf * 3); meshes.reserve(sizeOf); for(int i = 0; i < sizeOf * 3; i++) lines.push_back(line(Vector::ZERO, Vector::ZERO)); for(int i = 0; i < sizeOf; i++) meshes.push_back(Triangle(0, 0, 0)); } else { int f = 0; int n = (std::atoi(getNextValue(bufferLine, f).c_str()) - 1) * 3; unsigned int A = static_cast<unsigned int>(std::atoi(getNextValue(bufferLine, f).c_str())); unsigned int B = static_cast<unsigned int>(std::atoi(getNextValue(bufferLine, f).c_str())); unsigned int C = static_cast<unsigned int>(std::atoi(getNextValue(bufferLine, f).c_str())); Vector vecA = vertex[A - 1]; Vector vecB = vertex[B - 1]; Vector vecC = vertex[C - 1]; lines[n + 0] = line(vecA, vecB); lines[n + 1] = line(vecB, vecC); lines[n + 2] = line(vecC, vecA); meshes[n / 3] = Triangle(vecA, vecB, vecC); } i++; } }
double sumCand(List* candidates,int current) { double sum=0; ListCell *lc; foreach(lc,candidates) { ModelInfo *mdl=(((ModelInfo*)(lfirst(lc)))); sum+=getNextValue(mdl, current); }
void QGetOptions::getValues() { Q_ASSERT(QCoreApplication::instance()); QStringList arguments = QCoreApplication::instance()->arguments(); arguments.takeFirst(); //appname foreach (QString str, arguments) { getNextValue(str); }
int mapValues(struct keymap *keyList, char *line) { int pos = 0; char *value; int i = 0; int found; int numv = 0; while (keyList[i].key != NULL) { FREEUP (keyList[i].val); if (keyList[i].position != -1) numv++; i++; } while ((value = getNextValue(&line)) != NULL) { i=0; found = FALSE; while (keyList[i].key != NULL) { if (keyList[i].position != pos) { i++; continue; } if (strcmp (value, "-") == 0) keyList[i].val = putstr_(""); else { if (keyList[i].val != NULL) FREEUP (keyList[i].val); keyList[i].val = putstr_(value); } found = TRUE; break; } if (! found) goto fail; pos++; } if (pos != numv) goto fail; return 0; fail: i=0; while (keyList[i].key != NULL) { if (keyList[i].val != NULL) { free(keyList[i].val); keyList[i].val = NULL; } i++; } return -1; }
bool XMLRPC::bytesToFloat(t_float* _destination) { XMLRPC_VALUE v = getNextValue(); if(XMLRPC_GetValueType(v) != xmlrpc_double) { return 0; } double d = XMLRPC_GetValueDouble(v); (*_destination) = static_cast<t_float>(d); return true; }
t_int XMLRPC::genericSDTDeserialize(destinationType *_destination) { destinationType d; XMLRPC_VALUE v=getNextValue(); if(XMLRPC_GetValueType(v) != xmlrpc_int) { return 0; } d = XMLRPC_GetValueInt(v); (*_destination) = d; return sizeof(d); }
bool XMLRPC::getByte(t_byte & _byte) { XMLRPC_VALUE v = getNextValue(); if(XMLRPC_GetValueType(v) != xmlrpc_int) { return 0; } int res = XMLRPC_GetValueInt(v); _byte = static_cast<t_byte>(res); success(); return true; }
Block* NSDecoder::getNextBlock() { if (!hasNextBlock()) return NULL; int startPos = *startPosPtr+currLoc; int i; for (i = 0; i < bufferSize; i++) { if (!(getNextValue(outBuffer+i))) { //i++; break; } } //outBuffer-=i; outBlock->setBuffer(startPos, i, (byte*)outBuffer); return outBlock; }
main() { SkipList_t *list = NULL; char buf[256]; int choice = 0; list = SkipListAlloc( myCmp, myFree ); if ( list == NULL ) { printf( "ERROR: Allocation of skip list failed\n" ); exit(1); } while (1) { displayMenu(); choice = atoi( gets(buf) ); switch( choice ) { case 1 : insertValue( list ); break; case 2 : deleteValue( list ); break; case 3 : searchValue( list ); break; case 4 : getNextValue( list ); break; case 5 : printValue( list ); break; case 6 : clearList( list ); break; case 7: SkipListFree(list); exit(0); default : break; } } exit(0); }
//## Other Operations (implementation) //## Operation: nextValue%36B6E4C701BF // ******************************************************************************** // // Name: RetCode nextValue(bool *pValue) // // Description: Returns the next value of the Draw distribution. // // Output parameters: bool *pValue; //next result generated // // Returns: SCH_SUCCESS // SCH_ALLOCATION_ERROR // // ******************************************************************************** RetCode DrawGen::nextValue (bool *pValue) { //## begin DrawGen::nextValue%36B6E4C701BF.body preserve=yes RetCode rc = SCH_SUCCESS; Float number; bool draw; if (thresholdNumber == 1) { draw = true; } else if (thresholdNumber == 0) { draw = false; } else { do { rc = getNextValue (&number); if (rc != SCH_SUCCESS) { break; } }while (number == thresholdNumber); if (rc == SCH_SUCCESS) { if (number < thresholdNumber) { draw = true; } else { draw = false; } } } *pValue = draw; return rc; //## end DrawGen::nextValue%36B6E4C701BF.body }
//## Other Operations (implementation) //## Operation: nextValue%370A4D090004 // ******************************************************************************** // // Name: RetCode nextValue(Float *pValue) // // Description: Returns the next value of the Pareto distribution. // // Output parameters: Float *pValue; //next number generated // // Returns: SCH_SUCCESS // SCH_ALLOCATION_ERROR // // ******************************************************************************** RetCode ParetoGen::nextValue (Float *pValue) { //## begin ParetoGen::nextValue%370A4D090004.body preserve=yes RetCode rc = SCH_SUCCESS; Float number; Double exponent; // limits the value of number to: 0 < number <= 1 // otherwise it can occur a exception at pow(number,-1.0/(double)alfa) do rc = getNextValue (&number); while (number == 0.0f ); exponent = pow (number, -1.0 / (Double) alfa); *pValue = exponent * k; return rc; //## end ParetoGen::nextValue%370A4D090004.body }
void solve(){ unsigned int prev_i_value, j_value; unsigned int sub_cnt = 0; prev_i_value = 1983; j_value = getNextValue(1983); unsigned int sub_sum = getInput(prev_i_value); unsigned long long i(1), j(1); while(j <= N){ if(sub_sum < K){ j += 1; if(j >= N){ break; } sub_sum += getInput(j_value); j_value = getNextValue(j_value); }else if(sub_sum == K){ sub_cnt += 1; i += 1; j += 1; if(j >= N){ break; } sub_sum -= getInput(prev_i_value); prev_i_value = getNextValue(prev_i_value); sub_sum += getInput(j_value); j_value = getNextValue(j_value); }else if(sub_sum > K){ i += 1; if(i > j){ j += 1; if(j >= N){ break; } sub_sum += getInput(j_value); j_value = getNextValue(j_value); } sub_sum -= getInput(prev_i_value); prev_i_value = getNextValue(prev_i_value); } } std::cout << sub_cnt << std::endl; }
int main(int argc, char* argv[]) { /* declare variables */ /* MPI Variables */ int dims[2], chunk_size; int myrank=0; /* declare t, x, y as ints to index the domain */ int x, y; double dt, dx, dy; /* step size for t, x, y*/ int tmax;/* entire domain */ domain_t mydom; /* domain struct to hold axis limits */ /* u is the wave magnitude as an double for best accuracy * u0 is the array representing the domain for iteration l-1 * u1 is the array representing the domain for iteration l * u2 is the array representing the domain for iteration l+1 */ double ** u0; double ** u1; double ** u2; double ** A; /* temporary arrays for allocation and free */ double * Adata; double ** B; double * Bdata; double ** C; double * Cdata; double ** utemp; unsigned int numBytesAll; unsigned int numBytesPerRow; unsigned int numElements; double dTemp; /* Pulse Height and cutoffs */ double pulse; /* magnitude of pulses */ double pulseThresh; /* magnitude at which new pulse happens */ double pulseThreshPct; /* percentage of last pulse when next pulse happens*/ double gMax; /* maximum magnitude of the wave @ current time step for whole domain*/ double myMaxMag; /* gMax for each node */ unsigned int pulseCount = 0; /* the number of pulses emitted, track to compare to mesh plot */ int * pulseTimes; /* the time steps at which pulses happened (for debugging) */ unsigned int pulseSide = 0; /* the side where the pulse comes from 0-3*/ unsigned int lastPulseX = 0; /* coordinates of the last pulse */ unsigned int lastPulseY = 0; unsigned int lastPulseT = 0; /* time value of the last pulse */ int pulseX, pulseY; /* c is the wave velocity - unused * r is a coefficient in the wave equation where r = dt/dx' */ double r; /* index variables for loops */ short i, j, l; /* result of the Courant-Friedrichs-Lewy condition */ double CFL; /* timing variables */ struct timeval startTime, endTime; long seconds, useconds; double preciseTime; #ifdef CREATEANIMATION char fname[20] = "outputtt"; char ext[]=".txt"; #endif /* CREATEANIMATION */ /* Get start time - executed by all nodes since no rank assigned yet*/ gettimeofday(&startTime, NULL); dims[0] = dims[1] = 1; /* duration of simulation(steps), width, and height of domain */ if(argc > 1) tmax = atoi(argv[1]); else tmax = 100; /* dom.size is input arg #2 */ if(argc > 2) dom.size = atoi(argv[2]); else dom.size = 256; dom.xmax = dom.ymax = dom.size; /* maximum extent of domain */ dom.xmin = dom.ymin = 1; /* always 1 */ dom.xmid = dom.ymid = dom.size / 2; dom.size = dom.size + 2; /* two greater for ghost rows*/ chunk_size = (dom.size - 2)/dims[0]; mydom.size = chunk_size + 2; /* pulse size and threshhold at which next pulse happens */ if(argc > 3) pulse = atoi(argv[3]); else pulse = 5.0; pulseThreshPct = 0.2; /* 20% of intitial pulse height */ pulseThresh = pulse * pulseThreshPct; /* calculate the x & y coordinates of the node's subdomain */ mydom.xmin = 1; mydom.xmax = chunk_size; mydom.ymin = 1; mydom.ymax = chunk_size; /* step sizes for t, x, & y*/ dt = 0.42; /* 42 */ dx = dy = 0.90; CFL = checkCFL(dx, dy, dt); r = dt/dx; if(myrank==0){ printf("CFL = %3.3f, r = %3.3f\n", CFL, r); } /* allocate memory for arrays */ pulseTimes = malloc(sizeof(int) * tmax); for (i = 0; i < tmax; i++) { pulseTimes[i] = 0; } /* allocate contiguous memory for array */ numElements = mydom.size * mydom.size; numBytesAll = numElements * sizeof(* Adata); numBytesPerRow = mydom.size * sizeof(* A); Adata = malloc(numBytesAll); if(Adata == NULL) printf("Error: P%d malloc failed for Adata(%u B)", myrank, numBytesAll ); A = malloc(numBytesPerRow); if(A == NULL) printf("Error: P%d: malloc failed for A(%u B)\n", myrank, numBytesPerRow ); for(i=0; i < mydom.size; ++i){ A[i] = &Adata[i * mydom.size]; } u0 = A; Bdata = malloc(numBytesAll); if(Bdata == NULL) printf("Error: P%d malloc failed for Bdata(%u B)", myrank, numBytesAll ); B = malloc(numBytesPerRow); if(B == NULL) printf("Error: P%d: malloc failed for B(%u B)\n", myrank, numBytesPerRow ); for(i=0; i < mydom.size; ++i){ B[i] = &Bdata[i * mydom.size]; } u1 = B; Cdata = malloc(numBytesAll); if(Cdata == NULL) printf("Error: P%d malloc failed for Cdata(%u B)", myrank, numBytesAll ); C = malloc(numBytesPerRow); if(C == NULL) printf("Error: P%d: malloc failed for C(%u B)\n", myrank, numBytesPerRow ); for(i=0; i < mydom.size; ++i){ C[i] = &Cdata[i * mydom.size]; } u2 = C; /* zero memory */ for(i=0; i<numElements; i++){ Adata[i] = Bdata[i] = Cdata[i] = 0.0000; } #ifdef VERBOSE printf("P%d: myXmin(%d), myXmax(%d), myYmin(%d), myYmax(%d), chunk(%d)\n",myrank,mydom.xmin,mydom.xmax,mydom.ymin,mydom.ymax,chunk_size); #endif /* cycle sequence: * determine if a pulse is going to occur, issue one * update your domain * */ /* loop through time at single step intervals */ pulseSide=0; x = dom.xmid; y = 0; #ifdef DEBUG if(!myrank) printf("Beginning time series\n"); fflush(stdout); #endif for(l = 0; l < tmax; ++l){ #ifdef ISSUEPULSE if(l > 1){/* don't bother with pulses until time has elapsed */ /* determine max of each sub-domain and Gather to root */ myMaxMag = findMaxMag(u1,chunk_size); #ifdef DEBUG printf("P%d(t%d): max=%2.2f\n",myrank,l,myMaxMag); fflush(stdout); #endif gMax = myMaxMag; if( gMax < pulseThresh ){ /* issue pulse if global max mag has degraded below * threshhold of initial pulse magnitude */ /* figure out where the pulse is going to be*/ #ifdef ROTATEPULSE /* rotate pulses around the perimeter*/ pulseSide = pulseCount % 4; if(pulseSide == 0){ /* west */ pulseX = dom.xmin+1; pulseY = dom.ymid+1; }else if(pulseSide == 1){ /* north */ pulseX = dom.xmid+1; pulseY = dom.ymax-1; }else if(pulseSide == 2){ /* east */ pulseX = dom.xmax-1; pulseY = dom.ymid+1; }else if(pulseSide == 3){ /* south */ pulseX = dom.xmid+1; pulseY = dom.ymin+1; } #else /* default is static pulse, off center */ pulseSide=0; pulseX = 1; pulseY = dom.ymid-1; #endif /* ROTATEPULSE */ #ifdef DEBUG /* root issues msg */ if( myrank == 0){ printf("t%d:Pulse to issue @ (%d, %d)\n",l,pulseX, pulseY); fflush(stdout); } #endif if( 1 ){/* always my pulse */ /* issue only if pulse loc is in your domain */ #ifdef DEBUG printf("==>P%d,t%d: pulse(%d,%d) is mine\n", myrank,l, pulseX, pulseY); fflush(stdout); #endif /* narrow pulse */ // /* pulses need to be adjusted to the local domain */ // x = pulseX - mydom.xmin; // y = pulseY - mydom.ymin; dTemp = u1[x][y];/* preserve original value */ u1[x][y] = 0; u1[x][y] = pulse; #ifdef DEBUG printf("P%d,t%d: pulse(%u)@(%d,%d,%4.2f), old=%4.2f, new=%4.2f\n" ,myrank,l,pulseCount+1,pulseX,pulseY,pulse, dTemp, u1[x][y]); #endif } pulseCount++; pulseTimes[l] = 1; lastPulseX = pulseX; lastPulseY = pulseY; lastPulseT = l; } } #endif /* ISSUEPULSE */ #ifdef UPDATEDOMAIN #ifdef USEUPENMP #pragma omp parallel for default(shared) private(dTemp, i, j) firstprivate(chunk_size, r) #endif /* calculate wave intensity @ each location in the domain */ for(i=1; i <= chunk_size; i++){ for(j=1; j <= chunk_size; j++){ dTemp = u1[i][j]; ARRVAL(u2, i, j) = getNextValue(ARRVAL(u1, i, j), ARRVAL(u0, i, j), ARRVAL(u1, i+1, j), ARRVAL(u1, i, j+1), ARRVAL(u1, i-1, j), ARRVAL(u1, i, j-1), r); } } #endif /* UPDATEDOMAIN */ #ifdef ZEROPULSES if(lastPulseT == l){ #ifdef DEBUG /* root issues msg */ printf("t%d:Pulse to clear @ (%d, %d)\n",l, lastPulseX, lastPulseY); fflush(stdout); #endif /* Kill pulse only if pulse loc is in your domain */ #ifdef DEBUG printf("==>P%d,t%d: kill(%d,%d) is mine\n", myrank,l, lastPulseX, lastPulseY); fflush(stdout); #endif x = lastPulseX; y = lastPulseY; dTemp = u1[x][y];/* preserve original value */ u1[x][y] = 0; #ifdef DEBUG printf("==>P%d,t%d: kill(%u)@(%d,%d,%4.2f), old=%4.2f, new=%4.2f\n" ,myrank,l,pulseCount,lastPulseX,lastPulseY,0.0, dTemp, u1[x][y]); #endif } #endif /* ZEROPULSES */ /* rotate the u-arrays so that u1/u(l) becomes u2/u(l+1) and * u0/u(l-1) becomes u1/u(l) */ utemp = u1; u1 = u2; u2 = u0; u0 = utemp; #ifdef VERBOSEDEBUG if(!myrank) printf("\n"); #endif #ifdef CREATEANIMATION /* assumes fname <= 6 chars */ sprintf(fname+6, "%d",l+1); strcat(fname, ext); #ifdef DEBUG printf("Printing (%d) to: %s\n",mydom.size,fname); #endif filePrintMatrix(fname,u1,dom.size); #endif /* CREATEANIMATION */ }/* end for l=0:tmax */ #ifdef OUTPUT /* verified to work. Not likely to have bugs */ /* print the last iteration to a file */ if(myrank == 0){ #ifdef VERBOSE printf("p%d Writing to output.txt....\n",myrank); #endif filePrintMatrix("output.txt",u1,dom.size); #ifdef VERBOSE printf("P%d: closing file\n",myrank); fflush(stdout); #endif } #endif /* OUTPUT */ /* print total number of pulses */ if (myrank == 0) { printf("P(%d) pulseCount=%u\npulseTimes[", myrank, pulseCount); fflush(stdout); for(i = 0; i < tmax; i++){ if (pulseTimes[i] > 0) { printf(" %d", i); fflush(stdout); } } printf("]\n"); fflush(stdout); #ifdef VERBOSE printIRow(pulseTimes, tmax); #endif } #ifdef FREEMEMORY /* free memory for arrays */ /* free memory for u0 */ #ifdef VERBOSE printf("P%d Freeing contiguous memory...\n", myrank); #endif fflush(stdout); free(A); free(Adata); free(B); free(Bdata); free(C); free(Cdata); free(pulseTimes); #endif /* FREEMEMORY */ /* timekeeping - only needs to be executed by root*/ if(myrank == 0) { gettimeofday(&endTime, NULL); seconds = endTime.tv_sec - startTime.tv_sec; useconds = endTime.tv_usec - startTime.tv_usec; preciseTime = seconds + useconds/1000000.0; printf("Total Time = %3.4f\n", preciseTime ); } return 0; }/* end main() */
//## Other Operations (implementation) //## Operation: nextValue%3739B8720377 // ******************************************************************************** // // Name: RetCode nextValue(Float *pValue) // // Description: Returns the next value of the Gamma distribution. // // Output parameters: Float *pValue; //next number generated // // Returns: SCH_SUCCESS // SCH_ALLOCATION_ERROR // // ******************************************************************************** RetCode GammaGen::nextValue (Float *pValue) { //## begin GammaGen::nextValue%3739B8720377.body preserve=yes RetCode rc = SCH_SUCCESS; const Double e = exp(1); bool bGamma = false; Float a; Float b; Float d; Float exponent; Float factor; Float gamma; Float number1; Float number2; Float p; Float q; Float teta = 4.5; Float v; Float w; Float y; Float z; Double ey; Double ye; if ((alfa > 0) && (alfa <= 1)) { b = (Float) ((e + alfa) / e); do { // limits the value of number1 to: 0 <= number1 < 1 // otherwise it can occur a exception at log ((b-p)/alfa) do rc = getNextValue (&number1); while (number1 == 1.0f); if (rc == SCH_SUCCESS) { p = b * number1; if (p <= 1) { rc = getNextValue (&number1); if (rc == SCH_SUCCESS) { exponent = 1 / alfa; y = pow (p, exponent); ey = pow (e, -y); if (number1 <= ey) { gamma = y; bGamma = true; } } else { break; } } else { rc = getNextValue (&number1); if (rc == SCH_SUCCESS) { exponent = alfa-1; y = - log ((b-p)/alfa); ye = pow (y, exponent); if (number1 <= ye) { gamma = y; bGamma = true; } } else { break; } } } else { break; } } while (!bGamma); } else if (alfa > 1) { a = 1 / sqrt (2 * alfa - 1); b = alfa - log (4); q = alfa + 1 / a; d = 1 + log (teta); do { // limits the value of number1 to: 0 < number1 < 1 // otherwise it can occur a exception at log (number1 / (1 - number1)) do rc = getNextValue (&number1); while (number1 == 0.0f || number1 == 1.0f); if (rc == SCH_SUCCESS) { // limits the value of number2 to: 0 < number2 <= 1 // otherwise it can occur a exception at log (z) do rc = getNextValue (&number2); while (number2 == 0.0f); if (rc == SCH_SUCCESS) { v = a * log (number1 / (1 - number1)); y = alfa * pow(e, v); z = number1 * number1 * number2; w = b + q * v - y; factor = w + d - teta * z; if (factor >= 0) { gamma = y; bGamma = true; } else if (w >= log(z)) { gamma = y; bGamma = true; } } else { break; } } else { break; } } while (!bGamma); } *pValue = beta * gamma; return rc; //## end GammaGen::nextValue%3739B8720377.body }
void SequenceManager::signal() { if (g_globals->_sceneObjects->contains(&_sceneText)) _sceneText.hide(); bool continueFlag = true; while (continueFlag) { if (_sequenceOffset >=_sequenceData.size()) { // Reached the end of the sequence if (!_keepActive) remove(); break; } uint16 idx = static_cast<uint16>(getNextValue() - 32000); int16 v1, v2, v3; switch (idx) { case 0: // Stop sequence continueFlag = false; break; case 1: _sceneObject->animate(ANIM_MODE_1, NULL); break; case 2: _sceneObject->animate(ANIM_MODE_2, NULL); break; case 3: _sceneObject->animate(ANIM_MODE_3); break; case 4: v1 = getNextValue(); v2 = getNextValue(); _sceneObject->animate(ANIM_MODE_8, v1, v2 ? this : NULL); break; case 5: v1 = getNextValue(); v2 = getNextValue(); _sceneObject->animate(ANIM_MODE_7, v1, v2 ? this : NULL); break; case 6: v2 = getNextValue(); _sceneObject->animate(ANIM_MODE_5, v2 ? this : NULL); break; case 7: v2 = getNextValue(); _sceneObject->animate(ANIM_MODE_6, v2 ? this : NULL); break; case 8: v1 = getNextValue(); v3 = getNextValue(); v2 = getNextValue(); _sceneObject->animate(ANIM_MODE_4, v1, v3, v2 ? this : NULL); break; case 9: v1 = getNextValue(); v3 = getNextValue(); v2 = getNextValue(); g_globals->_sceneManager._scene->_sceneBounds.moveTo(v3, v2); g_globals->_sceneManager._scene->loadScene(v1); break; case 10: { int resNum= getNextValue(); int lineNum = getNextValue(); int color = getNextValue(); int xp = getNextValue(); int yp = getNextValue(); int width = getNextValue(); setMessage(resNum, lineNum, color, Common::Point(xp, yp), width); break; } case 11: v1 = getNextValue(); v2 = getNextValue(); setAction(globalManager(), v2 ? this : NULL, v1, _objectList[0], _objectList[1], _objectList[2], _objectList[3], NULL); break; case 12: v1 = getNextValue(); setDelay(v1); break; case 13: { v1 = getNextValue(); v3 = getNextValue(); v2 = getNextValue(); NpcMover *mover = new NpcMover(); Common::Point destPos(v1, v3); _sceneObject->addMover(mover, &destPos, v2 ? this : NULL); break; } case 14: v1 = getNextValue(); _sceneObject->_numFrames = v1; break; case 15: v1 = getNextValue(); _sceneObject->_moveRate = v1; break; case 16: v1 = getNextValue(); v2 = getNextValue(); _sceneObject->_moveDiff = Common::Point(v1, v2); break; case 17: _sceneObject->hide(); break; case 18: _sceneObject->show(); break; case 19: v1 = getNextValue(); _sceneObject->setVisage(v1); break; case 20: v1 = getNextValue(); _sceneObject->setStrip(v1); break; case 21: v1 = getNextValue(); _sceneObject->setFrame(v1); break; case 22: v1 = getNextValue(); _sceneObject->fixPriority(v1); break; case 23: v1 = getNextValue(); _sceneObject->changeZoom(v1); break; case 24: v1 = getNextValue(); v2 = getNextValue(); v3 = getNextValue(); _sceneObject->setPosition(Common::Point(v1, v2), v3); break; case 25: { int yStart = getNextValue(); int minPercent = getNextValue(); int yEnd = getNextValue(); int maxPercent = getNextValue(); g_globals->_sceneManager._scene->setZoomPercents(yStart, minPercent, yEnd, maxPercent); break; } case 26: v1 = getNextValue(); v2 = getNextValue(); _soundHandler.play(v1, v2 ? this : NULL, 127); break; case 27: { v1 = getNextValue(); v3 = getNextValue(); v2 = getNextValue(); PlayerMover *mover = new PlayerMover(); Common::Point destPos(v1, v3); _sceneObject->addMover(mover, &destPos, v2 ? this : NULL); break; } case 28: _objectIndex = getNextValue(); assert((_objectIndex >= 0) && (_objectIndex < 6)); _sceneObject = _objectList[_objectIndex]; assert(_sceneObject); break; case 29: _sceneObject->animate(ANIM_MODE_NONE); break; case 30: v1 = getNextValue(); g_globals->_scrollFollower = (v1 == -1) ? NULL : _objectList[v1]; break; case 31: _sceneObject->setObjectWrapper(new SceneObjectWrapper()); break; case 32: _sceneObject->setObjectWrapper(NULL); break; case 33: v1 = getNextValue(); if (_keepActive) setDelay(1); else { _sceneText.remove(); g_globals->_sceneManager._scene->_stripManager.start(v1, this); } break; case 34: { v1 = getNextValue(); v2 = getNextValue(); int objIndex1 = getNextValue() - 1; int objIndex2 = getNextValue() - 1; int objIndex3 = getNextValue() - 1; int objIndex4 = getNextValue() - 1; int objIndex5 = getNextValue() - 1; int objIndex6 = getNextValue() - 1; setAction(globalManager(), v2 ? this : NULL, v1, _objectList[objIndex1], _objectList[objIndex2], _objectList[objIndex3], _objectList[objIndex4], _objectList[objIndex5], _objectList[objIndex6], NULL); break; } /* Following indexes were introduced for Blue Force */ case 35: v1 = getNextValue(); _sceneObject->updateAngle(_objectList[v1]->_position); break; case 36: _sceneObject->animate(ANIM_MODE_9, NULL); break; case 37: v1 = getNextValue(); v2 = getNextValue(); if (_onCallback) _onCallback(v1, v2); break; case 38: { int resNum = getNextValue(); int lineNum = getNextValue(); int fontNum = getNextValue(); int color1 = getNextValue(); int color2 = getNextValue(); int color3 = getNextValue(); int xp = getNextValue(); int yp = getNextValue(); int width = getNextValue(); setMessage(resNum, lineNum, fontNum, color1, color2, color3, Common::Point(xp, yp), width); break; } default: error("SequenceManager::signal - Unknown action %d at offset %xh", idx, _sequenceOffset - 2); break; } } }
//## Operation: redefineAndNextValue%398ED12E004D // ******************************************************************************** // // Name: RetCode nextValue(Int *pValue) // // Description: Returns the next value of the Binomial distribution. // // Output parameters: Int *pValue; //next number generated // // Returns: SCH_SUCCESS // SCH_ALLOCATION_ERROR // // ******************************************************************************** RetCode BinomialGenBtpec::redefineAndNextValue (Int *pValue, Ulong n, Float pp) { //## begin BinomialGenBtpec::redefineAndNextValue%398ED12E004D.body preserve=yes Long ignbin,i,ix,ix1,k,m,mp,T1; Float al,alv,amaxp,c,f,f1,f2,ffm,fm,g,p,p1,p2,p3,p4,q,qn,r,u,v,w,w2,x,x1,x2,xl,xll,xlr,xm,xnp,xnpq,xr,ynorm,z,z2; RetCode rc = SCH_SUCCESS; //------------------------------------------------- // we assume that the values have changed for now //------------------------------------------------- //if(pp != psave) goto S10; //if(n != nsave) goto S20; //if(xnp < 30.0) goto S150; //goto S30; S10: /* *****SETUP, PERFORM ONLY WHEN PARAMETERS CHANGE */ psave = pp; p = (psave<1.0-psave) ? psave : 1.0-psave; q = 1.0-p; S20: xnp = n*p; nsave = n; if(xnp < 30.0) goto S140; ffm = xnp+p; m = ffm; fm = m; xnpq = xnp*q; p1 = (long) (2.195*sqrt(xnpq)-4.6*q)+0.5; xm = fm+0.5; xl = xm-p1; xr = xm+p1; c = 0.134+20.5/(15.3+fm); al = (ffm-xl)/(ffm-xl*p); xll = al*(1.0+0.5*al); al = (xr-ffm)/(xr*q); xlr = al*(1.0+0.5*al); p2 = p1*(1.0+c+c); p3 = p2+c/xll; p4 = p3+c/xlr; S30: /* *****GENERATE VARIATE */ rc = getNextValue (&u); rc = getNextValue (&v); u = u*p4; //u = ranf()*p4; //v = ranf(); /* TRIANGULAR REGION */ if(u > p1) goto S40; ix = xm-p1*v+u; goto S170; S40: /* PARALLELOGRAM REGION */ if(u > p2) goto S50; x = xl+(u-p1)/c; v = v*c+1.0-fabs(xm-x)/p1; if(v > 1.0 || v <= 0.0) goto S30; ix = x; goto S70; S50: /* LEFT TAIL */ if(u > p3) goto S60; ix = xl+log(v)/xll; if(ix < 0) goto S30; v *= ((u-p2)*xll); goto S70; S60: /* RIGHT TAIL */ ix = xr-log(v)/xlr; if(ix > n) goto S30; v *= ((u-p3)*xlr); S70: /* *****DETERMINE APPROPRIATE WAY TO PERFORM ACCEPT/REJECT TEST */ k = abs(ix-m); if(k > 20 && k < xnpq/2-1) goto S130; /* EXPLICIT EVALUATION */ f = 1.0; r = p/q; g = (n+1)*r; T1 = m-ix; if(T1 < 0) goto S80; else if(T1 == 0) goto S120; else goto S100; S80: mp = m+1; for(i=mp; i<=ix; i++) f *= (g/i-r); goto S120; S100: ix1 = ix+1; for(i=ix1; i<=m; i++) f /= (g/i-r); S120: if(v <= f) goto S170; goto S30; S130: /* SQUEEZING USING UPPER AND LOWER BOUNDS ON ALOG(F(X)) */ amaxp = k/xnpq*((k*(k/3.0+0.625)+0.1666666666666)/xnpq+0.5); ynorm = -(k*k/(2.0*xnpq)); alv = log(v); if(alv < ynorm-amaxp) goto S170; if(alv > ynorm+amaxp) goto S30; /* STIRLING'S FORMULA TO MACHINE ACCURACY FOR THE FINAL ACCEPTANCE/REJECTION TEST */ x1 = ix+1.0; f1 = fm+1.0; z = n+1.0-fm; w = n-ix+1.0; z2 = z*z; x2 = x1*x1; f2 = f1*f1; w2 = w*w; if(alv <= xm*log(f1/x1)+(n-m+0.5)*log(z/w)+(ix-m)*log(w*p/(x1*q))+(13860.0- (462.0-(132.0-(99.0-140.0/f2)/f2)/f2)/f2)/f1/166320.0+(13860.0-(462.0- (132.0-(99.0-140.0/z2)/z2)/z2)/z2)/z/166320.0+(13860.0-(462.0-(132.0- (99.0-140.0/x2)/x2)/x2)/x2)/x1/166320.0+(13860.0-(462.0-(132.0-(99.0 -140.0/w2)/w2)/w2)/w2)/w/166320.0) goto S170; goto S30; S140: /* INVERSE CDF LOGIC FOR MEAN LESS THAN 30 */ qn = pow(q,(double)n); r = p/q; g = r*(n+1); S150: ix = 0; f = qn; rc = getNextValue (&u); //u = ranf(); S160: if(u < f) goto S170; if(ix > 110) goto S150; u -= f; ix += 1; f *= (g/ix-r); goto S160; S170: if(psave > 0.5) ix = n-ix; ignbin = ix; *pValue = ignbin; return (SCH_SUCCESS); //## end BinomialGenBtpec::redefineAndNextValue%398ED12E004D.body }
Variant& StackMachine::evaluate(const VariableStore& store, const FunctionRegistry& functions) { reset(); for(const auto& instruction : _instructions) { switch(instruction._opCode) { case NOP: { break; } case PUSH: { _valueStack.emplace(instruction._value); break; } case PUSHVAR: { if(instruction._value.getType() != INT) { CSVSQLDB_THROW(StackMachineException, "expected an INT as variable index"); } int64_t index = instruction._value.asInt(); _valueStack.emplace(store[static_cast<size_t>(index)]); break; } case ADD: case SUB: case DIV: case MOD: case MUL: case EQ: case NEQ: case IS: case ISNOT: case GT: case GE: case LT: case LE: case AND: case OR: case CONCAT: { const Variant lhs(getNextValue()); Variant& rhs(getTopValue()); rhs = binaryOperation(mapOpCodeToBinaryOperationType(instruction._opCode), lhs, rhs); break; } case NOT: { Variant& rhs(getTopValue()); rhs = unaryOperation(OP_NOT, BOOLEAN, rhs); break; } case PLUS: { // this is a nop, as the value will not change, so just leave it on the stack break; } case MINUS: { Variant& rhs = getTopValue(); rhs = unaryOperation(OP_MINUS, rhs.getType(), rhs); break; } case BETWEEN: { const Variant lhs = getNextValue(); const Variant from = getNextValue(); Variant& to = getTopValue(); Variant result(BOOLEAN); if(not(lhs.isNull() || from.isNull() || to.isNull())) { if(binaryOperation(OP_GE, to, from).asBool()) { result = binaryOperation(OP_GE, lhs, from); if(result.asBool()) { result = binaryOperation(OP_LE, lhs, to); } } else { result = binaryOperation(OP_GE, lhs, to); if(result.asBool()) { result = binaryOperation(OP_LE, lhs, from); } } } to = result; break; } case FUNC: { if(instruction._value.getType() != STRING) { CSVSQLDB_THROW(StackMachineException, "expected a string as variable name"); } std::string funcname = instruction._value.asString(); Function::Ptr func = functions.getFunction(funcname); if(!func) { CSVSQLDB_THROW(StackMachineException, "function '" << funcname << "' not found"); } Variants parameter; size_t count = func->getParameterTypes().size(); for(const auto& param : func->getParameterTypes()) { Variant v = getNextValue(); if(param != v.getType()) { try { v = unaryOperation(OP_CAST, param, v); } catch(const std::exception&) { CSVSQLDB_THROW(StackMachineException, "calling function '" << funcname << "' with wrong parameter"); } } parameter.emplace(parameter.end(), v); --count; } if(count) { CSVSQLDB_THROW(StackMachineException, "too much parameters for function '" << funcname << "'"); } _valueStack.emplace(func->call(parameter)); break; } case CAST: { Variant& rhs = getTopValue(); rhs = unaryOperation(OP_CAST, instruction._value.getType(), rhs); break; } case IN: { size_t count = static_cast<size_t>(instruction._value.asInt()); const Variant lhs = getNextValue(); bool found(false); for(size_t n = 0; n < count; ++n) { Variant result = binaryOperation(OP_EQ, lhs, getNextValue()); if(result.asBool()) { found = true; ++n; for(; n < count; ++n) { // remove rest of the values from stack _valueStack.pop(); } break; } } if(found) { _valueStack.emplace(Variant(true)); } else { _valueStack.emplace(Variant(false)); } break; } case LIKE: { if(!instruction._r) { CSVSQLDB_THROW(StackMachineException, "expected a regexp in LIKE expression"); } Variant lhs = getTopValue(); if(lhs.getType() != STRING) { lhs = unaryOperation(OP_CAST, STRING, lhs); CSVSQLDB_THROW(StackMachineException, "can only do like operations on strings"); } if(instruction._r->match(lhs.asString())) { _valueStack.emplace(Variant(true)); } else { _valueStack.emplace(Variant(false)); } break; } } } return _valueStack.top(); }
PointSet::PointSet(const char* pointFileName,double flatteningFactor,double scaleFactor) { /* Open the point file: */ Misc::File pointFile(pointFileName,"rt"); /* Read the header line from the point file: */ int latIndex=-1; int lngIndex=-1; int radiusIndex=-1; enum RadiusMode { RADIUS,DEPTH,NEGDEPTH } radiusMode=RADIUS; int index=0; while(true) { char valueBuffer[40]; int terminator=getNextValue(pointFile,valueBuffer,sizeof(valueBuffer)); if(terminator=='\n') break; else if(terminator==EOF) Misc::throwStdErr("PointSet::PointSet: Early end of file in input file \"%s\"",pointFileName); else if(strcasecmp(valueBuffer,"Latitude")==0||strcasecmp(valueBuffer,"Lat")==0) latIndex=index; else if(strcasecmp(valueBuffer,"Longitude")==0||strcasecmp(valueBuffer,"Long")==0||strcasecmp(valueBuffer,"Lon")==0) lngIndex=index; else if(strcasecmp(valueBuffer,"Radius")==0) { radiusIndex=index; radiusMode=RADIUS; } else if(strcasecmp(valueBuffer,"Depth")==0) { radiusIndex=index; radiusMode=DEPTH; } else if(strcasecmp(valueBuffer,"Negative Depth")==0||strcasecmp(valueBuffer,"Neg Depth")==0||strcasecmp(valueBuffer,"NegDepth")==0) { radiusIndex=index; radiusMode=NEGDEPTH; } ++index; } /* Check if all required portions have been detected: */ if(latIndex<0||lngIndex<0||radiusIndex<0) Misc::throwStdErr("PointSet::PointSet: Missing point components in input file \"%s\"",pointFileName); /* Read all point positions from the point file: */ bool finished=false; while(!finished) { /* Read the next line from the input file: */ int index=0; float sphericalCoordinates[3]={0.0f,0.0f,0.0f}; // Initialization just to shut up gcc int parsedComponentsMask=0x0; while(true) { char valueBuffer[40]; int terminator=getNextValue(pointFile,valueBuffer,sizeof(valueBuffer)); if(terminator=='\n') break; else if(terminator==EOF) { finished=true; break; } else if(index==latIndex) { sphericalCoordinates[0]=Math::rad(float(atof(valueBuffer))); parsedComponentsMask|=0x1; } else if(index==lngIndex) { sphericalCoordinates[1]=Math::rad(float(atof(valueBuffer))); parsedComponentsMask|=0x2; } else if(index==radiusIndex) { sphericalCoordinates[2]=float(atof(valueBuffer)); parsedComponentsMask|=0x4; } ++index; } /* Check if a complete set of coordinates has been parsed: */ if(parsedComponentsMask==0x7&&!isnan(sphericalCoordinates[2])) { /* Convert the read spherical coordinates to Cartesian coordinates: */ Vertex p; p.position=Vertex::Position(0,0,0); // To shut up gcc switch(radiusMode) { case RADIUS: calcRadiusPos(sphericalCoordinates[0],sphericalCoordinates[1],sphericalCoordinates[2]*1000.0f,scaleFactor,p.position.getXyzw()); break; case DEPTH: calcDepthPos(sphericalCoordinates[0],sphericalCoordinates[1],sphericalCoordinates[2]*1000.0f,flatteningFactor,scaleFactor,p.position.getXyzw()); break; case NEGDEPTH: calcDepthPos(sphericalCoordinates[0],sphericalCoordinates[1],-sphericalCoordinates[2]*1000.0f,flatteningFactor,scaleFactor,p.position.getXyzw()); break; } /* Append the point to the point set: */ points.push_back(p); } } std::cout<<points.size()<<" points parsed from "<<pointFileName<<std::endl; }
template<typename T> Scan &operator()(T &t) { std::istringstream istr( getNextValue() ); istr >> t; return *this; }
void Engine::guessNumber(int _len) { init(_len); guessedByComputer=getNextValue(); }