예제 #1
0
ChainNarratorNodeIterator & ChainNarratorNodeIterator::operator++() //TODO: note this is recursive and as wanted
{
	assert(getChainPrimPtr()->isNarrator());
	if (!isLast())
		++(*(QList<ChainPrim*>::iterator *)this);
	else
	{
		//TODO:check how to transform this to NULL else will remain as is
		return nullChainNarratorNodeIterator;
	}
	while (!getChainPrimPtr()->isNarrator())
		++(*(QList<ChainPrim*>::iterator *)this);
	return *this;//check if this calls operator *() or not
}
예제 #2
0
파일: polynomial.c 프로젝트: theme/dsaa
void delNode( int X, Poly L ){
	Position b, p, n;
	b = findPreviousNode( X, L );
	if( !isLast( b, L ) && b->next->exp != X){
		p = b->next;
                n = p->next;
                
		b->next = n;
                if ( NULL != n )
                        n->prev = b;
                
		free(p);
	}
}
예제 #3
0
void FilterBar::filter(QString filter){
    if (t!=FILTER) filters.clear();
    if (filters.isEmpty()){
        filters.push_back(history[index]);
        filters.push_back(filter);
        t=FILTER;

    }
    else {
        filters.push_back(filter);
    }
    this->update();
        emit isFirst(!false);
        emit isLast(!true);
}
예제 #4
0
Position findPrevious(ElementType x, List l)
{
	Position p = NULL;

	///< 保证列表不为空
	if (!isEmpty(l))
	{
		p = l;
		while (NULL != p->Next && x != p->Next->Element)
			p = p->Next;
		/// p为l最后一个位置,标明l中不存在元素x;
		if (isLast(p, l))
			p = NULL;
	}
	return p;
}
예제 #5
0
Stub* StubContainerImpl::getStub() const
{
    ConstIterator iter = getCurrentStub();
    if(iter == stubs.end())
    {
       return 0;
    }

    if((*iter)->isCompleted() && !isLast())
    {
       iter++;
       index++;
    }

    return (*iter);
}
예제 #6
0
파일: polynomial.c 프로젝트: theme/dsaa
void swapNext(Position p, Poly l ){
        Position b, n, nn;
        if (isLast(p,l))
                return;

        n = p->next;
        nn = n->next;
        b = p->prev;

        b->next = n;
        n->prev = b;
        n->next = p;
        p->prev = n;
        p->next = nn;
        if (NULL != nn)
                nn->prev = p;
}
예제 #7
0
파일: sgd.cpp 프로젝트: gpascualg/Latte
	void SGD<DType>::forward()
	{
		std::vector<Layer::FinalizedLayer<DType>> pending = _layers;

		if (_orderedLayers.empty())
		{
			// TODO: Precompute this
			while (!pending.empty())
			{
				for (std::size_t i = 0; i < pending.size(); ++i)
				{
					auto layer = pending[i];

					if (layer->canBeForwarded())
					{
						// Remove from pending
						pending.erase(pending.begin() + i);

						// Add to ordered list
						_orderedLayers.push_back(layer);

						// Forward layer
						layer->forward();

						// If last, add it
						if (layer->isLast())
						{
							_lastLayers.push_back(layer);
						}

						break;	
					}
				}
			}
		}
		else
		{
			for (auto layer : _orderedLayers)
			{
				layer->forward();
			}
		}
	}
예제 #8
0
 /* {{{ MySQL_ArtResultSet::next() -I- */
 bool
 MySQL_ArtResultSet::next()
 {
     CPP_ENTER("MySQL_ArtResultSet::next");
     checkValid();
     bool ret = false;
     if (isLast()) {
         afterLast();
     }
     else if (row_position == 0) {
         first();
         ret = true;
     }
     else if (row_position > 0 && row_position < num_rows) {
         ++current_record;
         ++row_position;
         ret = true;
     }
     CPP_INFO_FMT("row_position=%llu num_rows=%llu", row_position, num_rows);
     return ret;
 }
