Esempio n. 1
0
/**
 * Use printf syntaxe to format new single value. This functions aims to be used to fill
 * arrays.
 * @param format Define the format to use in internal sprintf method.
**/
void JsonState::printFormattedValue(const char* format, ... )
{
	char buffer[SPRINTF_BUFFER_SIZE];

	//check where we are
	assert(getState() & (JSON_STATE_FIELD | JSON_STATE_ARRAY));

	//separator
	if (getState() == JSON_STATE_ARRAY && !isFirst())
		bufferdStream << ',';

	//format the chain
	va_list param;
	va_start (param, format);
	size_t size = vsnprintf (buffer,sizeof(buffer), format, param);
	va_end (param);
	
	//check buffer overflow
	if (size <= SPRINTF_BUFFER_SIZE)
		abort();

	//print
	bufferdStream << buffer;
	firstIsDone();
}
Esempio n. 2
0
void expandCube(struct Cube_t *cube) {
	#if LEVEL > DEBUG_WARN
	printf("expandCube()\n");
	#endif
	if (cube->depth >= g_uMaxDepth) return;
	int m;
	for (m=0;m<UNIQUE_MOVES;m++) {
		struct Cube_t *childCube = GlobalAlloc(0, sizeof(struct Cube_t));
		CopyMemory(childCube, cube, sizeof(struct Cube_t));
		DEBUG printf("moveCube() %u\n", m);
		moveCube(cube, childCube, m);
		if (!isFirst(childCube, &rootCube)) {
			DEBUG printf("cube was not first\n");
			GlobalFree(childCube);
			continue;
		}
		pruneClones(childCube, &rootCube);
		childCube->parent = cube;
		childCube->lastMove = m;
		childCube->depth = cube->depth + 1;
		ZeroMemory(&(childCube->nextMove), sizeof(childCube->nextMove));
		cube->nextMove[m] = childCube;
		DEBUG printMoveSequence(childCube);
		DEBUG putchar('\n');
		DEBUG printCube(childCube);
		if (compareCube(childCube, &solvedCube)) {
			printMoveSequence(childCube);
			printCube(childCube);
			printf("SOLUTION\n");
			exit(0);
		} else {
			expandCube(childCube);
		}
	}
}
Esempio n. 3
0
/**
 * Internal function to start a new field.
 * @param name Name of the field to declare.
**/
void JsonState::openField(const char * name)
{
	//check where we are
	assert(getState() & (JSON_STATE_ROOT | JSON_STATE_STRUCT));

	//print name
	if (!isFirst())
	{
		if (useIndent)
			bufferdStream << ',' << LINE_BREAK;
		else
			bufferdStream << ',';
	}

	//setup state
	pushState(JSON_STATE_FIELD);

	//print padding
	putPadding();

	//print name
	if (lua)
		bufferdStream << name << '=';
	else
		bufferdStream << '"' << name << '"' << ':';
}
bool ArrayList::toPrev() {
   if (isFirst() || isEmpty()) {
      return false;
   }

   current--;
   return true;
}
Esempio n. 5
0
void FilterBar::open(QString tag){

    if (history.contains(tag)){
        index=history.indexOf(tag);

        if (index==0) emit isFirst(!true);
        else emit isFirst(!false);
        if (index==history.length()-1) emit isLast(!true);
        else emit isLast(!false);

        emit currentDir(tag,false);
        this->update();
        return;
    }
    else {
        if (index==history.length()-1){
            add(tag);
            index++;
            this->update();
            emit isFirst(!false);
        }
        else {
            QList <QString> t1;
            QList <QRect> t2;
            for (int i=0; i<=index;i++){
                t1.push_back(history[i]);
                t2.push_back(historyButton[i]);
            }
            history.clear();
            historyButton.clear();
            for (int i=0; i<=index;i++){
                history.push_back(t1[i]);
                historyButton.push_back(t2[i]);
            }

            add(tag);
            index++;
            emit isLast(!true);
            emit isFirst(!false);
            this->update();
        }
    }


}
Esempio n. 6
0
BOOL isFirst(struct Cube_t *cube, struct Cube_t *query) {
	if (compareCube(cube, query)) return FALSE;
	int m;
	for (m=0;m<UNIQUE_MOVES;m++) {
		if (cube->nextMove[m] != NULL) {
			if (!isFirst(query, cube->nextMove[m])) return FALSE;
		}
	}
	return TRUE;
}
Esempio n. 7
0
/*******************  FUNCTION  *********************/
void JsonState::printListSeparator(void )
{
	//check where we are
	assert(getState() & (JSON_STATE_FIELD | JSON_STATE_ARRAY | JSON_STATE_ROOT));

	//separator
	if (getState() == JSON_STATE_ARRAY && !isFirst())
		bufferdStream << ", ";

	firstIsDone();
}
Esempio n. 8
0
ChainNarratorNodeIterator & ChainNarratorNodeIterator::operator--()
{
	assert(getChainPrimPtr()->isNarrator());
	if (!isFirst())
		--(*(QList<ChainPrim*>::iterator *)this);
	else
		return nullChainNarratorNodeIterator;
	while (!getChainPrimPtr()->isNarrator())
		--(*(QList<ChainPrim*>::iterator *)this);
	return *this;
}
Esempio n. 9
0
bool isFirst(Cube *cube, Cube *query)
{
    if (compareCube(cube, query)) return false;
    int m;
    for (m=0; m<UNIQUE_MOVES; m++) {
        if (cube->nextMove[m] != NULL) {
            if (!isFirst(query, cube->nextMove[m])) return false;
        }
    }
    return true;
}
Esempio n. 10
0
void FilterBar::back(){
    if (index>0 && t==HISTORY){
        index--;

        if (index == 0) emit isFirst(!true);
        if (index == history.length()-2) emit isLast(!false);
        emit currentDir(history[index],false);
        this->update();
        for (int i=0;i<history.length();i++)
            qWarning()<<history[i];
    }
}
Esempio n. 11
0
void FilterBar::forward(){
    if (index<history.length()-1 && t==HISTORY){
        index++;
        if (index==1) emit isFirst(!false);
        if (index==history.length()-1) emit isLast(!true);
        emit currentDir(history[index],false);
        this->update();
    }
    else if (t!=HISTORY){
        t==HISTORY;
        this->update();
    }
}
void ThumbnailView::Delegate::paintStackedIndicator( QPainter* painter, const QRect &pixmapRect, const QModelIndex& index ) const
{
    DB::ImageInfoPtr imageInfo = model()->imageAt(index.row()).info();
    if (!imageInfo || !imageInfo->isStacked())
        return;

    const QRect cellRect = widget()->visualRect( index );

    // Calculate the three points for the bottom most/right most lines
    int leftX = cellRect.left();
    int rightX = cellRect.right() + 5; // 5 for the 3D effect

    if ( isFirst( index.row() ) )
        leftX = pixmapRect.left() + pixmapRect.width()/2;

    if ( isLast( index.row() ) )
        rightX = pixmapRect.right();

    QPoint bottomLeftPoint( leftX, pixmapRect.bottom() );
    QPoint bottomRightPoint( rightX, pixmapRect.bottom() );
    QPoint topPoint = isLast( index.row() ) ? QPoint( rightX, pixmapRect.top() + pixmapRect.height()/2 ) : QPoint();

    // Paint the lines.
    painter->save();
    for ( int i=0; i < 8; ++i ) {
        painter->setPen( QPen(i % 2 == 0 ? Qt::black : Qt::white) );

        painter->drawLine(bottomLeftPoint,bottomRightPoint);
        if ( topPoint != QPoint() ) {
            painter->drawLine( bottomRightPoint, topPoint );
            topPoint -= QPoint(1,1);
        }

        bottomLeftPoint -= QPoint( isFirst( index.row()) ? 1 : 0, 1 );
        bottomRightPoint -= QPoint( isLast( index.row()) ? 1 : 0, 1);
    }
    painter->restore();
}
Esempio n. 13
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);
}
Esempio n. 14
0
/*******************  FUNCTION  *********************/
void JsonState::openField(const string& name)
{
	//check where we are
	assert(getState() & (JSON_STATE_ROOT | JSON_STATE_STRUCT));

	//print name
	if (!isFirst())
		*out << "," << endl;

	//setup state
	pushState(JSON_STATE_FIELD);

	//print padding
	putPadding();

	//print name
	*out << "\"" << name << "\"" << ": ";
}
Esempio n. 15
0
void ToursDlg::initIndex() {
  TraceOp.trc( "tourdlg", TRCLEVEL_INFO, __LINE__, 9999, "initIndex" );
  m_TourList->Clear();

  iONode model = wxGetApp().getModel();
  if( model != NULL ) {
    iONode tourlist = wPlan.gettourlist( model );
    if( tourlist != NULL ) {
      iOList list = ListOp.inst();
      int cnt = NodeOp.getChildCnt( tourlist );
      for( int i = 0; i < cnt; i++ ) {
        iONode tour = NodeOp.getChild( tourlist, i );
        const char* id = wTour.getid( tour );
        TraceOp.trc( "tourdlg", TRCLEVEL_INFO, __LINE__, 9999, "initIndex add [%s] (%d of %d)", id, i, cnt );
        if( id != NULL ) {
          ListOp.add(list, (obj)tour);
        }
      }

      ListOp.sort(list, &__sortID);
      cnt = ListOp.size( list );
      for( int i = 0; i < cnt; i++ ) {
        iONode tour = (iONode)ListOp.get( list, i );
        const char* id = wTour.getid( tour );
        if( m_StartBlock == NULL || m_ShowAll->IsChecked() || isFirst(tour, m_StartBlock) )
          m_TourList->Append( wxString(id,wxConvUTF8), tour );
      }
      /* clean up the temp. list */
      ListOp.base.del(list);

      if( m_Props != NULL ) {
        m_TourList->SetStringSelection( wxString(wTour.getid( m_Props ),wxConvUTF8) );
        m_TourList->SetFirstItem( wxString(wTour.getid( m_Props ),wxConvUTF8) );
        char* title = StrOp.fmt( "%s %s", (const char*)wxGetApp().getMsg("tour").mb_str(wxConvUTF8), wTour.getid( m_Props ) );
        SetTitle( wxString(title,wxConvUTF8) );
        StrOp.free( title );
      }
      else
        TraceOp.trc( "tourdlg", TRCLEVEL_INFO, __LINE__, 9999, "no selection" );
    }

  }

}
Esempio n. 16
0
int request_cs( const void* self ) {
	Process* proc = ( Process* ) self;

	// CS_REQUEST
	incLamportTime();
	Message requestMsg;
	fillMessage( &requestMsg, proc, CS_REQUEST );
	send_multicast( ( void* ) proc, &requestMsg );

	Request request = { get_lamport_time(), proc -> localId };
	insert( proc -> list, request );

	proc -> replied = 1;
	while( proc -> replied != proc -> total || !isFirst( proc -> list, proc -> localId ) ) {
		defaultCSExtendedCycle( proc );
	}

	return 0;
}
Esempio n. 17
0
        /* {{{ MySQL_ArtResultSet::previous() -I- */
        bool
        MySQL_ArtResultSet::previous()
        {
            CPP_ENTER("MySQL_ArtResultSet::previous");

            /* isBeforeFirst checks for validity */
            if (isBeforeFirst()) {
                return false;
            }
            else if (isFirst()) {
                beforeFirst();
                return false;
            }
            else if (row_position > 1) {
                --row_position;
                --current_record;
                return true;
            }
            throw sql::SQLException("Impossible");
        }
