示例#1
0
bool SuperastCPP::TraverseFunctionDecl(clang::FunctionDecl* functionDecl) {

  const std::string functionName = functionDecl->getNameInfo().getAsString();

  rapidjson::Value functionValue(rapidjson::kObjectType);
  addId(functionValue);
  addPos(functionValue, functionDecl);
  
  functionValue.AddMember("type", "function-declaration", allocator);
  // Add the name
  functionValue.AddMember(
      "name", 
      rapidjson::Value().SetString(functionName.c_str(), 
                                   functionName.size(),
                                   allocator), 
      allocator);

  // Add the return type
  clang::QualType qualType = functionDecl->getCallResultType().getNonLValueExprType(*context);
  functionValue.AddMember("return-type", createTypeValue((qualType.getTypePtr())), allocator);

  // Array of parameters
  rapidjson::Value parametersValue(rapidjson::kArrayType);

  // Traverse parameters
  for (unsigned int i = 0; i < functionDecl->param_size(); ++i) {
    TRY_TO(TraverseDecl(functionDecl->getParamDecl(i)));

    // Add the parameter to array
    parametersValue.PushBack(sonValue, allocator);
  }

  // Add parameters to functionValue
  functionValue.AddMember("parameters", parametersValue, allocator);
  
  // If this is a function definition, traverse definition.
  if (functionDecl->isThisDeclarationADefinition()) {
    TRY_TO(TraverseStmt(functionDecl->getBody()));
    ensureSonIsArray();
    rapidjson::Value blockValue = createBlockValue(sonValue);
    functionValue.AddMember("block", blockValue, allocator);
  }
  else {
    // If not definition, add empty block
    rapidjson::Value emptyArray(rapidjson::kArrayType);
    functionValue.AddMember("block", createBlockValue(emptyArray), allocator);
  }

  // END BODY TRAVERSE
  sonValue = functionValue;
  return true;
}
JSONTEST_FIXTURE( ValueTest, compareArray )
{
    // array compare size then content
    Json::Value emptyArray(Json::arrayValue);
    Json::Value l1aArray;
    l1aArray.append( 0 );
    Json::Value l1bArray;
    l1bArray.append( 10 );
    Json::Value l2aArray;
    l2aArray.append( 0 );
    l2aArray.append( 0 );
    Json::Value l2bArray;
    l2bArray.append( 0 );
    l2bArray.append( 10 );
    JSONTEST_ASSERT_PRED( checkIsLess( emptyArray, l1aArray ) );
    JSONTEST_ASSERT_PRED( checkIsLess( emptyArray, l2aArray ) );
    JSONTEST_ASSERT_PRED( checkIsLess( l1aArray, l2aArray ) );
    JSONTEST_ASSERT_PRED( checkIsLess( l2aArray, l2bArray ) );
    JSONTEST_ASSERT_PRED( checkIsEqual( emptyArray, Json::Value( emptyArray ) ) );
    JSONTEST_ASSERT_PRED( checkIsEqual( l1aArray, Json::Value( l1aArray) ) );
    JSONTEST_ASSERT_PRED( checkIsEqual( l2bArray, Json::Value( l2bArray) ) );
}
XBOX::VJSValue VJSStructuredClone::_NodeToValue (XBOX::VJSContext inContext, SNode *inNode, std::map<SNode *, JS4D::ValueRef> *ioAlreadyCreated, std::list<SEntry> *ioToDoList)
{
	xbox_assert(ioAlreadyCreated != NULL && ioToDoList != NULL);

	XBOX::VJSValue	value(inContext);

	switch (inNode->fType) {

		case eNODE_UNDEFINED:
	
			value.SetUndefined();
			break;

		case eNODE_NULL:

			value.SetNull();
			break;

		case eNODE_BOOLEAN:
				
			value.SetBool(inNode->fValue.fBoolean);
			break;

		case eNODE_NUMBER:

			value.SetNumber<Real>(inNode->fValue.fNumber);
			break;

		case eNODE_STRING:

			value.SetString(*inNode->fValue.fString);
			break;

		case eNODE_BOOLEAN_OBJECT: 

			value.SetBool(inNode->fValue.fBoolean);
			value = _ConstructObject(inContext, "Boolean", value);
			break;

		case eNODE_NUMBER_OBJECT:

			value.SetNumber(inNode->fValue.fNumber);
			value = _ConstructObject(inContext, "Number", value);
			break;

		case eNODE_STRING_OBJECT:
		case eNODE_REG_EXP_OBJECT: 

			value.SetString(*inNode->fValue.fString);
			value = _ConstructObject(inContext, inNode->fType == eNODE_STRING_OBJECT ? "String" : "RegExp", value);
			break;

		case eNODE_DATE_OBJECT: 

			value.SetNumber(inNode->fValue.fNumber);
			value = _ConstructObject(inContext, "Date", value);
			break;
			
		case eNODE_SERIALIZABLE:
			
			value.SetString(*inNode->fValue.fSerializationData.fJSON);
			value = _ConstructObject(inContext, *inNode->fValue.fSerializationData.fConstructorName, value);
			break;

		case eNODE_OBJECT: {

			XBOX::VJSObject	emptyObject(inContext);
			SEntry			entry;

			emptyObject.MakeEmpty();
			value.SetValueRef((JS4D::ValueRef) emptyObject.GetObjectRef());

			xbox_assert(ioAlreadyCreated->find(inNode->fValue.fReference) == ioAlreadyCreated->end());

			(*ioAlreadyCreated)[inNode] = value.GetValueRef();

			entry.fValueRef = value.GetValueRef();
			entry.fNode = inNode;
			ioToDoList->push_back(entry);

			break;

		}

		case eNODE_ARRAY: {

			XBOX::VJSArray	emptyArray(inContext);
			SEntry			entry;

			value.SetValueRef((JS4D::ValueRef) emptyArray.GetObjectRef());

			xbox_assert(ioAlreadyCreated->find(inNode->fValue.fReference) == ioAlreadyCreated->end());

			(*ioAlreadyCreated)[inNode] = value.GetValueRef();

			entry.fValueRef = value.GetValueRef();
			entry.fNode = inNode;
			ioToDoList->push_back(entry);
			
			break;

		}

		case eNODE_REFERENCE: {

			std::map<SNode *, JS4D::ValueRef>::iterator it;

			it = ioAlreadyCreated->find(inNode->fValue.fReference);
			xbox_assert(it != ioAlreadyCreated->end());

			value.SetValueRef(it->second);

			break;

		}

		default:

			xbox_assert(false);
			value.SetNull();
			break;
		
	}
	
	return value;
}
//       while(name[counnter] != null){ 
//           counter++;
//       }
// }
void writeFile(char* name, char* buffer, int secNum){
   int fileNameCounter =0;
      int i; 
     char mapArray [512];
     char directoryArray [512];
     char sectorBuffer [512];
     int emptyfileFound = 0;
      int bufferIndex = 0;
      int EmptySectorNumber;
      int j=0;
      int sectorNumber =0;
      readSector(mapArray,1);
      readSector(directoryArray,2); 
      
      for(i=0; i<512; i++){ 

       // checking for empty file

        if(directoryArray[i] != 0x00 && emptyfileFound == 0){
          i = i+31;
          
      
          
        }else{
          //printString("here2 \0");
        
          emptyfileFound =1;
        }
         if(directoryArray[i] == 0x0 && emptyfileFound ==1){ 
              // adding name of the file to the directory 

            if(fileNameCounter<6){  
                if(name[fileNameCounter]){
                  directoryArray[i] = name[fileNameCounter];
                  fileNameCounter++;
                }else{
                  //directoryArray[i]= 0x0;
                  fileNameCounter++;
                }
            } 
            else { 
               // adding the content of the file to the sector
                
                EmptySectorNumber = getTheFirstEmptySectorNumber(mapArray);
                if(secNum != 0){
                 
                  mapArray[EmptySectorNumber] = 0xFF;
                  directoryArray[i] = EmptySectorNumber;
                  for(j=0;j<512;j++){
                       
                     sectorBuffer[j]= buffer[(sectorNumber*32)+j];
                  }
                  writeSector(sectorBuffer,EmptySectorNumber);
                  EmptySectorNumber++;
                  secNum--;
                  bufferIndex++;
                  emptyArray(buffer);
                }else{
                 
                  break;
                }
            }
         }
      }
    writeSector(mapArray,1);
    writeSector(directoryArray,2);
}
示例#5
0
	//=================================================================
	bool TileAssembler::convertWorld()
	{

		#ifdef _ASSEMBLER_DEBUG
		#   ifdef _DEBUG
		::g_df = fopen("../TileAssembler_debug.txt", "wb");
		#   else
		::g_df = fopen("../TileAssembler_release.txt", "wb");
		#   endif
		#endif

		bool result = true;
		std::string fname = iSrcDir;
		fname.append("/");
		fname.append("dir");
		iCoordModelMapping->setModelNameFilterMethod(iFilterMethod);
		iCoordModelMapping->readCoordinateMapping(fname);

		Array<unsigned int> mapIds = iCoordModelMapping->getMaps();
		if(mapIds.size() == 0)
		{
			result = false;
		}
		for(int i=0; i<mapIds.size() && result; ++i)
		{
			unsigned int mapId = mapIds[i];

			#ifdef _ASSEMBLER_DEBUG
			if(mapId == 0)								// "Azeroth" just for debug
			{
				for(int x=28; x<29 && result; ++x)		//debug
				{
					for(int y=28; y<29 && result; ++y)
					{
						#else
						// ignore DeeprunTram (369) it is too large for short vector and not important
						// ignore test (13), Test (29) , development (451)
						if(mapId != 369 && mapId != 13 && mapId != 29 && mapId != 451)
						{
							for(int x=0; x<66 && result; ++x)
							{
								for(int y=0; y<66 && result; ++y)
								{
									#endif
									Array<ModelContainer*> mc;
									std::string dirname;
									char buffer[100];
									if(iCoordModelMapping->isWorldAreaMap(mapId) && x<65 && y<65)
									{
										sprintf(buffer, "%03u_%d_%d",mapId,x,y);
										dirname = std::string(buffer);
									}
									else
									{
										sprintf(buffer, "%03u",mapId);
										dirname = std::string(buffer);
									}
									result = fillModelContainerArray(dirname, mapId, x, y, mc);
									emptyArray(mc);
								}
							}
						}
					}
					#ifdef _ASSEMBLER_DEBUG
					if(::g_df) fclose(::g_df);
					#endif

					return result;
				}

				//=================================================================

				bool TileAssembler::fillModelContainerArray(const std::string& pDirFileName, unsigned int pMapId, int pXPos, int pYPos, Array<ModelContainer*>& pMC)
				{
					bool result = true;
					ModelContainer* modelContainer;

					NameCollection nameCollection = iCoordModelMapping->getFilenamesForCoordinate(pMapId, pXPos, pYPos);
					if(nameCollection.size() > 0)
					{
						result = false;
						char dirfilename[500];
						sprintf(dirfilename,"%s/%s.vmdir",iDestDir.c_str(),pDirFileName.c_str());
						FILE *dirfile = fopen(dirfilename, "ab");
						if(dirfile)
						{
							result = true;
							char destnamebuffer[500];
							char fullnamedestnamebuffer[500];
							if(nameCollection.iMainFiles.size() >0)
							{
								sprintf(destnamebuffer,"%03u_%i_%i.vmap",pMapId, pXPos, pYPos);
								std::string checkDoubleStr = std::string(dirfilename);
								checkDoubleStr.append("##");
								checkDoubleStr.append(std::string(destnamebuffer));
								// Check, if same file already is in the same dir file
								if(!iCoordModelMapping->isAlreadyProcessedSingleFile(checkDoubleStr))
								{
									iCoordModelMapping->addAlreadyProcessedSingleFile(checkDoubleStr);
									fprintf(dirfile, "%s\n",destnamebuffer);
									sprintf(fullnamedestnamebuffer,"%s/%s",iDestDir.c_str(),destnamebuffer);
									modelContainer = processNames(nameCollection.iMainFiles, fullnamedestnamebuffer);
									if(modelContainer)
									{
										pMC.append(modelContainer);
									}
									else
									{
										result = false;
									}
								}
							}
							// process the large singe files
							int pos = 0;
							while(result && (pos < nameCollection.iSingeFiles.size()))
							{
								std::string destFileName = iDestDir;
								destFileName.append("/");
								std::string dirEntryName = getDirEntryNameFromModName(pMapId,nameCollection.iSingeFiles[pos]);
								std::string checkDoubleStr = std::string(dirfilename);
								checkDoubleStr.append("##");
								checkDoubleStr.append(nameCollection.iSingeFiles[pos]);
								// Check, if same file already is in the same dir file
								if(!iCoordModelMapping->isAlreadyProcessedSingleFile(checkDoubleStr))
								{
									iCoordModelMapping->addAlreadyProcessedSingleFile(checkDoubleStr);
									fprintf(dirfile, "%s\n",dirEntryName.c_str());
									destFileName.append(dirEntryName);

									Array<std::string> positionarray;
									positionarray.append(nameCollection.iSingeFiles[pos]);

									if(!iCoordModelMapping->isAlreadyProcessedSingleFile(nameCollection.iSingeFiles[pos]))
									{
										modelContainer = processNames(positionarray, destFileName.c_str());
										iCoordModelMapping->addAlreadyProcessedSingleFile(nameCollection.iSingeFiles[pos]);
										if(modelContainer)
										{
											pMC.append(modelContainer);
										}
										else
										{
											result = false;
										}
									}
								}
								++pos;
							}
							fclose(dirfile);
						}
					}
					return(result);
				}

				//=================================================================

				void removeEntriesFromTree(AABSPTree<SubModel *>* pTree)
				{
					Array<SubModel *> submodelArray;
					pTree->getMembers(submodelArray);
					int no = submodelArray.size();
					while(no > 0)
					{
						--no;
						delete submodelArray[no];
					}
				}

				//=================================================================

				ModelContainer* TileAssembler::processNames(const Array<std::string>& pPositions, const char* pDestFileName)
				{
					ModelContainer *modelContainer = 0;

					Vector3 basepos = Vector3(0,0,0);
					AABSPTree<SubModel *>* mainTree = new AABSPTree<SubModel *>();

					int pos = 0;

					bool result = true;
					while(result && (pos < pPositions.size()))
					{
						std::string modelPosString = pPositions[pos];
						std::string modelFileName = getModNameFromModPosName(modelPosString);

						if(!fillModelIntoTree(mainTree, basepos, modelPosString, modelFileName))
						{
							result = false;
							break;
						}
						++pos;
					}
					if(result && mainTree->size() > 0)
					{
						mainTree->balance();
						modelContainer = new ModelContainer(mainTree);
						modelContainer->writeFile(pDestFileName);
					}
					removeEntriesFromTree(mainTree);

					delete mainTree;

					return(modelContainer);
				}
示例#6
0
 /// Construct a PicoJsonArray referencing an empty array.
 PicoJsonArray()
   : value(emptyArray()) { }
示例#7
0
 /// Construct a Json11Array referencing an empty array.
 Json11Array()
     : value(emptyArray()) { }
示例#8
0
文件: tris.c 项目: Giamp/lezioni
int main(){
    //imposta il seme del random al tempo attuale. Necessario per la funzione rand()
    srand(time(0));

    /*                                                                                  *\
    **  Ciclo principale, chiede la modalita' di gioco e inizializza il ciclo di gioco  **
    **  Decide casualmente il giocatore iniziale.                                       **
    \*                                                                                  */

    do{
        emptyArray(gameBoard);
        printf("Seleziona modalita:\n 0 -- umano vs pc\n 1 -- umano vs umano\n 2 -- pc vs pc\n");
        scanf("%d", &mod);
        if(mod == -1){
            break;
        }

        if(rand() % 2 + 1 == 1){
            turn = 1;
            printf("Giocatore 2 inizia per primo.\n");
        }
        else{
            turn = 0;
            printf("Giocatore 1 inizia per primo.\n");
        }

        /*                                                                                      *\
        **  Ciclo di gioco. Inizia cercando un vincitore.                                       **
        **  In base alla modalita' selezionata e al turno, richiede un input al giocatore umano **
        **  o calcola le mosse dell'IA.                                                         **
        **  Stampa il campo da gioco e infine controlla se il e' pieno                          **
        \*                                                                                      */

        do{
            if(checkForWinner(gameBoard) == 1 || checkForWinner(gameBoard) == 2){
                break;
            }

            if(turn == 0 && pc == 2 || turn == 1 && pc == 1){
                printf("-------------------\n");
                (mod == 0 || mod == 2) ? printf("Turno del computer\n") : printf("Turno del giocatore 1\n");
                printf("-------------------\n");

                if(mod == 1) printInstructions();

                (mod == 0 || mod == 2) ? (moveResult = elaborateMove(gameBoard, pc)) : (moveResult = makeMove(gameBoard, pc));
            }
            else if(turn == 0 && player == 2 || turn == 1 && player == 1){

                printf("-------------------\n");
                (mod == 2) ? printf("Turno del computer\n") : printf("Turno del giocatore 2\n");
                printf("-------------------\n");

                printInstructions();

                (mod == 2) ? (moveResult = elaborateMove(gameBoard, player)) : (moveResult = makeMove(gameBoard, player));
            }

            if(moveResult != -1){
                if(turn == 0){
                    turn = 1;
                }
                else{
                    turn = 0;
                }
            }
            else{
                printf("Partita terminata.\n");
                turn = -1;
            }

            createTable(gameBoard);

            if(gameBoardFull(gameBoard) && turn != -1){
                checkForWinner(gameBoard);
                turn = -1;
            }
        }while(turn != -1);
        turn = 0;
    }while(mod != -1);

    getchar();
}
示例#9
0
文件: tris.c 项目: Giamp/lezioni
int bestMove(int player, int gameBoard[BOARD_SIZE][BOARD_SIZE], int bestCell[2]){
    int mPriority[BOARD_SIZE][BOARD_SIZE];
    int i = 0, j = 0;
    int enemy;
    int highestPriority = 0;

    long rnd;   //Variabile per contenere il risultato della funzione rand()

    if(player == 1){
        enemy = 2;
    }
    else if(player == 2){
        enemy = 1;
    }

    emptyArray(mPriority);  //Inizializza l'array delle priorita' a 0 in ogni sua cella

    //I cicli controllano tutte le righe e colonne chiamando le funzioni checkRow e checkColumn

    for(i = 0; i < BOARD_SIZE; i++){
        ifLesserReplace(&highestPriority, checkRow(gameBoard, i, player, enemy, mPriority));

        for(j = 0; j < BOARD_SIZE; j++){
            ifLesserReplace(&highestPriority, checkColumn(gameBoard, j, player, enemy, mPriority));
        }
    }

    //Analisi delle diagonali tramite checkDiagonal

    ifLesserReplace(&highestPriority, checkDiagonal(gameBoard, player, enemy, mPriority));

    if(highestPriority >= 5){
        //Termina la partita
        return 5;
    }
    printf("Highest status: %d\n", highestPriority);

    //Inserisce in un array le mosse con priorita' massima

    int highestPriorityMoves[9];
    int highestPriorityMovesNumber = 0;


    for(i = 0; i < 3; i++){
        for(j = 0; j < 3; j++){
            if(mPriority[i][j] == highestPriority){
                /*La mossa e' memorizzata come un numero a 2 cifre
                  La prima cifra e' la x, la seconda la y           */
                highestPriorityMoves[highestPriorityMovesNumber] = (i * 10) + j;

                highestPriorityMovesNumber++;
            }/*Fine analisi mosse con priorita massima*/
        }
    }

    //Estrae un numero pseudo-randomico compreso fra 0 e il numero di mosse con priorita' piu' alta (escluso)

    rnd = rand() % highestPriorityMovesNumber;

    //Inizializza l'array contenete le coord. della mossa scelta

    //Se la mossa scelta e' un numero < 10 (ovvero la x era 0) imposta la x a 0, altrimenti la imposta come la prima cifra del numero
    (highestPriorityMoves[rnd] < 10) ? (bestCell[0] = 0) : (bestCell[0] = highestPriorityMoves[rnd] / 10);

    //Per la y invece, nel caso sia < 10 la y equivale al numero stesso, altrimenti equivale all'ultima cifra del numero
    (highestPriorityMoves[rnd] < 10) ? (bestCell[1] = highestPriorityMoves[rnd]) : (bestCell[1] = highestPriorityMoves[rnd] % 10);

    /*Fine analisi mossa migliore*/

    return 1;
}