static const char *getArrayItem(PJsonObject object,const char *jsonString){ PJsonObject value=createNewItem(); object->value_array=value; while(jsonString&&*jsonString!=']'){ object->size++; jsonString=getObject(jsonString,value); if(*jsonString==','){ jsonString++; value->value_array=createNewItem(); value=value->value_array; } } return jsonString; }
void GameLayer::moveForward() { disable(); items[ITEM_NUM] = createNewItem(); blocks[ITEM_NUM] = createNewBlock(); items[ITEM_NUM]->setPosition(items[ITEM_NUM - 1]->getPosition()); blocks[ITEM_NUM]->setPosition(blocks[ITEM_NUM - 1]->getPosition()); /* 向下移动的动画 */ for (unsigned int i = ITEM_NUM - 1; i > 0; i--) { items[i]->runAction( CCSequence::createWithTwoActions( CCMoveTo::create(0.1f, items[i - 1]->getPosition()), CCCallFunc::create(this, callfunc_selector(GameLayer::enable)))); blocks[i]->runAction( CCMoveTo::create(0.1f, blocks[i - 1]->getPosition())); } /* 重新设置数组存储顺序和前后遮挡排列顺序 */ items[0]->setZOrder(ITEM_NUM + 1); for (unsigned int i = 0; i < ITEM_NUM; i++) { items[i] = items[i + 1]; items[i]->setZOrder(ITEM_NUM - i); blocks[i] = blocks[i + 1]; blocks[i]->setZOrder(ITEM_NUM - i); } }
PJsonObject jsonObject(const char *jsonString){ PJsonObject object=createNewItem(); string_start=jsonString; object_start=object; jsonParse(object,jsonString); return object; }
bool TagListWidget::add( QString tag ) { //FIXME avoid duplicates createNewItem( tag ); m_newTags += tag; return true; }
void GameLayer::initPosition() { for (unsigned int i = 0; i < ITEM_NUM; i++) { items[i] = createNewItem(); items[i]->setZOrder(ITEM_NUM - i); items[i]->setPosition(ccpp(0, (-0.38 + 0.11 * i))); blocks[i] = createNewBlock(); blocks[i]->setZOrder(ITEM_NUM - i); blocks[i]->setPosition(items[i]->getPosition() + ccpp(0, -0.02)); } }
void TagListWidget::onTagsRequestFinished() { QNetworkReply* r = (QNetworkReply*)sender(); QMap<int, QString> tags = Tag::list( r ); QMapIterator<int, QString> i( tags ); while (i.hasNext()) { QTreeWidgetItem *entry = createNewItem( i.next().value() ); // I couldn't make it sort properly otherwise, even the QVariant methods wouldn't work! entry->setText( 1, QString::number( 10 * 1000 + i.key() ) ); } m_currentReply = 0; }
static const char *getItem(PJsonObject object,const char *jsonString){ if(*jsonString=='\"'){ jsonString++; jsonString=getKey(object,jsonString); if(*jsonString==':'){ jsonString++; jsonString=getObject(jsonString,object); if(*jsonString==','){ jsonString++; object->next=createNewItem(); jsonString=getItem(object->next,jsonString); } }else{ //print error message that this is no ':' showErrorMessage(jsonString,NO_COLON); } }else{ //print error message that string is not started with '"'. showErrorMessage(jsonString,NO_QUOTATION); } return jsonString; }
bool IngridientWindow::buttonBoxAcceptedNewMode(void) { bool isFood = ui->radioButton_1->isChecked(); Food* newFood = nullptr; Item* newItem = nullptr; try { if ( isFood ) { newFood = createNewFood(); } else { newItem = createNewItem(); } } catch ( IngridientWindowException e ) { QMessageBox msgBox; PRINT_ERR("Wrong value provided"); msgBox.setText("Wrong value provided"); msgBox.exec(); return false; } catch ( EngineException e ) { QMessageBox msgBox; PRINT_ERR("Engine calculation error"); msgBox.setText("Engine calculation error"); msgBox.exec(); return false; } if ( isFood ) { emit foodObjectReady(newFood); } else { emit itemObjectReady(newItem); } return true; }
static const char *getObject(const char *jsonString,PJsonObject object){ int size=0; const char *tmp=jsonString; if(*jsonString=='\"'){ object->type=STRING; tmp++; jsonString++; while(*tmp!='\"'&&tmp){ size++; tmp++; } size++; if(size==1){ //print error message that there is no key. showErrorMessage(jsonString,NO_VALUE); object->value_string=NULL; }else{ char*value=(char*)malloc(size*sizeof(char)); object->value_string=value; while(*jsonString!='\"'&&jsonString){ *value=*jsonString; value++; jsonString++; } jsonString++; *value++='\0'; } }else if(strncmp(jsonString,"true",4)==0||strncmp(jsonString,"false",5)==0){ object->type=BOOL; if(strncmp(jsonString,"true",4)==0){ object->value_boolean=true; jsonString+=4; }else{ object->value_boolean=false; jsonString+=5; } }else if(*jsonString=='{'){ object->type=OBJECT; object->value_child=createNewItem(); jsonString=jsonParse(object->value_child,jsonString); }else if(*jsonString=='['){ object->type=ARRAY; jsonString=jsonParse(object,jsonString); }else{ while((*tmp!=','&&*tmp!=']'&&*tmp!='}')&&tmp){ size++; tmp++; } size++; if(size==1){ //print error message that there is no key. showErrorMessage(jsonString,NO_VALUE); }else{ char *value=(char*)malloc(size*sizeof(char)); char *t=value; while(size>1){ *value=*jsonString; value++; jsonString++; size--; } *value++='\0'; if(isInteger(t)==1){ object->type=INTEGER; printf("%s",t); object->value_integer=atoi(t); }else{ object->type=DOUBLE; object->value_double=strtod(t,NULL); } } } return jsonString; }