示例#1
0
bool Boom(TC_Hero * phero,TC_Direction d,int OFFS)
{
	//判断英雄在d方向下,连续OFFS步会撞不
	TC_Position hp=phero->pos;
	TC_Position bp=iFreeBall.pos;
	TC_Speed sp=iFreeBall.speed;
	int hx,hy,bx,by;
	int i;
	for(i=1;i<=OFFS;++i)
	{
		//	if(i>iFreeBall.u.moving_time_left)return false;//球如果消失不用判断了
		hp=nextPosition(phero,d,hp);
		if((bp.y-iFreeBall.u.path.pos_start.y)*(bp.y-iFreeBall.u.path.pos_end.y)<=0 && (bp.x-iFreeBall.u.path.pos_start.x)*(bp.x-iFreeBall.u.path.pos_end.x)<=0 )
		{
		}
		else {
			sp.vx=-sp.vx;
			sp.vy=-sp.vy;
		}
		bp.x+=sp.vx;
		bp.y+=sp.vy;
		hx=hp.x+TC_HERO_WIDTH/2;
		hy=hp.y+TC_HERO_HEIGHT/2;
		bx=bp.x+TC_BALL_WIDTH/2;
		by=bp.y+TC_BALL_HEIGHT/2;
		double dis=sqrt(double( (hx-bx)*(hx-bx)+(hy-by)*(hy-by) ));
		if(dis<BOOMDIS)//会相撞
			break;
	}
	return i<=OFFS;
}
示例#2
0
//Navigate and map maze from starting point
void MazeNav::firstNavigate()
{
	RelDir turn;
	facing = WEST;
	
	eastTicks = MAX_EAST_TICKS;
	northTicks = 0;
	
	searchInitEntrance();
	while (1) //TODO: Need exit condition
	{
		while (!nextPosition());
#ifdef SIMULATION
if (irInMm.frnt <= 0)
	break;
#endif
		turn = alwaysLeft();
#ifdef DEBUG
Serial.print("Turn: ");
Serial.println((char)turn);
#endif
		facing = findNewFacing(facing, turn);
		updateTicks();
		mazeMap.updateMap(turn, eastTicks, northTicks);
#ifndef SIMULATION
		mover->rotateDirection(turn, DEFAULT_SPEED);
#endif
	}
#ifdef DEBUG
Serial.println("MazeMap: ");
mazeMap.printMapTurns();
Serial.println();
#endif
}
  void PhrasePositions::firstPosition(){
  //Func - Read the first TermPosition
  //Pre  - tp != NULL
  //Post - 

      CND_PRECONDITION(tp != NULL,"tp is NULL");

      //read first pos
      count = tp->freq();				  
      //Move to the next TermPosition
	  nextPosition();
  }
示例#4
0
  inline bool enqueue(const T &item) {
    static_assert(Size > 1, "RingBuffer size must be > 1");
    uint8_t next = nextPosition(head_);
    if (next == tail_) {
      // Full
      return false;
    }

    buf_[head_] = item;
    head_ = next;
    return true;
  }
