void SnakeList::goTo(int pos){ if(pos <= 1){ goToNext(); return; } if(pos == conteo - 1){ goToLast(); return; } goToFirst(); for(int i = 1; i < pos; i++){ if(current->next != 0) goToNext(); } }
int ModelManager::snapshotsFromString(const std::string& src){ unsigned r = src.size(); unsigned p=0; if(!goToNext(p, '{' , src)) return r; ++p; do{ p += snapshotFromString(src.substr(p)); if(!goToNext(p, ',', src)) return r; ++p; } while(p < src.size()); return p; }
SnakePart* SnakeList::take(int pos){ SnakePart* sp = 0; goToFirst(); for(int i = 1; i < pos; i++) goToNext(); if(pos != 1 && pos != conteo){ current->prev->next = current->next; current->next->prev = current->prev; }else if(pos == conteo){ first = current->next; if(current->next != 0) current->next->prev = 0; }else if(pos == conteo){ last = current->prev; current->prev->next = 0; } if(pos > 0 && pos <= conteo){ conteo--; sp = current->content; delete current; } return sp; }
char *Tokenizer::nextAfterToken(const char *token, BOOLFUNC isAlpha){ while (goToNext(isAlpha)){ if (strncmp(str + start, token, end - start) == 0){ return next(); } } return NULL; }
int ModelManager::snapshotFromString(const std::string& src){ //printf("%s\n", src.c_str()); unsigned r = src.size(); unsigned p=0, p2=0; // look for table name if(!goToNextPrintablePast(p, '[' , src)) return r; if(!goToNextPrintablePast(p, '\"', src)) return r; if(!goToNext(p2=p, '\"', src)) return r; std::string name = src.substr(p, p2-p); //printf("%s\n", name.c_str()); p = p2+1; if(!goToNextPrintablePast(p, ']' , src)) return r; if(!goToNextPrintablePast(p, '=' , src)) return r; //printf("%s\n", src.substr(p).c_str()); // retrieve key-value pairs struct It : KeyValueParser { It(Snapshot& vs, NamedModels& vm): s(vs), m(vm){} void onKeyValue(const std::string& key, const std::string& val){ //printf("%s = %s\n", key.c_str(), val.c_str()); // Only convert value string if main state contains key // with same name. NamedModels::const_iterator it = m.find(key); if(it != m.end()){ Data& ds = s[key]; //ds.print(); // Set size of snapshot Data according to application Model if(true){ Data temp; const Data& dm = it->second->getData(temp); ds.resize(dm.type(), dm.shape(), dm.maxDim()); ds.fromToken(val); //ds.print(); } // Or, resize application model and snapshot data according to // number of elements counted in string. /*else { int N = numElemsToken(val); ds.resize(dm.type(), N); ds.fromToken(val); }*/ } } Snapshot& s; NamedModels& m; } it(mSnapshots[name], mState); p += it(src.substr(p)); return p; }
void goToNext(Node *ptr){ if ((ptr->next)->next != NULL) { goToNext(ptr->next); } else { newHead = ptr->next; newHead->next = ptr; } (ptr->next)->next = ptr; }
char *Tokenizer::next(BOOLFUNC isAlpha){ if (goToNext(isAlpha)){ unsigned int size = end - start; char *buffer = getBuffer(size + 1); strncpy(buffer, str + start, size); buffer[size] = '\0'; return buffer; } return NULL; }
Node* Reverse(Node *head) { if (head != NULL && head->next != NULL ) { struct Node *current = head; goToNext(current); head->next = NULL; return newHead; } else { return head; } }
void Player::toBoat(Display* display) { if(!((getCurrentTile(display) == display->getWaterHandle(1)) || getCurrentTile(display) == display->getWaterHandle(2))) { shipState = false; } if(keyboard->getState(SDLK_z)) { if((getNextTile(display) == display->getWaterHandle(1)) || (getNextTile(display) == display->getWaterHandle(2))) { shipState = true; goToNext(); } } }
/****************************************************************************** Function Specifications: insertAfterCursor =============================================================================== Preconditions: - list is not full Postconditions: - a new node containing the newDataItem is created and placed after cursor - returns true if successful Algorithm: - node is created and linked Exceptional/Error Conditions: - list full exception handled (returns false) */ bool LinkedList::insertAfterCursor ( int newDataItem // input: data to be placed in list ) { ListNode* tmpNode = NULL; // if full return false if( isFull() ) { return false; } // if empty create and populate head node if( isEmpty() ) { head = new ListNode( newDataItem, NULL ); cursor = head; } // next node ptr is null else if( cursor->next == NULL ) { cursor->next = new ListNode( newDataItem, NULL ); goToNext(); } // next node ptr contains an object else if (cursor->next != NULL ) { tmpNode = cursor->next; cursor->next = new ListNode( newDataItem, tmpNode ); tmpNode = NULL; goToNext(); } size++; return true; }
SnakePart* SnakeList::at(int pos){ qDebug() << "in the at() method"; if(isEmpty()){ qDebug() << "it was empty"; return 0; } qDebug() << "it was NOT empty"; if( (pos > count()) || (pos <= 0)) return 0; else{ goToFirst(); for(int i = 1; i < pos; i++) goToNext(); return current->content; } }
/****************************************************************************** Function Specifications: goToEnd =============================================================================== Preconditions: - list is not empty Postconditions: - brings the cursor to the end of the list - return true if successful Algorithm: - uses existing goToNext function Exceptional/Error Conditions: - list is empty exception (returns false) */ bool LinkedList::goToEnd() { bool flag = true; // if list is empty return false if( isEmpty() ) { return false; } // go to end and return true while( flag ) { flag = goToNext(); } return true; }
void Cutscene::update(){ Scene* currentScene = mEnviroments[mCurrentEnviroment].first[mCurrentScene]; if(!currentScene->isStarted()){ if(!currentScene->fadeIn()){ currentScene->play(); } } if(currentScene->isCompleted()){ if(!currentScene->fadeOut()){ goToNext(); } } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)){ StateManager::getInst().popState(); } }
/****************************************************************************** Function Specifications: isAssigned =============================================================================== Preconditions: - none expected Postconditions: - other is copied into this list, behaves like assignment operator Algorithm: - iterative node copying Exceptional/Error Conditions: - none expected or handled */ LinkedList& LinkedList::isAssigned ( const LinkedList& other // input: list you want assigned ) { ListNode* otherCurs; // if assigned to itself, return itself if( this == &other ) { return *this; } // clear out this list clear(); // begin copying capacity = other.capacity; if( other.isEmpty() ) { return *this; } otherCurs = other.head; do { insertAfterCursor( otherCurs->dataItem ); goToNext(); otherCurs = otherCurs->next; } while( otherCurs != NULL ); goToBeginning(); return *this; }
/****************************************************************************** Function Specifications: replaceAfterCursor =============================================================================== Preconditions: - list is not empty - cursor not at end of list Postconditions: - the data in the node after the cursor is replaced with newDataItem - true is returned if successful Algorithm: - cursor movements are used and assignments manipulate data Exceptional/Error Conditions: - list empty exception handled (returns false) - cursor at end exception handled (returns false) */ bool LinkedList::replaceAfterCursor ( int newDataItem // input: data to replace existing data ) { // if empty if( isEmpty() ) { return false; } // if at end of list else if( cursor->next == NULL ) { return false; } // normal operation else { goToNext(); replaceAtCursor( newDataItem ); return true; } }
/****************************************************************************** Function Specifications: removeAtCursor =============================================================================== Preconditions: - list is not empty Postconditions: - the node at the cursor is remove and the following nodes are shifted down - true is returned if successful Algorithm: - node is deleted and adjacent nodes linked Exceptional/Error Conditions: - list empty exception (returns false) */ bool LinkedList::removeAtCursor ( int &dataVal // output: data the removed node contained ) { ListNode* tmpNode; // if list is empty if( isEmpty() ) { return false; } // if current object is last object in list else if( ( cursor == head ) && ( cursor->next == NULL ) ) { // remove node and initialize list delete cursor; head = cursor = NULL; } // if cursor is at end of list else if( cursor->next == NULL ) { // shift cursor tmpNode = cursor; goToPrior(); // remove node delete tmpNode; cursor->next = NULL; tmpNode = NULL; } // if cursor is at beginning of list else if( cursor == head ) { // head head and cursor tmpNode = cursor; goToNext(); head = cursor; // remove node delete tmpNode; tmpNode = NULL; } // if cursor is at middle of list else if( cursor->next != NULL ) { // bridge soon-to-be gap tmpNode = cursor; goToPrior(); cursor->next = tmpNode->next; // remove node delete tmpNode; tmpNode = NULL; // adjust "index" goToNext(); } size--; return true; }
void MainWindow::on_pushButton_clicked() { QString masterIP = "123.123.231.132"; goToNext(masterIP); }