예제 #9
0
ChainNarratorNodeIterator & ChainNarratorNodeIterator::nearestNarratorInChain(bool next)
{
	if (getChainPrim().isNarrator())
		return *this;
	else
	{
		if (next)
		{
			if (!isLast())
				++(*this);
			else
				return nullChainNarratorNodeIterator;
		}
		else
		{
			if (!isFirst())
				--(*this);
			else
				return nullChainNarratorNodeIterator;
		}
		return nearestNarratorInChain(next);
	}
}
예제 #10
0
static void formatList( OUTPUTFORMATTER* out, int aNestLevel, int aCtl, CPTREE& aTree )
    throw( IO_ERROR )
{
    for( CITER it = aTree.begin();  it != aTree.end();  ++it )
    {
        // Processing a tree which was read in with xml_parser?
        if( it->first == "<xmlattr>" )
        {
            formatList( out, aNestLevel, aCtl | CTL_IN_ATTRS, it->second );
            continue;
        }

        int ctl = 0;

#if defined(DEBUG)
        if( it->first == "field" )
        {
            int breakhere = 1;
            (void) breakhere;
        }
#endif

        if( isLast( aTree, it ) )   // is "it" the last one?
        {
            //if( !( aCtl & CTL_IN_ATTRS ) )
                ctl = CTL_OMIT_NL;
        }
        else if( isAtom( next( it )->second ) )
        {
            /* if( !( aCtl & CTL_IN_ATTRS ) ) */
                ctl = CTL_OMIT_NL;
        }

        formatNode( out, aNestLevel+1, ctl, it->first, it->second );
    }
}
예제 #11
0
/** handle the results of the TopDown operator
  * pid ==  0 -> no operator or node have no holistic operator
  * pid == -1 -> can't start process
  * never call for "root" node (this is not root node)
  * this can be "last" node
  */
