// Takes two string sets and returns the union set. StringSet StringSet::Union(StringSet in_set) { StringSet result; for (int i = 0; i < this->Count(); ++i) result.Add(this->GetString(i)); for (int i = 0; i < in_set.Count(); ++i) if (!result.Contains(in_set.GetString(i))) result.Add(in_set.GetString(i)); return result; }
// Takes two string sets and returns the intersection set. StringSet StringSet::Intersection(StringSet in_set) { StringSet result; for (int i = 0; i < this->Count(); ++i) if (in_set.Contains(this->GetString(i))) result.Add(this->GetString(i)); return result; }
bool ClassAdCollection::CheckClassAd(BaseCollection* Coll,const MyString& OID, ClassAd* Ad) { if (Coll->Type()==PartitionParent_e) { PartitionParent* ParentColl=(PartitionParent*) Coll; StringSet Values; MyString AttrName; MyString AttrValue; ParentColl->Attributes.StartIterations(); // printf("Checking OID %s\n",OID.Value()); while (ParentColl->Attributes.Iterate(AttrName)) { ExprTree* expr=Ad->LookupExpr(AttrName.Value()); if (expr) { AttrValue = ExprTreeToString( expr ); } else { AttrValue = ""; } Values.Add(AttrValue); } // Values.StartIterations(); while (Values.Iterate(AttrValue)) { printf("Val: AttrValue=%s\n",AttrValue.Value()); } int CoID; PartitionChild* ChildColl=NULL; ParentColl->Children.StartIterations(); while (ParentColl->Children.Iterate(CoID)) { if (Collections.lookup(CoID,Coll)==-1) continue; ChildColl=(PartitionChild*) Coll; // ChildColl->Values.StartIterations(); while (ChildColl->Values.Iterate(AttrValue)) { printf("ChildVal: AttrValue=%s\n",AttrValue.Value()); } if (EqualSets(ChildColl->Values,Values)) break; ChildColl=NULL; } if (ChildColl==NULL) { // Create a new child collection ChildColl=new PartitionChild(ParentColl->Rank,Values); CoID=LastCoID+1; if (Collections.insert(CoID,ChildColl)==-1) return false; LastCoID=CoID; // Add to parent's children ParentColl->Children.Add(CoID); } // Add to child AddClassAd(CoID,OID,Ad); return false; } else { return Coll->CheckClassAd(Ad); } }
// Check the roms to see if they code, graphics etc are complete static int CheckRoms() { nBzipError = 0; // Assume romset is fine for (int i = 0; i < nRomCount; i++) { struct BurnRomInfo ri; memset(&ri, 0, sizeof(ri)); BurnDrvGetRomInfo(&ri, i); // Find information about the wanted rom if (ri.nCrc && (ri.nType & BRF_OPT) == 0 && (ri.nType & BRF_NODUMP)) { int nState = RomFind[i].nState; // Get the state of the rom in the zip file int nError = GetBZipError(nState); if (nState == 0 && ri.nType) { // (A type of 0 means empty slot - no rom) char* szName = "Unknown"; RomDescribe(&BzipDetail, &ri); BurnDrvGetRomName(&szName, i, 0); BzipDetail.Add(_T("%hs was not found.\n"), szName); } if (nError == 0) { nBzipError |= 0x2000; } if (ri.nType & BRF_ESS) { // essential rom - without it the game may not run at all nBzipError |= nError << 0; } if (ri.nType & BRF_PRG) { // rom which contains program information nBzipError |= nError << 1; } if (ri.nType & BRF_GRA) { // rom which contains graphics information nBzipError |= nError << 2; } if (ri.nType & BRF_SND) { // rom which contains sound information nBzipError |= nError << 3; } } } if (nBzipError & 0x0F0F) { nBzipError |= 0x4000; } return 0; }
// ZZZ: Set up a C-string in the repository; a repeated call will replace an old string void TS_PutCString(short ID, short Index, const char *String) { // Search for string set: (FindStringSet() creates a new one if necessary) StringSet *CurrStringSet = FindStringSet(ID); // Create a PString of the incoming CString, truncate to fit unsigned char thePStringStagingBuffer[256]; size_t theStringLength = strlen(String); if(theStringLength > 255) theStringLength = 255; // Fill in the string length. thePStringStagingBuffer[0] = (char)theStringLength; // Copy exactly the string bytes (no termination etc.) memcpy(&(thePStringStagingBuffer[1]), String, theStringLength); // Add() copies the string, so using the stack here is OK. CurrStringSet->Add(Index,thePStringStagingBuffer); }
// Check the roms to see if they code, graphics etc are complete static int CheckRoms() { nBzipError = 0; // Assume romset is fine for (int i = 0; i < nRomCount; i++) { struct BurnRomInfo ri; memset(&ri, 0, sizeof(ri)); BurnDrvGetRomInfo(&ri, i); // Find information about the wanted rom if (ri.nCrc && (ri.nType & 0x80) == 0) { int nState = RomFind[i].nState; // Get the state of the rom in the zip file if (nState == 0 && ri.nType) { // (A type of 0 means empty slot - no rom) char* szName = "Unknown"; RomDescribe(&BzipDetail, &ri); BurnDrvGetRomName(&szName, i, 0); BzipDetail.Add(_T("%hs was not found.\n"), szName); } if (ri.nType & 0x90) { // essential rom - without it the game may not run at all nBzipError |= GetBZipError(nState) << 0; } if (ri.nType & 0x01) { // rom which contains graphics information nBzipError |= GetBZipError(nState) << 1; } if (ri.nType & 0x02) { // rom which contains sound information nBzipError |= GetBZipError(nState) << 2; } } } if (!nZipsFound) { nBzipError |= 0x08; // No data at all! } return 0; }
int BzipOpen(bool bootApp) { int nMemLen; // Zip name number nZipsFound = 0; // Haven't found zips yet nTotalSize = 0; if (szBzipName == NULL) { return 1; } BzipClose(); // Make sure nothing is open if(!bootApp) { // reset information strings BzipText.Reset(); BzipDetail.Reset(); } // Count the number of roms needed for (nRomCount = 0; ; nRomCount++) { if (BurnDrvGetRomInfo(NULL, nRomCount)) { break; } } if (nRomCount <= 0) { return 1; } // Create an array for holding lookups for each rom -> zip entries nMemLen = nRomCount * sizeof(struct RomFind); RomFind = (struct RomFind*)malloc(nMemLen); if (RomFind == NULL) { return 1; } memset(RomFind, 0, nMemLen); for (int z = 0; z < BZIP_MAX; z++) { char* szName = NULL; if (BurnDrvGetZipName(&szName, z)) { break; } for (int d = 0; d < DIRS_MAX; d++) { free(szBzipName[z]); szBzipName[z] = (TCHAR*)malloc(MAX_PATH * sizeof(TCHAR)); _stprintf(szBzipName[z], _T("%s%hs"), szAppRomPaths[d], szName); if (ZipOpen(TCHARToANSI(szBzipName[z], NULL, 0)) == 0) { // Open the rom zip file nZipsFound++; nCurrentZip = z; break; } } if (nCurrentZip >= 0) { if (!bootApp) { BzipText.Add(_T("Found %s;\n"), szBzipName[z]); } ZipGetList(&List, &nListCount); // Get the list of entries for (int i = 0; i < nRomCount; i++) { struct BurnRomInfo ri; int nFind; if (RomFind[i].nState == 1) { // Already found this and it's okay continue; } memset(&ri, 0, sizeof(ri)); nFind = FindRom(i); if (nFind < 0) { // Couldn't find this rom at all continue; } RomFind[i].nZip = z; // Remember which zip file it is in RomFind[i].nPos = nFind; RomFind[i].nState = 1; // Set to found okay BurnDrvGetRomInfo(&ri, i); // Get info about the rom if ((ri.nType & BRF_OPT) == 0 && (ri.nType & BRF_NODUMP) == 0) { nTotalSize += ri.nLen; } if (List[nFind].nLen == ri.nLen) { if (ri.nCrc) { // If we know the CRC if (List[nFind].nCrc != ri.nCrc) { // Length okay, but CRC wrong RomFind[i].nState = 2; } } } else { if (List[nFind].nLen < ri.nLen) { RomFind[i].nState = 3; // Too small } else { RomFind[i].nState = 4; // Too big } } if (!bootApp) { if (RomFind[i].nState != 1) { RomDescribe(&BzipDetail, &ri); if (RomFind[i].nState == 2) { BzipDetail.Add(_T("%hs has a CRC of %.8X. (It should be %.8X.)\n"), GetFilenameA(List[nFind].szName), List[nFind].nCrc, ri.nCrc); } if (RomFind[i].nState == 3) { BzipDetail.Add(_T("%hs is %dk which is incomplete. (It should be %dkB.)\n"), GetFilenameA(List[nFind].szName), List[nFind].nLen >> 10, ri.nLen >> 10); } if (RomFind[i].nState == 4) { BzipDetail.Add(_T("%hs is %dk which is too big. (It should be %dkB.)\n"), GetFilenameA(List[nFind].szName), List[nFind].nLen >> 10, ri.nLen >> 10); } } } }
// Set up a string in the repository; a repeated call will replace an old string void TS_PutString(short ID, short Index, unsigned char *String) { // Search for string set: StringSet *CurrStringSet = FindStringSet(ID); CurrStringSet->Add(Index,String); }
TEST(StringSetTest, Count3Strings) { // Tests the count function. set.Add("String number 2."); set.Add("String number 3."); EXPECT_EQ(3, set.Count()); }
TEST(StringSetTest, AddString) { // Tests the addition of a simple string. set.Add(str); EXPECT_EQ(str, set.GetString(1)); }
TEST(StringSetTest, AddEmptyString) { // Tests the addition of the empty string. set.Add(empty); EXPECT_EQ(empty, set.GetString(0)); }
void AddOsModule(wxString mod) { osModules.Add(mod); theDatabase->reload(true); theMainWin->Reset(); }
void AddOsFunction(wxString function) { osFunctions.Add(function); theDatabase->reload(true); theMainWin->Reset(); }