示例#5
0
PreviewBoard::PreviewBoard(DockPreviewBoard* dockPreviewBoard, QWidget *parent) : QWidget(parent),
  dockPreviewBoard_(dockPreviewBoard)
{
  srand ( time(NULL) );
  for (int x = 0; x < 19; x++) {
    for (int y = 0; y < 19; y++) {
      whiteStoneType_[x][y] = rand()%35; // between 0 and 35
      board_[x][y] = 0;
    }
  }
  
//   boards.clear();
//   resize(400, 400);
//   setMinimumSize ( 200, 200 ); //int minw, int minh
//   setMaximumSize ( 600, 600 );
//   setSizeIncrement ( 0, 0 );
  setMouseTracking (true);
      
  QString boardDir = Resources::path();
  origBoardImage = QPixmap(boardDir + "Beige1.png");
  QPalette palette;
  palette.setBrush(backgroundRole(), QBrush(origBoardImage));
  setPalette(palette);
  setAutoFillBackground ( true );
  //connect(this, SIGNAL(click()), this, SLOT(makeFocus()));
  
  previewBoardMenu = new QMenu("Preview board menu", this);
//   boardMenu->setTitle ("Preview board menu");
  
  
  positionActions_ = new QActionGroup(this);
  positionActions_->setExclusive(true);
  
  currentPositionAct = new QAction(tr("&Current board position"), this);
  currentPositionAct->setCheckable(true);
  
  nextPositionAct = new QAction(tr("&Board next move"), this);
  nextPositionAct->setCheckable(true);
  
  endPositionAct = new QAction(tr("&End position"), this);
  endPositionAct->setCheckable(true);
  
  positionActions_->addAction (currentPositionAct);
  positionActions_->addAction (nextPositionAct);
  positionActions_->addAction (endPositionAct);
  
  previewBoardMenu->addActions(positionActions_->actions());
  
  connect(currentPositionAct, SIGNAL(triggered()), this, SLOT(currentPosition()));
  connect(nextPositionAct, SIGNAL(triggered()), this, SLOT(nextPosition()));
  connect(endPositionAct, SIGNAL(triggered()), this, SLOT(endPosition()));
}
示例#6
0
  inline bool get(T &dest, bool commit = true) {
    auto tail = tail_;
    if (tail == head_) {
      // No more data
      return false;
    }

    dest = buf_[tail];
    tail = nextPosition(tail);

    if (commit) {
      tail_ = tail;
    }
    return true;
  }
    void addBoxedItem(QGraphicsItem* item, QString title) {
        QGraphicsRectItem* box = createBox();
        item->setParentItem(box);

        QString htmlTitle = QString("<center>%1</center>").arg(title);
        QGraphicsTextItem *textItem = new QGraphicsTextItem();
        textItem->setDefaultTextColor(Qt::blue);
        QFont font;
        font.setPixelSize(10);
        textItem->setFont(font);

        textItem->setHtml(htmlTitle);

        textItem->setTextWidth(WIDTH);
        textItem->setParentItem(box);
        textItem->moveBy(0, 110);
        nextPosition();
    }