Esempio n. 18
0
/*******************  FUNCTION  *********************/
void JsonState::printFormattedValue(const char* format, ... )
{
	char buffer[1024];

	//check where we are
	assert(getState() & (JSON_STATE_FIELD | JSON_STATE_ARRAY));

	//separator
	if (getState() == JSON_STATE_ARRAY && !isFirst())
		*out << ", ";

	//format the chain
	va_list param;
	va_start (param, format);
	vsnprintf (buffer,sizeof(buffer), format, param);
	va_end (param);

	//print
	*out << buffer;
	firstIsDone();
}
ZLTextParagraphCursorPtr ZLTextTreeParagraphCursor::previous() const {
	if (isFirst()) {
		return 0;
	}
	const ZLTextTreeParagraph *oldTreeParagraph = (const ZLTextTreeParagraph*)myModel[myIndex];
	const ZLTextTreeParagraph *parent = oldTreeParagraph->parent();
	size_t index = myIndex - 1;
	const ZLTextTreeParagraph *newTreeParagraph = (ZLTextTreeParagraph*)myModel[index];
	if (newTreeParagraph != parent) {
		const ZLTextTreeParagraph *lastNotOpen = newTreeParagraph;
		for (const ZLTextTreeParagraph *p = newTreeParagraph->parent(); p != parent; p = p->parent()) {
			if (!p->isOpen()) {
				lastNotOpen = p;
			}
		}
		while (myModel[index] != lastNotOpen) {
			--index;
		}
	}
	return myParagraphCursorCache->cursor(myModel, index);
}
Esempio n. 20
0
void expandCube(Cube *cube)
{
    //if (cube->depth >= g_uMaxDepth) return;
    int m;
    for (m=0; m<UNIQUE_MOVES; m++) {
        //Cube *childCube = GlobalAlloc(0, sizeof(Cube));
        Cube *childCube = malloc(sizeof(Cube));
        //CopyMemory(childCube, cube, sizeof(Cube));
        memcpy(childCube, cube, sizeof(Cube));
        debug("moveCube() %u\n", m);
        moveCube(cube, childCube, m);
        if (!isFirst(childCube, &rootCube)) {
            debug("cube was not first\n");
            //GlobalFree(childCube);
            free(childCube);
            continue;
        }
        pruneClones(childCube, &rootCube);
        childCube->parent = cube;
        childCube->lastMove = m;
        childCube->depth = cube->depth + 1;
        //ZeroMemory(&(childCube->nextMove), sizeof(childCube->nextMove));
        memset(&childCube->nextMove, '\0', sizeof(childCube->nextMove));
        cube->nextMove[m] = childCube;
#ifndef NDEBUG
        printMoveSequence(childCube);
        putchar('\n');
        printCube(childCube);
#endif
        if (compareCube(childCube, &solvedCube)) {
            printMoveSequence(childCube);
            printCube(childCube);
            printf("SOLUTION\n");
            exit(0);
        } else {
            expandCube(childCube);
        }
    }
}
Esempio n. 21
0
Cube *expandGeneration(Cube *cube, unsigned gen)
{
    Cube *result, *child;
    if (cube->depth < gen) {
        //traverse
        for (int m = 0; m < UNIQUE_MOVES; m++) {
            if (cube->nextMove[m] == NULL) continue;
            result = expandGeneration(cube->nextMove[m], gen);
            if (result != NULL) return result;
        }
    } else if (cube->depth == gen) {
        //expand generation
        for (int m = 0; m < UNIQUE_MOVES; m++) {
            assert(cube->nextMove[m] == NULL);
            child = Cube_New();
            verify(memcpy(child->face, cube->face, sizeof(child->face)) == child->face);
            moveCube(child, cube, m);
            child->parent = cube;
            child->lastMove = m;
            child->depth = cube->depth + 1;
            if (compareCube(child, &solvedCube)) {
                cube->nextMove[m] = child;
                return child;
            }
            //if (FALSE) {
            if (!isFirst(&rootCube, child)) {
                //GlobalFree(child);
                free(child);
                continue;
            } else {
                cube->nextMove[m] = child;
            }
        }
    } else {
        fatal(0, "Something really f****d up here");
    }
    return NULL;
}
Esempio n. 22
0
struct Cube_t *expandGeneration(struct Cube_t *cube, UINT generation) {
	int m;
	struct Cube_t *result, *child;
	if (cube->depth < generation) {
		//traverse
		for (m = 0; m < UNIQUE_MOVES; m++) {
			if (cube->nextMove[m] == NULL) continue;
			result = expandGeneration(cube->nextMove[m], generation);
			if (result != NULL) return result;
		}
	} else if (cube->depth == generation) {
		//expand generation
		for (m = 0; m < UNIQUE_MOVES; m++) {
			child = GlobalAlloc(0, sizeof(struct Cube_t));
			ZeroMemory(child, sizeof(struct Cube_t));
			CopyMemory(&child->face, &cube->face, sizeof(struct Face_t[FACES_PER_CUBE]));
			moveCube(child, cube, m);
			child->parent = cube;
			child->lastMove = m;
			child->depth = cube->depth + 1;
			if (compareCube(child, &solvedCube)) {
				cube->nextMove[m] = child;
				return child;
			}
			//if (FALSE) {
			if (!isFirst(&rootCube, child)) {
				GlobalFree(child);
				continue;
			} else {
				cube->nextMove[m] = child;
			}
		}
	} else {
		MessageBox(NULL, "something really f****d up here", NULL, 0);
		exit(0);
	}
	return NULL;
}
Esempio n. 23
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);
	}
}
Esempio n. 24
0
bool Leg::notFirst(double p)
{
	return !isFirst(p);
}
ZLTextParagraphCursorPtr ZLTextPlainParagraphCursor::previous() const {
	return isFirst() ? 0 : myParagraphCursorCache->cursor(myModel, myIndex - 1);
}
Esempio n. 26
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 */
}