void testCalculate() { char str[64]; int len=0, i, k=0; DParam dp; char strbuff[256] = "f(x)=-x^2"; Function *f = NULL; double val[1]; dp.values = val; f = (Function*)malloc(sizeof(Function)); f->prefix = NULL; f->domain = NULL; f->criterias = NULL; f->str = NULL; f->len = 0; f->variableNode = NULL; f->numVarNode = 0; f->valLen = 0; //printf("Input function: "); //scanf("%s", &strbuff); len = strlen(strbuff); parseFunction(strbuff, len, f); if(getErrorCode() != NMATH_NO_ERROR) { printError(getErrorColumn(), getErrorCode()); releaseFunct(f); free(f); return; } if( f->valLen==0 ) { printf("This expression is not a function due to variables not determined.\n"); } dp.error = NMATH_NO_ERROR; dp.t = f->prefix->list[0]; dp.variables[0] = 'x'; dp.values[0] = 2; //reduce_t(&dp); calc_t(&dp); if(dp.error == NMATH_NO_ERROR) { k = 0; printNMAST(dp.t, 0); printf("\n"); toString(dp.t, str, &k, 64); f->prefix->list[0] = dp.t; printf("Calculating result: %lf\n", dp.retv); } //release token list releaseFunct(f); clearPool(); free(f); }
void BulletPool::init(int capacity, cocos2d::Node* parent) { if (getAvailableItemCount() > 0) clearPool(); mParent = parent; initWithCapacity(capacity); }
void SpritePool::init(int capacity, cocos2d::SpriteFrame* spriteFrame, cocos2d::Node* parent) { if (getAvailableItemCount() > 0) clearPool(); mSpriteFrame = spriteFrame; mParent = parent; initWithCapacity(capacity); }
int testDerivative() { DParam d; int error; double vars[] = {4, 1}; double ret; char dstr[64]; int l = 0; Function *f; f = (Function*)malloc(sizeof(Function)); f->prefix = NULL; f->domain = NULL; f->criterias = NULL; f->str = NULL; f->len = 0; f->variableNode = NULL; f->numVarNode = 0; f->valLen = 0; printf("Input function: "); scanf("%s", &dstr); l = strlen(dstr); parseFunction(dstr, l, f); if(getErrorCode() != NMATH_NO_ERROR) { printError(getErrorColumn(), getErrorCode()); releaseFunct(f); free(f); return getErrorCode(); } if( f->valLen==0 ) { printf("This expression is not a function due to variables not determined.\n"); } d.t = f->prefix->list[0]; d.error = 0; d.returnValue = NULL; d.variables[0] = 'x'; derivative(&d); toString(d.returnValue, dstr, &l, 64); printf("f' = %s\n", dstr); clearTree(&(d.returnValue)); releaseFunct(f); clearPool(); free(f); return 0; }
void GenePool::randomize (int count) { clearPool(); for (int i = 0; i < count; i++) { BreadNoteCluster *elist = new BreadNoteCluster(generation_*windowSize_, windowSize_, pitchMin_, pitchMax_, dynamicMin_, dynamicMax_); elist->createRandomEvents(eventsPerGroup_); pool_.push_back(elist); } }
void ObjectPool::init(int capacity, Object* sample, cocos2d::Node* parent) { if (getAvailableItemCount() > 0) clearPool(); mParent = parent; mSample = sample; mSample->setVisible(false); mSample->pause(); mSample->setPosition(-10, -10); mParent->addChild(mSample); //TODO: enable retain, and implement release // mSample->retain(); initWithCapacity(capacity); }
GenePool::~GenePool (void) { clearPool(); }
DbConnectionPool::~DbConnectionPool() { clearPool(); }
void jniJLexerGetSpace() { Function *f; DParam dp; TokenList tokens; char outString[256]; char strbuff[256] = "f(x)=-x^2"; int i, j, textLen, vertexCount, l=0; int tokenNum = 9; float bdarr[2] = {-2, 2}; float epsilon = 0.2; ListFData *spaces; float temp; int k, r; f = (Function*)malloc(sizeof(Function)); f->prefix = NULL; f->domain = NULL; f->criterias = NULL; f->str = NULL; f->len = 0; f->variableNode = NULL; f->numVarNode = 0; f->valLen = 0; tokens.loggedSize = tokenNum; tokens.list = (Token*)malloc(sizeof(Token) * tokens.loggedSize); tokens.list[0].type = 19; tokens.list[0].column = 0; tokens.list[0].priority = 0; tokens.list[0].text[0]='f'; tokens.list[0].textLength = 1; tokens.list[1].type = 11; tokens.list[1].column = 1; tokens.list[1].priority = 0; tokens.list[1].text[0]='('; tokens.list[1].textLength = 1; tokens.list[2].type = 19; tokens.list[2].column = 2; tokens.list[2].priority = 0; tokens.list[2].text[0]='x'; tokens.list[2].textLength = 1; tokens.list[3].type = 12; tokens.list[3].column = 3; tokens.list[3].priority = 0; tokens.list[3].text[0]=')'; tokens.list[3].textLength = 1; tokens.list[4].type = 10; tokens.list[4].column = 4; tokens.list[4].priority = 0; tokens.list[4].text[0]='='; tokens.list[4].textLength = 1; tokens.list[5].type = 22; tokens.list[5].column = 5; tokens.list[5].priority = 4; tokens.list[5].text[0]='-'; tokens.list[5].textLength = 1; tokens.list[6].type = 19; tokens.list[6].column = 6; tokens.list[6].priority = 0; tokens.list[6].text[0]='x'; tokens.list[6].textLength = 1; tokens.list[7].type = 25; tokens.list[7].column = 7; tokens.list[7].priority = 6; tokens.list[7].text[0]='^'; tokens.list[7].textLength = 1; tokens.list[8].type = 18; tokens.list[8].column = 8; tokens.list[8].priority = 0; tokens.list[8].text[0]='2'; tokens.list[8].textLength = 1; tokens.size = tokenNum; parseFunctionExpression(&tokens, f); if( getErrorCode() == NMATH_NO_ERROR ) { spaces = getSpaces(f, bdarr, f->valLen * 2, epsilon); if(spaces != NULL) { for(i=0; i<spaces->size; i++) { for(j=0; j<spaces->list[i]->dataSize; j++) { printf("%lf ", (spaces->list[i]->data[j])); } } free(spaces->list[0]->data); free(spaces->list[0]->rowInfo); free(spaces->list[0]); free(spaces->list); free(spaces); } } free(tokens.list); releaseFunct(f); clearPool(); free(f); }
int testGetSpaces() { int cmd, k, numOfV=0, i, j, vcount; float bd[]={-2, 2, -2, 2}; float eps = 0.2f; ListFData *data; FILE *file; int *indice; int l, indiceSize = 0, indiceLoggedSize; char strbuff[256] = "f(x)=sin(x)"; Function *f = NULL; //printf("Enter function: "); //fflush(stdin); //fgets(strbuff, 256, stdin); //scanf("%s", &strbuff); f = (Function*)malloc(sizeof(Function)); f->prefix = NULL; f->domain = NULL; f->criterias = NULL; f->str = NULL; f->len = 0; f->variableNode = NULL; f->numVarNode = 0; f->valLen = 0; printf("Input function: "); scanf("%s", &strbuff); l = strlen(strbuff); parseFunction(strbuff, l, f); if(getErrorCode() != NMATH_NO_ERROR) { printError(getErrorColumn(), getErrorCode()); releaseFunct(f); free(f); return getErrorCode(); } if( f->valLen==0 ) { printf("This expression is not a function due to variables not determined.\n"); } printf("The range for each variable is [-2, 2]\n"); printf("The epsilon = %lf \n", eps); printf("Do you want to change these values? Press 1 and Enter to change otherwise you will use the default\n"); scanf("%d", &cmd); if(cmd == 1){ printf("Enter the range for each variable, use space as delimiter: "); fflush(stdin); //fgets(strbuff, 256, stdin); scanf("%s", &strbuff); printf("Enter epsilon: "); scanf("%lf", &eps); // parseRange(strbuff, strlen(strbuff), bd, &numOfV); } printf("\n"); data = getSpaces(f, bd, f->valLen * 2, eps); if(data != NULL) { file = fopen("../data.txt", "w+"); for(i=0; i<data->size; i++){ vcount = data->list[i]->dataSize/data->list[i]->dimension; printf("Mesh %d, row count: %d number of vertex: %d\n", i, data->list[i]->rowCount, vcount); fprintf(file, "number of vertex = %d\n", vcount ); for(j=0; j<vcount; j++){ fprintf(file, "%lf \t %lf \t %lf\n", data->list[i]->data[j*3], data->list[i]->data[j*3+1], data->list[i]->data[j*3+2]); } indice = buildIndicesForGLLINEs(vcount, data->list[i]->rowInfo, data->list[i]->rowCount, &indiceSize, &indiceLoggedSize); if(indice != NULL) { cmd = 0; for(j=0; j<data->list[i]->rowCount; j++) { fprintf(file, "\n "); for(k=0; k<data->list[i]->rowInfo[j]; k++) fprintf(file, "%d \t ", cmd++); } fprintf(file, "\nIndices length: %d \n", indiceSize); k = indiceSize/20; for(j=0; j<indiceSize; j++) { fprintf(file, "\t %d", indice[j] ); if(j>0 && (j%k==0)) fprintf(file, "\n"); } free(indice); } free(data->list[i]->data); free(data->list[i]->rowInfo); free(data->list[i]); #ifdef DEBUG descNumberOfDynamicObjectBy(3); #endif } fclose(file); free(data->list); free(data); #ifdef DEBUG descNumberOfDynamicObjectBy(2); #endif } releaseFunct(f); clearPool(); free(f); return 0; }