Position VisiblePosition::nextVisiblePosition(const Position &pos)
{
    if (pos.isNull() || atEnd(pos))
        return Position();

    Position test = deepEquivalent(pos);
    bool acceptAnyVisiblePosition = !isCandidate(test);

    Position current = test;
    Position downstreamTest = test.downstream(StayInBlock);
    while (!atEnd(current)) {
        current = nextPosition(current);
        if (isCandidate(current) && (acceptAnyVisiblePosition || (downstreamTest != current.downstream(StayInBlock)))) {
            return current;
        }
    }

    return Position();
}
示例#9
0
void sewClothModel() {
	M3DVector3f temp, displacement;
	for (int i = 0; i < PTCAMT; i ++) {
		m3dLoadVector3(displacement, 0.0f, 0.0f, 0.0f);
		clearForce(i);
		getInternalForce(i);
		//sew together
		getTensionForce(i, ClothCenter, 0.01f);
		m3dScaleVector3(ClothLnk[i].force, TensionCoefficient);
		nextPosition(i);
		m3dSubtractVectors3(temp, ClothLnk[i].next_position, ClothLnk[i].position);
		m3dAddVectors3(displacement, displacement, temp);
	}
	m3dScaleVector3(displacement, (GLfloat)800000/PTCAMT);
	//printf(" total displace: %.1f %.1f %.1f\n", displacement[0], displacement[1], displacement[2]);
	m3dAddVectors3(ClothCenter, ClothCenter, displacement);
	//m3dLoadVector3(TotalDisplacement, 0.0f, 0.0f, 0.0f);
	refreshPosition();

}
Position VisiblePosition::downstreamDeepEquivalent() const
{
    Position pos = m_deepPosition;

    if (pos.isNull() || atEnd(pos))
        return pos;

    Position downstreamTest = pos.downstream(StayInBlock);

    Position current = pos;
    while (!atEnd(current)) {
        current = nextPosition(current);
        if (isCandidate(current)) {
            if (downstreamTest != current.downstream(StayInBlock))
                break;
            pos = current;
        }
    }

    return pos;
}
示例#11
0
//  recursive function using backtrack method
void knightTravel(int x, int y){
    POINT array[8] = {{0, 0}, {0, 0}};
    // remainin initialized to zero automatically
    volatile int noOfPossiblePoints = nextPosition(x, y, array);
    volatile int i;
 
    chessBoard[x][y] = ++count;
 
    // base condition uses count
    if( count == chessBoardSize * chessBoardSize ){
        displayAnswer();
        exit(0);
    }
 
    for(i=0; i< noOfPossiblePoints; i++)
        if( chessBoard[array[i].x][array[i].y] == 0 )
            knightTravel(array[i].x, array[i].y);
 
    chessBoard[x][y] = 0;
    count--;
}
示例#12
0
void MazeNav::followMap(RelDir navDir)
{
	RelDir turn;
	
	if (navDir == FRONT)
		mazeMap.resetToStart();
	else
		mazeMap.resetToEnd();
	while (!mazeMap.finalTurn())
	{
#ifndef SIMULATION	
		while (!nextPosition());
#endif
		turn = mazeMap.getNext();
#ifdef DEBUG
Serial.print("Turn: ");
Serial.println((char)turn);
#endif
#ifndef SIMULATION
		mover->rotateDirection(turn, DEFAULT_SPEED);
#endif
	}
}
示例#13
0
文件: movement.cpp 项目: vtcb/stuff
bool Movement::move() {
	bool moved = false;

	phase++;

	if(phase == speed) {
		phase = 0;

		changeDirection(next_dir);

		int di = i;
		int dj = j;

		nextPosition(di, dj);

		if(map->valid(di, dj)) {
			_i = di;
			_j = dj;
			moved = true;
		}
	}

	return moved;
}
示例#14
0
void simulation(void) {
	//if (true) {
	//	sewClothModel();
	//} else if (stepCount == 200){
	//	for (int i = 0; i < PTCAMT; i ++) {

	//		clearForce(i);
	//		m3dCopyVector3(ClothLnk[i].next_position, ClothLnk[i].position);
	//	}
	//} else {
		for (int i = 0; i < PTCAMT; i ++) {
			clearForce(i);
			getForce(i);
			//if ((i>=44 && i<=46)||(i>=54 && i<=56)||(i>=64 && i<=66))
			//	printf("[%d].force	 	{%.1f, %.1f, %.1f} \n", i, ClothLnk[i].force[0], ClothLnk[i].force[1], ClothLnk[i].force[2]);
			//printf("	ClothLnk[%d].force = {%f, %f, %f} \n", i, ClothLnk[i].force[0], ClothLnk[i].force[1], ClothLnk[i].force[2]);
		}
	//}
	for (int i = 0; i < PTCAMT; i ++) {
		nextPosition(i);
	}
	refreshPosition();
	stepCount ++;
}
示例#15
0
void Esh3DRenderer::render(const EshShape& in_shape, EshRendererContext& in_rendererContext,MfGdiBrush *in_brush)
{
    ChLOG_DEBUG_START_FN;
    if (!setUp(in_shape, in_rendererContext))
    {
        return;
    }

    // temporary pen & brush so I can see what I'm doing!
    //ChAutoPtr<MfGdiBrush> pBrush = m_driver.CreateSolidBrush(CsColour(0x88, 0x88, 0x88));
    //ChAutoPtr<MfGdiPen> pPen = m_driver.CreatePen(MfGdiPen::Style_Solid, 4, CsColour(0,0,0), ChVector<ChFLT8>());
    //ChAutoPtr<MfGdiBrush> pBrush = EshGdiObjectFactory::makeNullBrush(m_driver);
    ChAutoPtr<MfGdiPen> pPen(EshGdiObjectFactory::makeNullPen(m_driver)); // LINUX_PORT
    // TODO - pen must be null pen, but because faces aren't being shaded according to normal angle, an
    //        outline is being drawn to figure out where the faces are
    //in_rendererContext.getDeviceContextReference().SetBrush(*pBrush);
    //in_rendererContext.getDeviceContextReference().TakeBrush(pBrush.giveUpOwnership());
    in_rendererContext.getDeviceContextReference().TakePen(pPen.giveUpOwnership());

    if (in_rendererContext.hasTransformation())
    {
        // 2D rotation must be done before any 3D rotation/skew, so multiply on right of current
        // 3D world transform, which at this point will have the skew and rotation already
        m_worldTransform = m_worldTransform * CsMatrix3D<ChFLT8>(in_rendererContext.getTransformationMatrix());
    }

    m_pPathData = ChNEW EshPathRendererData(*m_pGeometry, in_rendererContext);
    m_pPathData->init();
    MfGdiDeviceContext& deviceContext = in_rendererContext.getDeviceContextReference();

    // use non-const verion of method to have geometry add implied segments
    const EshPathCommandTable& pathCommands = m_pPathData->getPathCommandsReference();
    if (pathCommands.size() == 0)
    {
        return;
    }

	bool skip				 = true;
    bool isFirstSegmentDrawn = false;

    CsPoint<ChFLT8> startPosition(0,0);
    CsPoint<ChFLT8> position(0,0);
    CsPoint<ChFLT8> nextPosition(0,0);

    const EshPathCommand* pCurrentPathCommand;
    const EshPathCommand* pNextPathCommand;

    ChUINT2 j = 0;

    /**
     * TODO - is it possible for the first path param to be an editing command?
     */
    pNextPathCommand = &pathCommands[0];
    EshPathCommandTypeEnums nextPathCommandType = pNextPathCommand->m_type;

    CsPlanarPolygon<ChFLT8> frontFace;
    CsPlanarPolygon<ChFLT8> extrusion;

    for (ChUINT4 i=1; i <= pathCommands.size(); i++)
    {
        pCurrentPathCommand = pNextPathCommand;

        // Skip editing commands
		skip = true;
        while ( skip && i < pathCommands.size())
        {
			skip = (ESH_PATH_CMD_HA <= pathCommands[i].m_type && pathCommands[i].m_type <= ESH_PATH_CMD_HI);
			if(skip)
			{
				++i;
			}
		}     
        
        if (i == pathCommands.size())
        {
            nextPathCommandType = ESH_PATH_CMD_E;
        }
        else
        {
            pNextPathCommand = &pathCommands[i];
            nextPathCommandType = pNextPathCommand->m_type;
        }

        bool isLastCommand = (nextPathCommandType == ESH_PATH_CMD_E);
        bool isEnd = isLastCommand;
        
        switch (pCurrentPathCommand->m_type)
        {
        case ESH_PATH_CMD_L:
            // Line to
//            openClosedPath(deviceContext);
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                m_pPathData->getPoint(nextPosition);
                //m_pPathData->getPoint(nextPosition);
                if (!isFirstSegmentDrawn)
                {
                    startPosition = position;
                    frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth));
                    isFirstSegmentDrawn = true;
                }

                if (m_isFilled)
                {
                    frontFace.addPoint(m_worldTransform * ChPoint3DF8(nextPosition, m_lForeDepth));
                }
                // TODO - linecap stuff

                makePolygon(position, nextPosition, extrusion);
                m_tree.insert(extrusion);
                position = nextPosition;
            }
            break;

        case ESH_PATH_CMD_C:
            // Cubic curve
