void partition_list(List &list, int x) { if (list.Head() == NULL) { return; } List small; List large; Node *pre = list.Head(); while (pre != NULL) { if (pre->Data() <= x) { small.Append(pre->Data()); } else { large.Append(pre->Data()); } pre = pre->Next(); } if (small.Head() != NULL) { pre = small.Head(); while (pre->Next() != NULL) { pre = pre->Next(); } pre->SetNext(large.Head()); list.SetHead(small.Head()); } else { list.SetHead(large.Head()); } }
int main() { // New list List<int> list; // Append nodes to the list list.Append(100); list.Print(); list.Append(200); list.Print(); list.Append(300); list.Print(); list.Append(400); list.Print(); list.Append(500); list.Print(); // Delete nodes from the list list.Delete(400); list.Print(); list.Delete(300); list.Print(); list.Delete(200); list.Print(); list.Delete(500); list.Print(); list.Delete(100); list.Print(); return 0; }
void writeUandLToFile() { // wait for your turn if (rank != 0) { int predecessorDone = 0; MPI_Status status; MPI_Recv(&predecessorDone, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, &status); } List<Dimension*> *udimLengths = new List<Dimension*>; udimLengths->Append(&uDims[0]); udimLengths->Append(&uDims[1]); TypedOutputStream<double> *ustream = new TypedOutputStream<double>("/home/yan/u.bin", udimLengths, rank == 0); List<Dimension*> *ldimLengths = new List<Dimension*>; ldimLengths->Append(&lDims[0]); ldimLengths->Append(&lDims[1]); TypedOutputStream<double> *lstream = new TypedOutputStream<double>("/home/yan/l.bin", ldimLengths, rank == 0); List<int> *indexList = new List<int>; int blockStride = blockSize * processCount; int storeIndex = 0; ustream->open(); lstream->open(); for (int i = blockSize * rank; i < aDims[0].length; i+= blockStride) { int start = i; int end = start + blockSize - 1; if (end >= aDims[0].length) end = aDims[0].length - 1; for (int r = start; r <= end; r++) { for (int j = 0; j < aDims[1].length; j++) { indexList->clear(); indexList->Append(r); indexList->Append(j); ustream->writeElement(u[storeIndex], indexList); lstream->writeElement(l[storeIndex], indexList); storeIndex++; } } } ustream->close(); lstream->close(); delete indexList; delete ustream; delete lstream; // notify the next in line if (rank < processCount - 1) { int writingDone = 1; MPI_Send(&writingDone, 1, MPI_INT, rank + 1, 0, MPI_COMM_WORLD); } }
EXP void LinearizeCurve( int max_iter, const int n, const int p, Ptr< T > U, Ptr< HP > Pw, const T tol, const rtl<T>& t, int *ret_nP, Ptr< EP > *retP ) { List< ListNode<EP> > L; ListNode<EP> *node = new ListNode<EP>(euclid(Pw[0])); int i,nEl; Ptr< EP > P; L.Append( node ); LinearizeCurve( max_iter, n, p, U, Pw, tol, t, LinearizeLineCallback<EP>, (void *)&L ); nEl = L.nElems; node = L.head; P.reserve_pool( nEl ); for( i = 0; i < nEl; i++ ) { P[nEl-1-i] = node->el; node = node->next; } *ret_nP = nEl; *retP = P; L.DeleteElems(); }
Animation * Animation::AddAnimation(Object * source) const { if (GetState() == true) { ActiveAnimations.Append(new Animation); Animation * newAnim = ActiveAnimations.GetLast(); newAnim->Copy(*this); newAnim->source = source; const char * animScript = script.GetScript(); newAnim->script.LoadScript(animScript, newAnim); const char * onAddScript = onAdd.GetScript(); newAnim->onAdd.LoadScript(onAddScript, newAnim); newAnim->sprite = sprite; newAnim->bounds = bounds; newAnim->scalingCenter = scalingCenter; newAnim->rotationCenter = rotationCenter; newAnim->offset = offset; newAnim->color = color; newAnim->onAdd.ActivateScript(true); newAnim->SetUInt32Value(ANIM_VAR_START_TIME, GetGameTime()); return newAnim; } return NULL; }
int main() { List list; cout << "output1" << endl; list.OutputAllElements(); bool success; for ( int i = 0; i < 6; i++ ) { success = list.Append( i * 3 ); } cout << "output2" << endl; list.OutputAllElements(); cout << "Remove index 3" << endl; list.Remove( 3 ); list.OutputAllElements(); cout << list.GetItemAtPosition( 3 ) << endl; return 0; }
void readAFromFile(const char *filePath) { TypedInputStream<double> *stream = new TypedInputStream<double>(filePath); int storeIndex = 0; int blockStride = blockSize * processCount; List<int> *indexList = new List<int>; stream->open(); for (int i = 0; i < aDims[0].length; i++) { for (int j = blockSize * rank; j < aDims[1].length; j += blockStride) { int start = j; int end = start + blockSize - 1; if (end >= aDims[1].length) end = aDims[1].length - 1; for (int c = start; c <= end; c++) { indexList->clear(); indexList->Append(i); indexList->Append(c); a[storeIndex] = stream->readElement(indexList); storeIndex++; } } } stream->close(); delete indexList; delete stream; }
bool BoolTable:: GenerateMaxTrueABVList( List<AnnotatedBoolVector> &result ) { if( !initialized ) { return false; } AnnotatedBoolVector *abv; int frequency = 0; bool *seen = new bool[numCols]; bool *tempContexts = new bool[numCols]; for( int col = 0; col < numCols; col ++ ) { seen[col] = false; tempContexts[col] = false; } bool hasCommonTrue = false; // find maximum colTotalTrue value int maxTotalTrue = 0; for( int i = 0; i < numCols; i++ ) { if( colTotalTrue[i] > maxTotalTrue ) { maxTotalTrue = colTotalTrue[i]; } } // only create ABVs for cols with max colTotalTrue values for( int i = 0; i < numCols; i++ ) { if( colTotalTrue[i] == maxTotalTrue ) { // check initial if( !seen[i] ) { frequency = 1; tempContexts[i] = true; for( int j = i + 1; j < numCols; j++ ) { if( colTotalTrue[j] == maxTotalTrue ) { // check compare if( !seen[j] ){ CommonTrue( i, j, hasCommonTrue ); if( hasCommonTrue ) { frequency++; seen[j] = true; tempContexts[j] = true; } } } } abv = new AnnotatedBoolVector; abv->Init( numRows, numCols, frequency ); for( int row = 0; row < numRows; row++ ) { abv->SetValue( row, table[i][row] ); } for( int col = 0; col < numCols; col++ ) { abv->SetContext( col, tempContexts[col] ); tempContexts[col] = false; } result.Append( abv ); } } } delete [] seen; delete [] tempContexts; return true; }
bool BoolTable:: GenerateMaximalTrueBVList( List< BoolVector > &result ) { BoolVector *newBV = NULL; BoolVector *oldBV = NULL; for( int i = 0; i < numCols; i++ ) { newBV = new BoolVector( ); newBV->Init( numRows ); for( int row = 0; row < numRows; row++ ) { newBV->SetValue( row, table[i][row] ); } result.Rewind( ); bool addBV = true; bool isSubset = false; while( result.Next( oldBV ) ) { newBV->IsTrueSubsetOf( *oldBV, isSubset ); if( isSubset ) { addBV = false; break; } oldBV->IsTrueSubsetOf( *newBV, isSubset ); if( isSubset ) { result.DeleteCurrent( ); } } if( addBV ) { result.Append( newBV ); } else { delete newBV; } } return true; }
List<T> * List<T>::Clone() const // returns pointer to a copy of *this { List * clone = new List; clone->Append(*this); return clone; }
void main() { Recipe myRecipe1 = Recipe("Fish Filets in Hot Chili Oil"); Recipe myRecipe2 = Recipe("Boiled Fish with Pickled Cabbage and Chili "); Recipe myRecipe3 = Recipe("Coke Chicken"); Recipe myRecipe4 = Recipe("Fish ball soup"); List<Recipe>* myRecipeList = new List<Recipe>(); myRecipeList->Append(myRecipe1); myRecipeList->Append(myRecipe2); myRecipeList->Append(myRecipe3); myRecipeList->Append(myRecipe4); ListIterator<Recipe> myIterator = ListIterator<Recipe>(myRecipeList); for(myIterator.First(); !myIterator.IsDone(); myIterator.Next()) { myIterator.CurrentItem().Print(); } while(1) { ; } }
void AnimationMaintenance() { while (RemovedAnimations.GetSize() > 0) { if (RemovedAnimations[0] != NULL) { delete RemovedAnimations[0]; } RemovedAnimations.Remove(0); } ActiveAnimations.ToStart(); for (int32 i = 0; i < ActiveAnimations.GetSize(); i++) { Animation * animation = ActiveAnimations.GetCurrent(); Object * source = animation->GetSource(); ActiveAnimations.ToNext(); if ((source != NULL) && (source->GetState() == false)) { animation->SetSource(NULL); } if (animation != NULL) { if (animation->GetState() == false) { RemovedAnimations.Append(animation); ActiveAnimations.Remove(i); i--; } else { Object * source = animation->GetSource(); uint32 duration = animation->GetUInt32Value(ANIM_VAR_DURATION); uint32 startTime = animation->GetUInt32Value(ANIM_VAR_START_TIME); if (((duration == 0) && (source != NULL) && (source->GetState() == true)) || ((GetGameTime() - startTime) < duration)) { animation->ActivateScript(); } else { animation->Unload(); } } } else { ActiveAnimations.Remove(i); i--; } } }
void writeAToFile() { // wait for your turn if (rank != 0) { int predecessorDone = 0; MPI_Status status; MPI_Recv(&predecessorDone, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, &status); } List<Dimension*> *dimLengths = new List<Dimension*>; dimLengths->Append(&aDims[0]); dimLengths->Append(&aDims[1]); TypedOutputStream<double> *stream = new TypedOutputStream<double>("/home/yan/a-copy.bin", dimLengths, rank == 0); int storeIndex = 0; List<int> *indexList = new List<int>; int blockStride = blockSize * processCount; stream->open(); for (int i = 0; i < aDims[0].length; i++) { int aRow = i * aDims[1].length; for (int j = blockSize * rank; j < aDims[1].length; j += blockStride) { int start = j; int end = start + blockSize - 1; if (end >= aDims[1].length) end = aDims[1].length - 1; for (int c = start; c <= end; c++) { indexList->clear(); indexList->Append(i); indexList->Append(c); stream->writeElement(a[storeIndex], indexList); storeIndex++; } } } stream->close(); delete indexList; delete stream; // notify the next in line if (rank < processCount - 1) { int writingDone = 1; MPI_Send(&writingDone, 1, MPI_INT, rank + 1, 0, MPI_COMM_WORLD); } }
int main( ) { // New list List list; // Append nodes to the list list.Append( 100 ); list.Print( ); list.Append( 200 ); list.Print( ); list.Append( 300 ); list.Print( ); list.Append( 400 ); list.Print( ); list.Append( 500 ); list.Print( ); // Delete nodes from the list list.Delete( 400 ); list.Print( ); list.Delete( 300 ); list.Print( ); list.Delete( 200 ); list.Print( ); list.Delete( 500 ); list.Print( ); list.Delete( 100 ); list.Print( ); std::list<int> myList; myList.push_back( 5 ); myList.push_front( 3 ); myList.push_back( 9 ); myList.remove( 5 ); for ( auto it = myList.begin(); it != myList.end(); it++ ) cout << ( *it ) << endl; return 0; }
void GenericQuery:: copyStringCategory (List<char> &to, List<char> &from) { char *item; clearStringCategory (to); from.Rewind (); while ((item = from.Next ())) to.Append (new_strdup (item)); }
void writePToFile() { List<Dimension*> *dimLengths = new List<Dimension*>; dimLengths->Append(&pDims[0]); TypedOutputStream<int> *stream = new TypedOutputStream<int>("/home/yan/p.bin", dimLengths, true); stream->open(); for (int i = 0; i < pDims[0].length; i++) { stream->writeNextElement(p[i]); } stream->close(); delete stream; }
List<BusTour>* Search(BusTour query) { List<BusTour>* result = new List<BusTour>(); auto curr = Begin(); while (curr != nullptr) { if (Compare(curr->Data(), query) >= 50) result->Append(curr->Data()); curr = curr->Next(); } return result; }
int ScheddTransaction::queryJobAds(const char *constraint, List<ClassAd> &ads) { // XXX: Do this in a transaction (for ACID reasons) ClassAd *ad = GetNextJobByConstraint_as_ClassAd(constraint, 1); while (ad) { ads.Append(ad); ad = GetNextJobByConstraint_as_ClassAd(constraint, 0); } return 0; }
void Application::OpenDocument (const char* name) { if (!CanOpenDocument(name)) { // cannot handle this document return; } /* */ Document* doc = DoCreateDocument(); if (doc) { _docs->Append(*doc); AboutToOpenDocument(doc); doc->Open(); doc->DoRead(); } }
int main() { List hubList; string line,name,location; int number,i=0; ifstream hubfile ("Hub.csv"); if (hubfile.is_open()) { while ( getline (hubfile,line) ) { // Skip first line while(getline(hubfile,name,',')) { getline(hubfile,location,','); hubList.Append(name,location); } } hubList.Print(); hubfile.close(); } else {cout << "WARNING: Can't open file."; } getchar(); return 0; }
void printStartdNormal (ClassAd *ad, bool first) { if (first) { ppInit(); ppSetColumn(ATTR_NAME, wide_display ? -34 : -18, ! wide_display); if (javaMode) { ppSetColumn(ATTR_JAVA_VENDOR, -10, ! wide_display); ppSetColumn(ATTR_JAVA_VERSION, Lbl("Ver"), -6, ! wide_display); } else if (vmMode) { ppSetColumn(ATTR_VM_TYPE, Lbl("VmType"), -6, true); ppSetColumn(ATTR_VM_NETWORKING_TYPES, Lbl("Network"), -9, true); }else { ppSetColumn(ATTR_OPSYS, -10, true); ppSetColumn(ATTR_ARCH, -6, true); } ppSetColumn(ATTR_STATE, -9, true); ppSetColumn(ATTR_ACTIVITY, -8, true); //ppSetColumn(0, ATTR_LOAD_AVG, "%.3f ", false, invalid_fields_empty ? "" : "[???] "); //pm_head.Append(ATTR_LOAD_AVG); //pm_head.Append(wide_display ? ATTR_LOAD_AVG : "LoadAv"); //pm.registerFormat("%.3f ", wide_display ? 7 : 6, FormatOptionAutoWidth, ATTR_LOAD_AVG, invalid_fields_empty ? "" : "[???] "); ppSetColumn(ATTR_LOAD_AVG, Lbl("LoadAv"), formatLoadAvg, NULL, 6, true); if (vmMode) { ppSetColumn(ATTR_VM_MEMORY, Lbl("VMMem"), "%4d", false); } else { ppSetColumn(ATTR_MEMORY, Lbl("Mem"), "%4d", false); } pm_head.Append(wide_display ? "ActivityTime" : " ActvtyTime"); pm.registerFormat(NULL, 12, FormatOptionAutoWidth | (wide_display ? 0 : FormatOptionNoPrefix) | AltFixMe, formatActivityTime, ATTR_ENTERED_CURRENT_ACTIVITY /* " [Unknown]"*/); ppDisplayHeadings(stdout, ad, "\n"); } if (ad) pm.display (stdout, ad); }
int main() { /*IntNode* head = new IntNode(0); head->previous = head; head->next = head; for (int numberOfNodesToAdd = 1; numberOfNodesToAdd < 100; numberOfNodesToAdd++) { head->previous->AddAfter(new IntNode(numberOfNodesToAdd)); } print(head); printBackwards(head); */ List myList; myList.Append(1); myList.Append(2); cout << myList.At(0) << endl; cout << myList.At(1) << endl; //cout << myList.At(10) << endl; myList.Set(1, 20); cout << myList.At(0) << endl; cout << myList.At(1) << endl; myList.RemoveByValue(20); cout << myList.At(0) << endl; cout << myList.At(1) << endl; system("pause"); return 0; }
// Add a frame void AddFrame(FScope *fScope) { FrameInfo *frame = new FrameInfo; FScope *sScope; // Read image info sScope = fScope->GetFunction("Texture"); IFace::FScopeToTextureInfo(sScope, frame->tex); // Optional hotspot if ((sScope = fScope->GetFunction("Hotspot", FALSE)) != NULL) { frame->hotspot.x = sScope->NextArgInteger(); frame->hotspot.y = sScope->NextArgInteger(); } else { frame->hotspot.Set(0, 0); } // Add frame to list frames.Append(frame); }
int Job::get_spool_list(List<FileInfo> &file_list, CondorError &errstack) { StatInfo directoryInfo(spoolDirectory.Value()); if (directoryInfo.IsDirectory()) { Directory directory(spoolDirectory.Value()); const char * name; FileInfo *info; while (NULL != (name = directory.Next())) { info = new FileInfo(); info->initialize(name, directory.GetFileSize()); ASSERT(info); if (!file_list.Append(info)) { errstack.pushf("SOAP", FAIL, "Error adding %s to file list.", name); return 2; } } return 0; } else { dprintf(D_ALWAYS, "spoolDirectory == '%s'\n", spoolDirectory.Value()); errstack.pushf("SOAP", FAIL, "spool directory '%s' is not actually a directory.", spoolDirectory.Value()); return 1; } }
FD FS_Open(const char* filename, int flags) { int mode; int oflags; int fd; mode = S_IRUSR | S_IWUSR; oflags = 0; if ((flags & FS_CREATE) == FS_CREATE) oflags |= O_CREAT; if ((flags & FS_READWRITE) == FS_READWRITE) oflags |= O_RDWR; if ((flags & FS_READONLY) == FS_READONLY) oflags |= O_RDONLY; if ((flags & FS_WRITEONLY) == FS_WRITEONLY) oflags |= O_WRONLY; if ((flags & FS_APPEND) == FS_APPEND) oflags |= O_APPEND; #ifdef PLATFORM_LINUX if ((flags & FS_DIRECT) == FS_DIRECT) oflags |= O_DIRECT; #endif fd = open(filename, oflags, mode); if (fd < 0) { Log_Errno("%s", filename); return INVALID_FD; } globalMutex.Lock(); fileHandles.Append(fd); dirtyFiles[fd] = false; globalMutex.Unlock(); return fd; }
int Push(T node) { // 进栈操作 return list.Append(node); }
void Init() { pid_t schedd_pid; // schedd address may be overridden by a commandline option // only set it if it hasn't been set already if ( ScheddAddr == NULL ) { schedd_pid = daemonCore->getppid(); char const *tmp = daemonCore->InfoCommandSinfulString( schedd_pid ); if ( tmp == NULL ) { EXCEPT( "Failed to determine schedd's address" ); } else { ScheddAddr = strdup( tmp ); } } const char *val = getenv( "SCHEDD_NAME" ); if ( val ) { ScheddName = strdup( val ); } else { ScheddName = strdup( "" ); } if ( ScheddObj == NULL ) { ScheddObj = new DCSchedd( ScheddAddr ); ASSERT( ScheddObj ); if ( ScheddObj->locate() == false ) { EXCEPT( "Failed to locate schedd: %s", ScheddObj->error() ); } } // read config file // initialize variables if ( GridmanagerScratchDir == NULL ) { EXCEPT( "Schedd didn't specify scratch dir with -S" ); } if ( InitializeProxyManager( GridmanagerScratchDir ) == false ) { EXCEPT( "Failed to initialize Proxymanager" ); } JobType *new_type; #if !defined(WIN32) new_type = new JobType; new_type->Name = strdup( "Cream" ); new_type->InitFunc = CreamJobInit; new_type->ReconfigFunc = CreamJobReconfig; new_type->AdMatchFunc = CreamJobAdMatch; new_type->CreateFunc = CreamJobCreate; jobTypes.Append( new_type ); #endif new_type = new JobType; new_type->Name = strdup( "Nordugrid" ); new_type->InitFunc = NordugridJobInit; new_type->ReconfigFunc = NordugridJobReconfig; new_type->AdMatchFunc = NordugridJobAdMatch; new_type->CreateFunc = NordugridJobCreate; jobTypes.Append( new_type ); #if defined( LINUX ) || defined(DARWIN) || defined(WIN32) new_type = new JobType; new_type->Name = strdup( "EC2" ); new_type->InitFunc = EC2JobInit; new_type->ReconfigFunc = EC2JobReconfig; new_type->AdMatchFunc = EC2JobAdMatch; new_type->CreateFunc = EC2JobCreate; jobTypes.Append( new_type ); new_type = new JobType; new_type->Name = strdup( "GCE" ); new_type->InitFunc = GCEJobInit; new_type->ReconfigFunc = GCEJobReconfig; new_type->AdMatchFunc = GCEJobAdMatch; new_type->CreateFunc = GCEJobCreate; jobTypes.Append( new_type ); #endif new_type = new JobType; new_type->Name = strdup( "Unicore" ); new_type->InitFunc = UnicoreJobInit; new_type->ReconfigFunc = UnicoreJobReconfig; new_type->AdMatchFunc = UnicoreJobAdMatch; new_type->CreateFunc = UnicoreJobCreate; jobTypes.Append( new_type ); new_type = new JobType; new_type->Name = strdup( "INFNBatch" ); new_type->InitFunc = INFNBatchJobInit; new_type->ReconfigFunc = INFNBatchJobReconfig; new_type->AdMatchFunc = INFNBatchJobAdMatch; new_type->CreateFunc = INFNBatchJobCreate; jobTypes.Append( new_type ); new_type = new JobType; new_type->Name = strdup( "BOINC" ); new_type->InitFunc = BoincJobInit; new_type->ReconfigFunc = BoincJobReconfig; new_type->AdMatchFunc = BoincJobAdMatch; new_type->CreateFunc = BoincJobCreate; jobTypes.Append( new_type ); new_type = new JobType; new_type->Name = strdup( "Condor" ); new_type->InitFunc = CondorJobInit; new_type->ReconfigFunc = CondorJobReconfig; new_type->AdMatchFunc = CondorJobAdMatch; new_type->CreateFunc = CondorJobCreate; jobTypes.Append( new_type ); new_type = new JobType; new_type->Name = strdup( "Globus" ); new_type->InitFunc = GlobusJobInit; new_type->ReconfigFunc = GlobusJobReconfig; new_type->AdMatchFunc = GlobusJobAdMatch; new_type->CreateFunc = GlobusJobCreate; jobTypes.Append( new_type ); jobTypes.Rewind(); while ( jobTypes.Next( new_type ) ) { new_type->InitFunc(); } }
INavMesh *NavMeshLoader::Load(char *error, int errorMaxlen) { strcpy_s(error, errorMaxlen, ""); char navPath[1024]; g_pSM->BuildPath(Path_Game, navPath, sizeof(navPath), "maps\\%s.nav", this->mapName); FILE *fileHandle = fopen(navPath, "rb"); if(!fileHandle) { sprintf_s(error, errorMaxlen, "Unable to find navigation mesh: %s", navPath); return NULL; } unsigned int magicNumber; int elementsRead = this->ReadData(&magicNumber, sizeof(unsigned int), 1, fileHandle); if(elementsRead != 1) { fclose(fileHandle); sprintf_s(error, errorMaxlen, "Error reading magic number value from navigation mesh: %s", navPath); return NULL; } if(magicNumber != 0xFEEDFACE) { fclose(fileHandle); sprintf_s(error, errorMaxlen, "Invalid magic number value from navigation mesh: %s [%p]", navPath, magicNumber); return NULL; } unsigned int version; elementsRead = this->ReadData(&version, sizeof(unsigned int), 1, fileHandle); if(elementsRead != 1) { fclose(fileHandle); sprintf_s(error, errorMaxlen, "Error reading version number from navigation mesh: %s", navPath); return NULL; } if (version < 6 || version > 16) { fclose(fileHandle); sprintf_s(error, errorMaxlen, "Invalid version number value from navigation mesh: %s [%d]", navPath, version); return NULL; } unsigned int navMeshSubVersion = 0; if(version >= 10) { this->ReadData(&navMeshSubVersion, sizeof(unsigned int), 1, fileHandle); } unsigned int saveBspSize; this->ReadData(&saveBspSize, sizeof(unsigned int), 1, fileHandle); char bspPath[1024]; g_pSM->BuildPath(Path_Game, bspPath, sizeof(bspPath), "maps\\%s.bsp", this->mapName); unsigned int actualBspSize = 0; #ifdef PLATFORM_WINDOWS struct _stat s; _stat(bspPath, &s); actualBspSize = s.st_size; #elif defined PLATFORM_POSIX struct stat s; stat(bspPath, &s); actualBspSize = s.st_size; #endif if(actualBspSize != saveBspSize) { META_CONPRINTF("WARNING: Navigation mesh was not built with the same version of the map [%d vs %d].\n", actualBspSize, saveBspSize); } unsigned char meshAnalyzed = 0; if(version >= 14) { this->ReadData(&meshAnalyzed, sizeof(unsigned char), 1, fileHandle); } bool isMeshAnalyzed = meshAnalyzed != 0; //META_CONPRINTF("Is mesh analyzed: %s\n", isMeshAnalyzed ? "yes" : "no"); unsigned short placeCount; this->ReadData(&placeCount, sizeof(unsigned short), 1, fileHandle); //META_CONPRINTF("Nav version: %d; BSPSize: %d; MagicNumber: %p; SubVersion: %d [v10+only]; Place Count: %d\n", version, saveBspSize, magicNumber, navMeshSubVersion, placeCount); List<INavMeshPlace*> *places = new List<INavMeshPlace*>(); for(unsigned int placeIndex = 0; placeIndex < placeCount; placeIndex++) { unsigned short placeSize; this->ReadData(&placeSize, sizeof(unsigned short), 1, fileHandle); char placeName[256]; this->ReadData(placeName, sizeof(unsigned char), placeSize, fileHandle); places->Append(new NavMeshPlace(placeIndex, placeName)); //META_CONPRINTF("Parsed place: %s [%d]\n", placeName, placeIndex); } unsigned char unnamedAreas = 0; if(version > 11) { this->ReadData(&unnamedAreas, sizeof(unsigned char), 1, fileHandle); } bool hasUnnamedAreas = unnamedAreas != 0; //META_CONPRINTF("Has unnamed areas: %s\n", hasUnnamedAreas ? "yes" : "no"); IList<INavMeshArea*> *areas = new List<INavMeshArea*>(); unsigned int areaCount; this->ReadData(&areaCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Area count: %d\n", areaCount); for(unsigned int areaIndex = 0; areaIndex < areaCount; areaIndex++) { unsigned int areaID; float x1, y1, z1, x2, y2, z2; unsigned int areaFlags = 0; IList<INavMeshConnection*> *connections = new List<INavMeshConnection*>(); IList<INavMeshHidingSpot*> *hidingSpots = new List<INavMeshHidingSpot*>(); IList<INavMeshEncounterPath*> *encounterPaths = new List<INavMeshEncounterPath*>(); IList<INavMeshLadderConnection*> *ladderConnections = new List<INavMeshLadderConnection*>(); IList<INavMeshCornerLightIntensity*> *cornerLightIntensities = new List<INavMeshCornerLightIntensity*>(); IList<INavMeshVisibleArea*> *visibleAreas = new List<INavMeshVisibleArea*>(); unsigned int inheritVisibilityFrom = 0; unsigned char hidingSpotCount = 0; unsigned int visibleAreaCount = 0; float earliestOccupyTimeFirstTeam = 0.0f; float earliestOccupyTimeSecondTeam = 0.0f; float northEastCornerZ; float southWestCornerZ; unsigned short placeID = 0; unsigned char unk01 = 0; this->ReadData(&areaID, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Area ID: %d\n", areaID); if(version <= 8) { this->ReadData(&areaFlags, sizeof(unsigned char), 1, fileHandle); } else if(version < 13) { this->ReadData(&areaFlags, sizeof(unsigned short), 1, fileHandle); } else { this->ReadData(&areaFlags, sizeof(unsigned int), 1, fileHandle); } //META_CONPRINTF("Area Flags: %d\n", areaFlags); this->ReadData(&x1, sizeof(float), 1, fileHandle); this->ReadData(&y1, sizeof(float), 1, fileHandle); this->ReadData(&z1, sizeof(float), 1, fileHandle); this->ReadData(&x2, sizeof(float), 1, fileHandle); this->ReadData(&y2, sizeof(float), 1, fileHandle); this->ReadData(&z2, sizeof(float), 1, fileHandle); //META_CONPRINTF("Area extent: (%f, %f, %f), (%f, %f, %f)\n", x1, y1, z1, x2, y2, z2); this->ReadData(&northEastCornerZ, sizeof(float), 1, fileHandle); this->ReadData(&southWestCornerZ, sizeof(float), 1, fileHandle); //META_CONPRINTF("Corners: NW(%f), SW(%f)\n", northEastCornerZ, southWestCornerZ); // CheckWaterLevel() are we underwater in this area? for(unsigned int direction = 0; direction < NAV_DIR_COUNT; direction++) { unsigned int connectionCount; this->ReadData(&connectionCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Connection count: %d (%p)\n", connectionCount, connectionCount); for(int connectionIndex = 0; connectionIndex < connectionCount; connectionIndex++) { unsigned int connectingAreaID; this->ReadData(&connectingAreaID, sizeof(unsigned int), 1, fileHandle); INavMeshConnection *connection = new NavMeshConnection(connectingAreaID, (NavDirType)direction); connections->Append(connection); } } this->ReadData(&hidingSpotCount, sizeof(unsigned char), 1, fileHandle); //META_CONPRINTF("Hiding Spot Count: %d\n", hidingSpotCount); for(unsigned int hidingSpotIndex = 0; hidingSpotIndex < hidingSpotCount; hidingSpotIndex++) { unsigned int hidingSpotID; this->ReadData(&hidingSpotID, sizeof(unsigned int), 1, fileHandle); float hidingSpotX, hidingSpotY, hidingSpotZ; this->ReadData(&hidingSpotX, sizeof(float), 1, fileHandle); this->ReadData(&hidingSpotY, sizeof(float), 1, fileHandle); this->ReadData(&hidingSpotZ, sizeof(float), 1, fileHandle); unsigned char hidingSpotFlags; this->ReadData(&hidingSpotFlags, sizeof(unsigned char), 1, fileHandle); INavMeshHidingSpot *hidingSpot = new NavMeshHidingSpot(hidingSpotID, hidingSpotX, hidingSpotY, hidingSpotZ, hidingSpotFlags); hidingSpots->Append(hidingSpot); //META_CONPRINTF("Parsed hiding spot (%f, %f, %f) with ID [%p] and flags [%p]\n", hidingSpotX, hidingSpotY, hidingSpotZ, hidingSpotID, hidingSpotFlags); } // These are old but we just need to read the data. if(version < 15) { unsigned char approachAreaCount; this->ReadData(&approachAreaCount, sizeof(unsigned char), 1, fileHandle); for(unsigned int approachAreaIndex = 0; approachAreaIndex < approachAreaCount; approachAreaIndex++) { unsigned int approachHereID; this->ReadData(&approachHereID, sizeof(unsigned int), 1, fileHandle); unsigned int approachPrevID; this->ReadData(&approachPrevID, sizeof(unsigned int), 1, fileHandle); unsigned char approachType; this->ReadData(&approachType, sizeof(unsigned char), 1, fileHandle); unsigned int approachNextID; this->ReadData(&approachNextID, sizeof(unsigned int), 1, fileHandle); unsigned char approachHow; this->ReadData(&approachHow, sizeof(unsigned char), 1, fileHandle); } } unsigned int encounterPathCount; this->ReadData(&encounterPathCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Encounter Path Count: %d\n", encounterPathCount); for(unsigned int encounterPathIndex = 0; encounterPathIndex < encounterPathCount; encounterPathIndex++) { unsigned int encounterFromID; this->ReadData(&encounterFromID, sizeof(unsigned int), 1, fileHandle); unsigned char encounterFromDirection; this->ReadData(&encounterFromDirection, sizeof(unsigned char), 1, fileHandle); unsigned int encounterToID; this->ReadData(&encounterToID, sizeof(unsigned int), 1, fileHandle); unsigned char encounterToDirection; this->ReadData(&encounterToDirection, sizeof(unsigned char), 1, fileHandle); unsigned char encounterSpotCount; this->ReadData(&encounterSpotCount, sizeof(unsigned char), 1, fileHandle); //META_CONPRINTF("Encounter [from ID %d] [from dir %p] [to ID %d] [to dir %p] [spot count %d]\n", encounterFromID, encounterFromDirection, encounterToID, encounterToDirection, encounterSpotCount); IList<INavMeshEncounterSpot*> *encounterSpots = new List<INavMeshEncounterSpot*>(); for(int encounterSpotIndex = 0; encounterSpotIndex < encounterSpotCount; encounterSpotIndex++) { unsigned int encounterSpotOrderId; this->ReadData(&encounterSpotOrderId, sizeof(unsigned int), 1, fileHandle); unsigned char encounterSpotT; this->ReadData(&encounterSpotT, sizeof(unsigned char), 1, fileHandle); float encounterSpotParametricDistance = (float)encounterSpotT / 255.0f; INavMeshEncounterSpot *encounterSpot = new NavMeshEncounterSpot(encounterSpotOrderId, encounterSpotParametricDistance); encounterSpots->Append(encounterSpot); //META_CONPRINTF("Encounter spot [order id %d] and [T %p]\n", encounterSpotOrderId, encounterSpotT); } INavMeshEncounterPath *encounterPath = new NavMeshEncounterPath(encounterFromID, (NavDirType)encounterFromDirection, encounterToID, (NavDirType)encounterToDirection, encounterSpots); encounterPaths->Append(encounterPath); } this->ReadData(&placeID, sizeof(unsigned short), 1, fileHandle); //META_CONPRINTF("Place ID: %d\n", placeID); for(unsigned int ladderDirection = 0; ladderDirection < NAV_LADDER_DIR_COUNT; ladderDirection++) { unsigned int ladderConnectionCount; this->ReadData(&ladderConnectionCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Ladder Connection Count: %d\n", ladderConnectionCount); for(unsigned int ladderConnectionIndex = 0; ladderConnectionIndex < ladderConnectionCount; ladderConnectionIndex++) { unsigned int ladderConnectID; this->ReadData(&ladderConnectID, sizeof(unsigned int), 1, fileHandle); INavMeshLadderConnection *ladderConnection = new NavMeshLadderConnection(ladderConnectID, (NavLadderDirType)ladderDirection); ladderConnections->Append(ladderConnection); //META_CONPRINTF("Parsed ladder connect [ID %d]\n", ladderConnectID); } } this->ReadData(&earliestOccupyTimeFirstTeam, sizeof(float), 1, fileHandle); this->ReadData(&earliestOccupyTimeSecondTeam, sizeof(float), 1, fileHandle); if(version >= 11) { for (int navCornerIndex = 0; navCornerIndex < NAV_CORNER_COUNT; navCornerIndex++) { float navCornerLightIntensity; this->ReadData(&navCornerLightIntensity, sizeof(float), 1, fileHandle); INavMeshCornerLightIntensity *cornerLightIntensity = new NavMeshCornerLightIntensity((NavCornerType)navCornerIndex, navCornerLightIntensity); cornerLightIntensities->Append(cornerLightIntensity); //META_CONPRINTF("Light intensity: [%f] [idx %d]\n", navCornerLightIntensity, navCornerIndex); } if(version >= 16) { this->ReadData(&visibleAreaCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Visible area count: %d\n", visibleAreaCount); for(unsigned int visibleAreaIndex = 0; visibleAreaIndex < visibleAreaCount; visibleAreaIndex++) { unsigned int visibleAreaID; this->ReadData(&visibleAreaID, sizeof(unsigned int), 1, fileHandle); unsigned char visibleAreaAttributes; this->ReadData(&visibleAreaAttributes, sizeof(unsigned char), 1, fileHandle); INavMeshVisibleArea *visibleArea = new NavMeshVisibleArea(visibleAreaID, visibleAreaAttributes); visibleAreas->Append(visibleArea); //META_CONPRINTF("Parsed visible area [%d] with attr [%p]\n", visibleAreaID, visibleAreaAttributes); } this->ReadData(&inheritVisibilityFrom, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Inherit visibilty from: %d\n", inheritVisibilityFrom); this->ReadData(&unk01, sizeof(unsigned char), 1, fileHandle); } } INavMeshArea *area = new NavMeshArea(areaID, areaFlags, placeID, x1, y1, z1, x2, y2, z2, northEastCornerZ, southWestCornerZ, connections, hidingSpots, encounterPaths, ladderConnections, cornerLightIntensities, visibleAreas, inheritVisibilityFrom, earliestOccupyTimeFirstTeam, earliestOccupyTimeSecondTeam, unk01); areas->Append(area); } unsigned int ladderCount; this->ReadData(&ladderCount, sizeof(unsigned int), 1, fileHandle); //META_CONPRINTF("Ladder count: %d\n", ladderCount); IList<INavMeshLadder*> *ladders = new List<INavMeshLadder*>(); for(unsigned int ladderIndex = 0; ladderIndex < ladderCount; ladderIndex++) { unsigned int ladderID; this->ReadData(&ladderID, sizeof(unsigned int), 1, fileHandle); float ladderWidth; this->ReadData(&ladderWidth, sizeof(float), 1, fileHandle); float ladderTopX, ladderTopY, ladderTopZ, ladderBottomX, ladderBottomY, ladderBottomZ; this->ReadData(&ladderTopX, sizeof(float), 1, fileHandle); this->ReadData(&ladderTopY, sizeof(float), 1, fileHandle); this->ReadData(&ladderTopZ, sizeof(float), 1, fileHandle); this->ReadData(&ladderBottomX, sizeof(float), 1, fileHandle); this->ReadData(&ladderBottomY, sizeof(float), 1, fileHandle); this->ReadData(&ladderBottomZ, sizeof(float), 1, fileHandle); float ladderLength; this->ReadData(&ladderLength, sizeof(float), 1, fileHandle); unsigned int ladderDirection; this->ReadData(&ladderDirection, sizeof(unsigned int), 1, fileHandle); unsigned int ladderTopForwardAreaID; this->ReadData(&ladderTopForwardAreaID, sizeof(unsigned int), 1, fileHandle); unsigned int ladderTopLeftAreaID; this->ReadData(&ladderTopLeftAreaID, sizeof(unsigned int), 1, fileHandle); unsigned int ladderTopRightAreaID; this->ReadData(&ladderTopRightAreaID, sizeof(unsigned int), 1, fileHandle); unsigned int ladderTopBehindAreaID; this->ReadData(&ladderTopBehindAreaID, sizeof(unsigned int), 1, fileHandle); unsigned int ladderBottomAreaID; this->ReadData(&ladderBottomAreaID, sizeof(unsigned int), 1, fileHandle); INavMeshLadder *ladder = new NavMeshLadder(ladderID, ladderWidth, ladderLength, ladderTopX, ladderTopY, ladderTopZ, ladderBottomX, ladderBottomY, ladderBottomZ, (NavDirType)ladderDirection, ladderTopForwardAreaID, ladderTopLeftAreaID, ladderTopRightAreaID, ladderTopBehindAreaID, ladderBottomAreaID); ladders->Append(ladder); } fclose(fileHandle); INavMesh *mesh = new NavMesh(magicNumber, version, navMeshSubVersion, saveBspSize, isMeshAnalyzed, places, areas, ladders); return mesh; }
void print_reftrace (const char * act, const char * typname, int refcount, bool keep) { #ifdef HAVE_UNWIND unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp, bp; unw_getcontext(&uc); unw_init_local(&cursor, &uc); char framename [1024]; Frame *frame; List *frames = new List (); int count = 0; while (unw_step(&cursor) > 0 && count < get_max_frames ()) { frame = new Frame (); unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); #if (__i386__) unw_get_reg(&cursor, UNW_X86_EBP, &bp); #elif (__amd64__) unw_get_reg(&cursor, UNW_X86_64_RBP, &bp); #endif unw_get_proc_name (&cursor, framename, sizeof(framename), 0); if (!*framename) { if (mono_domain_get ()) { frame->ptr = (long)ip; char * ret = get_method_name_from_ip ((void*)ip); frame->name = g_strdup (ret); g_free (ret); frame->type = MONO; } else { delete frame; continue; } } else { char * demangled = cplus_demangle (framename, 0); if (demangled) { if (strstr (demangled, ":") > 0) { frame->ptr = *(int*)(bp+8); frame->name = g_strdup (demangled); frame->type = INSTANCE; } else { frame->ptr = (long)bp; frame->name = g_strdup (demangled); frame->type = STATIC; } } else { frame->ptr = (long)bp; frame->name = g_strdup (framename); frame->type = C; } } frames->Append (frame); count++; } if (keep) { if (allframes == NULL) allframes = new List (); if (allframes->Length() % 50) dump_frames (); Frames *f = new Frames (); f->list = frames; f->act = g_strdup (act); f->typname = g_strdup (typname); f->refcount = refcount; allframes->Append (f); } else { printf("trace:%s|%s|%d;", act, typname,refcount); frame = (Frame*)frames->First (); while (frame != NULL) { char *s = frame->ToString (); printf ("%s;", s); g_free(s); frame = (Frame*)frame->next; } printf ("\n"); delete frames; } #endif }
int main() { List<int> MyList; int nSelected; bool IsQuit = false; while(!IsQuit) { cout << "请输入链表操作指令: " << endl; cout << "1. 打印链表节点数 " << endl; cout << "2. 打印链表所有节点数据 " << endl; cout << "3. 在指定ID的节点后插入一个新节点 " << endl; cout << "4. 删除指定的数据 " << endl; cout << "5. 在链表最后插入一个新节点" << endl; cout << "6. 清空链表" << endl; cout << "7. 链表排序" << endl; cout << "8. 退出 " << endl; cin >> nSelected; switch(nSelected) { case 1: cout << "链表当前长度为:" << endl; cout << MyList.Length() << endl; break; case 2: cout << "链表当前数据为:" << endl; for(int i = 1; i <= MyList.Length(); i++) { cout << MyList.FindPosition(i) << " "; } cout << endl; break; case 3: cout << "请输入需要插入的位置:" << endl; int new_position; cin >> new_position; cout << "请输入需要插入的数据:" << endl; int new_data; cin >> new_data; MyList.Insert(new_data, new_position); break; case 4: cout << "请输入删除的数据:" << endl; int del_data; cin >> del_data; MyList.Delete(del_data); break; case 5: cout << "请输入需要在链表末尾添加的数据:" << endl; int append_data; cin >> append_data; MyList.Append(append_data); break; case 6: cout << "清空链表" << endl; MyList.MakeEmpty(); break; case 7: cout << "链表排序" << endl; MyList.ListSort(); break; case 8: IsQuit = true; break; default: cout << "此操作无效,请重新选择!" <<endl; break; } } return 0; }