예제 #1
0
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();
    }
}
예제 #2
0
파일: glv_model.cpp 프로젝트: eranws/GLV
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;
}
예제 #3
0
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;
}
예제 #4
0
char *Tokenizer::nextAfterToken(const char *token, BOOLFUNC isAlpha){
	while (goToNext(isAlpha)){
		if (strncmp(str + start, token, end - start) == 0){
			return next();
		}
	}

	return NULL;
}
예제 #5
0
파일: glv_model.cpp 프로젝트: eranws/GLV
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;
}
예제 #6
0
void goToNext(Node *ptr){
  if ((ptr->next)->next != NULL) {
    goToNext(ptr->next);
  } else {
      newHead = ptr->next;
      newHead->next = ptr;
  }
  (ptr->next)->next = ptr;
}
예제 #7
0
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;
}
예제 #8
0
Node* Reverse(Node *head) {
  if (head != NULL && head->next != NULL ) {
    struct Node *current = head;
    goToNext(current);
    head->next = NULL;
    return newHead;
  } else {
      return head;
  }
}
예제 #9
0
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();
		}
	}
}
예제 #10
0
/******************************************************************************
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;
}
예제 #11
0
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;
    }
}
예제 #12
0
/******************************************************************************
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;
}
예제 #13
0
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();
	}
}
예제 #14
0
/******************************************************************************
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;
}
예제 #15
0
/******************************************************************************
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;
    }
}
예제 #16
0
/******************************************************************************
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;
}
예제 #17
0
void MainWindow::on_pushButton_clicked()
{
    QString masterIP = "123.123.231.132";
    goToNext(masterIP);
}