//            openClosedPath(deviceContext);
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                ChPoint3DF8 p0(position.getX(), position.getY(), m_lForeDepth);
                ChPoint3DF8 p1(m_pPathData->getPointF8(), m_lForeDepth);  // 1st control point
                ChPoint3DF8 p2(m_pPathData->getPointF8(), m_lForeDepth);  // 2nd control point
                m_pPathData->getPoint(nextPosition);
                ChPoint3DF8 p3(nextPosition, m_lForeDepth);  // endpoint
                if (!isFirstSegmentDrawn)
                {
                    startPosition = position;
                    if (m_isFilled)
                    {
                        frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth));
                    }
                    isFirstSegmentDrawn = true;
                }

                divideBezier(p0, p1, p2, p3, frontFace);
                position = nextPosition;
            }
            break;

        case ESH_PATH_CMD_M:
            // Move to - count is always 1
            ChASSERT(pCurrentPathCommand->m_unCount == 1);
            m_pPathData->getPoint(position);
            break;
        case ESH_PATH_CMD_X:
            // Close path
            nextPosition = startPosition;
            if (position != nextPosition)
            {
                makePolygon(position, nextPosition, extrusion);
                m_tree.insert(extrusion);
                position = nextPosition;
            }
            
           if (m_isFilled)
            {
                m_faces.push_back(frontFace);
                frontFace.clear();
            }
            isFirstSegmentDrawn = false;
            break;
        case ESH_PATH_CMD_E:
            // End path data attribute
            /* Freeform paths will not have a close path command, however, if
               the path is filled, we still need a polygon for that line segment. */
            if (m_isFilled && position != startPosition)
            {
                makePolygon(position, startPosition, extrusion);
                m_tree.insert(extrusion);
                position = startPosition;
                m_faces.push_back(frontFace);
                frontFace.clear();
            }
            break;
       
        case ESH_PATH_CMD_AE:
            // Angle ellipse to
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                if (!isFirstSegmentDrawn)
                {
                    startPosition =  makeAngleEllipse(in_rendererContext, position, false, j, frontFace);
                    isFirstSegmentDrawn = true;
                }
                else
                {
                    makeAngleEllipse(in_rendererContext, position, false, j, frontFace);
                }
            }
            break;

        case ESH_PATH_CMD_AL:
            // Angle ellipse
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                if (!isFirstSegmentDrawn)
                {
                    startPosition =  makeAngleEllipse(in_rendererContext, position, true, j, frontFace);
                    isFirstSegmentDrawn = true;
                }
                else
                {
                    makeAngleEllipse(in_rendererContext, position, true, j, frontFace);
                }
            }
            break;

        case ESH_PATH_CMD_AT:
            // Arc to
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                if (!isFirstSegmentDrawn)
                {
                    startPosition = makeArc(position, false, j, false, frontFace);
                    isFirstSegmentDrawn = true;
                }
                else
                {
                    makeArc(position, false, j, false, frontFace);
                }

                
            }
            break;

        case ESH_PATH_CMD_AR:
            // Arc
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                if (!isFirstSegmentDrawn)
                {
                    startPosition = makeArc(position, true, j, false, frontFace);
                    frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth));
                    isFirstSegmentDrawn = true;
                }
                else
                {
                    makeArc(position, true, j, false, frontFace);
                }
            }
            break;

        case ESH_PATH_CMD_WA:
            // Clockwise arc to
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                if (!isFirstSegmentDrawn)
                {
                    startPosition = makeArc(position, false, j, true, frontFace);
                    isFirstSegmentDrawn = true;
                }
                else
                {
                    makeArc(position, false, j, true, frontFace);
                }
            }
            break;

        case ESH_PATH_CMD_WR:
            // Clockwise arc
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                if (!isFirstSegmentDrawn)
                {
                    startPosition = makeArc(position, true, j, true, frontFace);
                    frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth));
                    isFirstSegmentDrawn = true;
                }
                else
                {
                    makeArc(position, true, j, true, frontFace);
                }               
            }
            break;

        case ESH_PATH_CMD_QX:
            // Elliptical quadrant x
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                if (!isFirstSegmentDrawn)
                {
                    startPosition = position;
                    isFirstSegmentDrawn = true;
                }
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                makeQuadrantArc(position, j % 2 == 0, frontFace);

            }
            break;

        case ESH_PATH_CMD_QY:
            // Elliptical quadrant y
            for (j=0; j < pCurrentPathCommand->m_unCount; j++)
            {
                if (!isFirstSegmentDrawn)
                {
                    startPosition = position;
                    frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth));
                    isFirstSegmentDrawn = true;
                }
                isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1);
                makeQuadrantArc(position, j % 2 == 1, frontFace);
            }
            break;
        }

    }

    // Draw the actual shape.
    m_tree.render(m_driver, in_rendererContext);
    if (m_isFilled)
    {
        ChBYTE opacity = 255;
        const EshFill &fill = in_shape.getFill();

        if (fill.isOpacitySet())
        {
            opacity = fill.getOpacity() >> 8;
        }

        renderPrimaryFaces(deviceContext,in_brush,opacity);
    }
 void PhrasePositions::firstPosition()
 {
     count = tp->freq(); // read first pos
     nextPosition();
 }