int INode::evalTopDown(int pid)
{
#ifdef DEBUGMSG
  qDebug("#*  INode::evalTopDown(%s)(%p): pid=%d Start\n",
         (const char *) name(), this, pid);
#endif
  CHECK_PTR(sNode_);
//Hier Absturz weil parent = 0
  CHECK_PTR(parent());
  INode* parent=INode::parent();
  if (pid <= 0) {
#ifdef DEBUGMSG
    qDebug
      ("#  (ERROR -1/0) evalTopDown: can't start process \n  try it structural\n");
#endif
#warning Without Dummy TopDown nothing works
    if (!isLast() && !truncation())
      childTopDown();           //do it structural
    else if (isLast()) {                      //is last node
      status(MI);
      execState(BU);
      parent->childUnlink(this);      //!remove this temporary INode
      parent->decrementCount();
      return 0;
    } else { //is trash
      status(TRASH);
      execState(BU);
      parent->childUnlink(this);      //!remove this temporary INode
      parent->decrementCount();
      return 0;
    }
  }

  if (sNode_->holistic()) {     //pid > 0
    QList < INode > iNodeList = sNode_->evalTopDown(this);
#ifdef DEBUGMSG
qDebug("##*** evalTopDown: %d(min) < %d(ist) < %d(max)",sNode()->minNumNode(),iNodeList.count(), sNode()->maxNumNode());
#endif
    if (!(sNode()->minNumNode() == 0 && sNode()->maxNumNode() == 0 )) //beide eintraege null -> alles erlaubt
      if (iNodeList.count() < sNode()->minNumNode() || iNodeList.count() > sNode()->maxNumNode() ) {
#ifdef DEBUGMSG
qDebug("*****  iNodeList.count %d, sNode->minNumNode %d, sNode->maxNumNode %d \n",iNodeList.count(),sNode()->minNumNode(),sNode()->maxNumNode());
#endif
        status(MI);
        execState(BU);
        truncation(TRUE);
        //! unlink here
        parent->status(TRASH);
        parent->truncation(TRUE);
        parent->childUnlink(this);      //!remove this temporary INode
        parent->decrementCount();
        return 0;
      }
#ifdef DEBUGMSG
    qDebug("#  (INFO) sNode is holistic; count new nodes: %d\n", iNodeList.count());
#endif

    if (iNodeList.isEmpty()) {
#ifdef DEBUGMSG
      qDebug("#  (warning) operator return no result - missing Instance");
#endif
      status(MI);
      execState(BU);
      //! unlink here
      parent->childUnlink(this);      //!remove this temporary INode
      parent->decrementCount();
      return 0;
    }

    parent->incrementCount(iNodeList.count() - 1);
    INode *el;
    parent->childUnlink(this);        //!remove this temporary INode
    for (el = iNodeList.first(); el != 0; el = iNodeList.next()) {
#ifdef DEBUGMSG
      qDebug("# einhaengen: (%p) %s in %s", this,(const char *)el->name(), (const char *)parent->name());
#endif
      if (el->isLast())
        el->status(CI);  //el->execState(BU); ???????????
      else
        el->status(PI);
      el->execState(TD); //}?????????????
      parent->childLink(el);         //insert the new INodes
      analysis_->nodeChange(el);
      if (el->isLast())
        parent->decrementCount();
      else
        el->childTopDown();     //last node have no children
    }
    //delete this; //XXXX
#ifdef DEBUGMSG
      qDebug("# einhaengen: (%p) fertig in %s",this,(const char *)parent->name());
#endif
    return 0;
  }
  else {
    qDebug
      ("#  (ERROR 1) taskFinished no operator found \n  try it structural\n");
    if (isLast())
      qDebug("#  (ERROR 1) last node must be holistic!\n");
    parent->childUnlink(this);        //!remove this temporary INode
    return 0;
  }
}
ZLTextParagraphCursorPtr ZLTextPlainParagraphCursor::next() const {
	return isLast() ? 0 : myParagraphCursorCache->cursor(myModel, myIndex + 1);
}
예제 #13
0
int main() {
    List L = malloc(sizeof(struct Node));
    L->next = NULL;

    if (isEmpty(L))
    	puts("Empty\n");
    else
    	puts("Not empty\n");
   
    insert(3, L, L);
    Position last = L->next;
    /* test inserting */
    insert(5, L, last);
    last = last -> next;
    insert(2, L, last);
    last = last -> next;
    
    printfList(L);

    /* test isEmpty again */
    if (isEmpty(L))
    	puts("Empty\n");
    else
    	puts("Not empty\n");

    if (isLast(last))
    	printf("Last is %d\n", last->value);

    /* test finding */
    Position p = find(5, L);
    printf("Found place's value %d\n", p->value);
    
    /* test deleting */
    delete(5, L);
    printfList(L);

    insert(9, L, last);
    last = last->next;

    p = findPrevious(9, L);
    printf("Previous Position's value %d\n", p->value);

    /* test getting header */
    p = header(L);
    assert(p == L);

    /* test getting first */
    p = first(L);
    printf("First node value: %d\n", p->value);

    /* test advancing method */
    p = advance(p);
    printf("First node adancing, now %d\n", p->value);

    /* test retrieving */
    printf("Last value retieved: %d\n", retrieve(last));

    /* test deleteList */
    deleteList(L);
    if (L == NULL)
    	printf("Delete List Done\n");

    return 0;
}
예제 #14
0
/* BEGIN TEMPLATE */
void solve() {
	/* BEGIN SOLUTION */
	/* cruft to search for an instance exercising all transformations */
	int doneA=0;
	int doneB=0;
	int doneC=0;
	int doneD=0;
	int doneE=0;
	int doneF=0;
	int doneG=0;
	int doneH=0;
	int* origSizes = (int*)malloc(sizeof(int)*getStackSize());
	int i;
	for (i=0;i<getStackSize();i++)
		origSizes[i] = getPancakeRadius(i);
	/* end of this cruft */

	int stackSize = getStackSize();

	if (debug>0) {
		printf("{\n");
		int rank;
		for (rank=0; rank < stackSize; rank++){
			printf("%d\n",getPancakeRadius(rank));
		}
		printf("}\n");
	}

	while (1) {
		int tRadius = getPancakeRadius(0);
		int posTPlus  = getRankOf(tRadius+1); // returns -99 if non-existent, that is then ignored
		int posTMinus = getRankOf(tRadius-1);
		int posT = 0;

		if (debug>1) {
			printf("t Radius: %d\n",tRadius);
			int rank;
			for (rank=0; rank < stackSize; rank++) {
				printf("[%d]=%d; ",rank,getPancakeRadius(rank));

				if (isFree(rank))
					printf("free;");
				else
					printf("NON-free;");

				if (isFirst(rank))
					printf("first; ");
				else
					printf("NON-first; ");

				if (isLast(rank))
					printf("last; ");
				else
					printf("NON-last; ");


				if (rank == posTPlus)
					printf("t+1; ");
				if (rank == posTMinus)
					printf("t-1; ");
				if (rank == posT)
					printf("t;" );

				printf("\n");
			}
		}

		if (isFree(posT)) {
			if (isFree(posTPlus)) { /* CASE A: t and t+o free */
				if (debug>0)
					printf("Case A+\n");
				flip(posTPlus);
				doneA = 1;
			} else if (isFree(posTMinus)) { /* CASE A: t and t-o free */
				if (debug>0)
					printf("Case A-\n");
				flip(posTMinus);
				doneA = 1;

			} else if (isFirst(posTPlus)) { /* CASE B: t free, t+o first element */
				if (debug>0)
					printf("Case B+\n");
				flip(posTPlus);
				doneB = 1;
			} else if (isFirst(posTMinus)) { /* CASE B: t free, t-o first element */
				if (debug>0)
					printf("Case B-\n");
				flip(posTMinus);
				doneB = 1;

			} else if (min(posTPlus,posTMinus) != -99) { /* CASE C: t free, but both t+o and t-o are last elements */
				if (debug>0)
					printf("Case C\n");
				flip(min(posTPlus,posTMinus) );
				flip(min(posTPlus,posTMinus) - 1);
				flip(max(posTPlus,posTMinus) + 1);
				flip(min(posTPlus,posTMinus) - 1);
				doneC = 1;

			} else {
				if (debug>0)
					printf("Case Cbis\n");
				flip(max(posTPlus,posTMinus) + 1);
				flip(max(posTPlus,posTMinus) );
				doneC = 1;
			}

		} else { // t is in a block
			if (blockLength() == stackSize) { // Done!
				if (tRadius != 1) // all reverse
					flip(stackSize);
				if (doneA && doneB && doneC && doneD && doneE && doneF && doneG && doneH && wasRandom()) {
					printf("BINGO! This instance is VERY interesting as it experiences every cases of the algorithm.\nPLEASE REPORT IT. PLEASE DONT LOSE IT.\n");
					printf("{\n");
					int rank;
					for (rank=0; rank < stackSize; rank++)
						printf("%d, ",origSizes[rank]);
					printf("}\n");
				}
				free(origSizes);
				return;
			}

			if (isFree(posTPlus)) {          /* CASE D: t in a block, t+1 free */
				if (debug>0)
					printf("Case D+\n");
				flip(posTPlus);
				doneD = 1;

			} else if (isFree(posTMinus)) {  /* CASE D: t in a block, t-1 free */
				if (debug>0)
					printf("Case D-\n");
				flip(posTMinus);
				doneD = 1;

			} else if (isFirst(posTPlus)) {  /* CASE E: t in a block, t+1 first element */
				if (debug>0)
					printf("Case E+\n");
				flip(posTPlus);
				doneE = 1;

			} else if (isFirst(posTMinus)) { /* CASE E: t in a block, t-1 first element */
				if (debug>0)
					printf("Case E-\n");
				flip(posTMinus);
				doneE = 1;

			} else if (isLast(posTPlus) && posTPlus != 1) { /* CASE F+: t in a block, t+1 last element */
				doneF = 1;
				if (debug>0)
					printf("Case F+\n");
				flip(blockLength());
				flip(posTPlus + 1);
				int newPos = getRankOf(tRadius);
				if (newPos>0)
					flip(newPos);

			} else if (isLast(posTMinus) && posTMinus != 1) { /* CASE F-: t in a block, t-1 last element */
				doneF = 1;
				if (debug>0)
					printf("Case F-\n");
				flip(blockLength());
				flip(posTMinus + 1);
				int newPos = getRankOf(tRadius);
				if (newPos>0)
					flip(newPos);
			} else {
				int k = blockLength()-1;
				int o = getPancakeRadius(1) - tRadius;
				int pos = getRankOf(tRadius+(k+1)*o);
				if (isFree(pos) || isFirst(pos)) {
					doneG = 1;
					if (debug>0)
						printf("Case G\n");
					flip(k+1);
					flip(pos);
				} else {
					doneH = 1;
					if (debug>0)
						printf("Case H\n");
					flip(pos+1);
					flip(getRankOf(tRadius+k*o));
				}
			}
		}
	}
	free(origSizes);
	/* END SOLUTION */
}
예제 #15
0
CleverMonster::~CleverMonster() {
    if(isLast()) {
        freeMaps();
    }
}
void BookmarksDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if(!mViewPtr)
        return;

    painter->save();
    QColor bkgrColor = QColor(0xAA,0xAA,0xAA);
    QColor folderColor = QColor(0x33, 0x33, 0x33);

    QPen borderPen(bkgrColor.darker());
    if(!isFolder(index))
    {
        QRadialGradient itemGradient(0.3*(qreal)option.rect.width()+option.rect.left(), -2*(qreal)option.rect.height()+option.rect.top(), 0.8*(qreal)option.rect.width(), 0.3*(qreal)option.rect.width()+option.rect.left(), -2*(qreal)option.rect.height()+option.rect.top());
        itemGradient.setColorAt(0.0, Qt::white);
        itemGradient.setColorAt(1.0, bkgrColor);

        if(isLast(index))
        {
            QPainterPath endPath;
            endPath.moveTo(option.rect.topLeft());
            endPath.lineTo(option.rect.bottomLeft()-QPoint(0, RADIUS));
            endPath.arcTo(option.rect.left(), option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 180, 90);
            endPath.lineTo(option.rect.bottomRight()-QPoint(RADIUS, 0));
            endPath.arcTo(option.rect.right()-2*RADIUS, option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 270, 90);
            endPath.lineTo(option.rect.topRight());

            //painter->setBrush( bkgrColor );
            painter->setBrush(itemGradient);
            painter->setPen(borderPen);
            painter->drawPath(endPath);
        }
        else // middle elements
        {
            //painter->setBrush( bkgrColor );
            painter->setBrush(itemGradient);
            painter->setPen(Qt::NoPen);
            painter->drawRect(option.rect);

            painter->setPen(borderPen);
            // vertical lines
            painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
            painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
            // horizontal lines
            painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
        }

        QRectF brect = option.rect;
        brect.setLeft(brect.left()+SPACER);
        painter->setFont(option.font);
        painter->drawText(brect, Qt::AlignVCenter, qVariantValue<QString>(index.data()));
    }
    else // doesn't have parent
    {
        QRadialGradient itemGradient(0.3*(qreal)option.rect.width()+option.rect.left(), -2*(qreal)option.rect.height()+option.rect.top(), 0.8*(qreal)option.rect.width(), 0.3*(qreal)option.rect.width()+option.rect.left(), -2*(qreal)option.rect.height()+option.rect.top());
        itemGradient.setColorAt(0.0, Qt::white);
        itemGradient.setColorAt(1.0, folderColor);

        QPainterPath titlePath;
        if(isExpanded(index))
        {
            titlePath.moveTo(option.rect.bottomLeft());
            titlePath.lineTo(option.rect.topLeft()+QPoint(0, RADIUS));
            titlePath.arcTo(option.rect.left(), option.rect.top(), 2*RADIUS, 2*RADIUS, 180, -90);
            titlePath.lineTo(option.rect.topRight()-QPoint(RADIUS, 0));
            titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.top(), 2*RADIUS, 2*RADIUS, 90, -90);
            titlePath.lineTo(option.rect.bottomRight());
            titlePath.closeSubpath();
        }
        else
        {
            titlePath.lineTo(option.rect.topLeft()+QPoint(0, RADIUS));
            titlePath.arcTo(option.rect.left(), option.rect.top(), 2*RADIUS, 2*RADIUS, 180, -90);
            titlePath.lineTo(option.rect.topRight()-QPoint(RADIUS, 0));
            titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.top(), 2*RADIUS, 2*RADIUS, 90, -90);
            titlePath.lineTo(option.rect.bottomRight()-QPoint(0, RADIUS));
            titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 0, -90);
            titlePath.lineTo(option.rect.bottomLeft()+QPoint(RADIUS, 0));
            titlePath.arcTo(option.rect.left(), option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 270, -90);
            titlePath.closeSubpath();
        }

        painter->setBrush(itemGradient);
        painter->setPen(borderPen);
        painter->drawPath(titlePath);

        QRectF brect = option.rect;
        brect.setLeft(brect.left()+SPACER);
        painter->setFont(option.font);
        painter->drawText(brect, Qt::AlignVCenter, qVariantValue<QString>(index.data()));
    }

    //// HIGHLIGHTING SELECTED ITEM
    //if (option.state & QStyle::State_Selected)
        //painter->fillRect(option.rect, option.palette.highlight());

    painter->restore();
}