示例#17
0
void Lexico::createLexico()
{
	bool sig;
	int nTab = 0;
	while (noError && (sig = nextPosition()))
	{
		sig = false;
		if (isdigit(cadena[position])) {
			elementos.push_back(Elemento(std::string(1, cadena[position]), T_ENTERO));
			while (nextPosition()) {
				if (isdigit(cadena[position]))
				{
					elementos.back().simbolo.append(1, cadena[position]);
				}
				else if (cadena[position] == '.') {
					elementos.back().tipo = T_FLOTANTE;
					elementos.back().simbolo.append(1, cadena[position]);
					while ((sig = nextPosition()) && isdigit(cadena[position]))
					{
						elementos.back().simbolo.append(1, cadena[position]);
					}
					if (sig)	position--;
					break;
				}
				else
				{
					position--;
					break;
				}
			}
		}
		else if (isalpha(cadena[position]) || cadena[position] == '_') {
			elementos.push_back(Elemento(std::string(1, cadena[position]), T_ID));
			while ((sig = nextPosition()) && isalnum(cadena[position]) || cadena[position] == '_')
			{
				elementos.back().simbolo.append(1, cadena[position]);
			}
			if (sig)	position--;
		}
		else {
			switch (cadena[position]) {
			case ' ':
			case '\t':
				break;
			case '\n':
			case '\r':
				elementos.push_back(Elemento(std::string(1, cadena[position]), T_SALTO_LINEA));

				while ((sig = nextPosition()) && cadena[position] == '\n' || cadena[position] == '\r');
				if (sig) position--;

				nTab = 0;
				while ((sig = nextPosition()) && cadena[position] == '\t')
				{
					nTab++;
				}
				if (sig)
				{
					position--;
				}
				if (indent > nTab)
				{
					for (int a = 0; a < indent - nTab; a++)
						elementos.push_back(Elemento(std::string(1, cadena[position]), T_DEDENT));
				}
				else if (indent < nTab)
				{
					for (int a = 0; a < nTab - indent; a++)
						elementos.push_back(Elemento(std::string(1, cadena[position]), T_INDENT));
				}
				indent = nTab;
				break;
			case ':':
				elementos.push_back(Elemento(std::string(1, cadena[position]), T_DOS_PUNTOS));
				break;
			case '+':
			case '-':
				elementos.push_back(Elemento(std::string(1, cadena[position]), T_ADICION));
				break;
			case ',':
				elementos.push_back(Elemento(std::string(1, cadena[position]), T_COMA));
				break;
			case '(':
			case ')':
				elementos.push_back(Elemento(std::string(1, cadena[position]), T_PARENTESIS));
				break;
			case '*':
			case '/':
				elementos.push_back(Elemento(std::string(1, cadena[position]), T_MULTIPLICACION));
				break;
			case '=':
				if ((sig = nextPosition()) && cadena[position] == '=') {
					elementos.push_back(Elemento("==", T_IGUAL_QUE));
				}
				else
				{
					if (sig) position--;
					elementos.push_back(Elemento("=", T_ASIGNACION));
				}
				break;
			case '&':
				if ((sig = nextPosition()) && cadena[position] == '&') {
					elementos.push_back(Elemento("&&", T_AND));
				}
				else
				{
					noError = false;
				}
				break;
			case '|':
				if ((sig = nextPosition()) && cadena[position] == '|') {
					elementos.push_back(Elemento("||", T_OR));
				}
				else
				{
					noError = false;
				}
				break;
			case '!':
				if ((sig = nextPosition()) && cadena[position] == '=') {
					elementos.push_back(Elemento("!=", T_DIFERENTE));

				}
				else
				{
					if (sig) position--;
					elementos.push_back(Elemento("!", T_NOT));
				}
				break;
			case '<':
			case '>':
				if ((sig = nextPosition()) && cadena[position] == '=') {
					elementos.push_back(Elemento(cadena.substr(position - 1, 2), T_MAYOR_MENOR_IGUAL_QUE));
				}
				else
				{
					if (sig) position--;
					elementos.push_back(Elemento(std::string(1, cadena[position]), T_MAYOR_MENOR_QUE));
				}
				break;
			default:
				noError = false;
			}
		}
	}
}
示例#18
0
/* Malloc Function */
void *MyMalloc(int size){
	
	//checking whether given size is lesser than the (array_size - 1000) if okay then proceed, else give an error
	if(size < (ARRAY_SIZE - 1000)){
		
		//void pointers to be used
		void *vir,*adr;
	
		//checking for the HEAD : to find out the initial starting point
		if(!memory[HEAD] && (size+13)<(ARRAY_SIZE - 4)){
			//setting initial starting point
			memory[HEAD]=4;	
			//pointing vir_pointer to the starting address
			vir = &memory[memory[HEAD]];
			//setting the previous point for the block
			insert_pos(HEAD,4);
			memory[4]=0;
			memory[8]=size;
			vir += 8;
			adr = vir;
			memory[12+size] = TRUE;
			insert_pos(17+size,13+size);
			//returning the address
			return adr;					
		}

		/* if HEAD is initialized then check for the next position which HEAD points */
		else{
			int x = memory[HEAD];
			if((isAvailable(x) == TRUE) && (giveSize(x) == size || giveSize(x) > size)){
				void *vir,*adr;
				vir = &memory[x];
				vir += 8;
				adr = vir;
				//setting the chunck is filled
				memory[x+8+size] = TRUE;
				return adr;						
			}
			else{
				int prev = x;
				int next = nextPosition(x);//taking the next position adjacent to 'x'
				//try to find a available slot from the memory
				while(((isAvailable(next) == FALSE) ||  (giveSize(next) < size )) && (next+13+giveSize(next)+size<19996) && giveSize(next) != 0){
					//if not found then go into the loop : set 'prev' to current 'next' and 'next' to next_position of 'next'
					prev = next;
					next = nextPosition(next);
					//check whether new 'next' is available : if available then allocate it, else continue the loop
					if((isAvailable(next) == TRUE) && (giveSize(next)==0)){
						void *vir,*adr;
						insert_pos(prev,next);
						insert_size(size,next+4);
						vir = &memory[next];
						vir += 8;
						adr = vir;
						//setting the chunk is filled
						memory[next+8+size] = TRUE;
						insert_pos(next+size+13,next+size+9);
						return adr;							
					}
					else{
						continue;
					}
				}
				//if available memory slot is found, then allocate it , else give an error 
				if(isAvailable(next) && (next+13+giveSize(next)+size < 19996) && (giveSize(next) == size || giveSize(next) > size || giveSize(next) == 0)){
					
						void *vir,*adr;
						insert_pos(prev,next);
						insert_size(size,next+4);
						vir = &memory[next];
						vir += 8;
						adr = vir;
						//setting the chunk is filled
						memory[next+8+size] = TRUE;
						insert_pos(next+size+13,next+size+9);
						return adr;							
				}
				printf("Cannot allocate space. Memory is filled.\n");
			}			
		}
	

	}

	else{
		printf("The asked Memory Portion cannot be allocated.\n");
	}
	


}