Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
template <class T> struct STListEntry { T* Object; char* pcObjectPath; char* pcAddInf1; char* pcAddInf2; inline STListEntry() {Object = NULL; pcObjectPath = NULL, pcAddInf1 = NULL, pcAddInf2 = NULL;} inline ~STListEntry() {delete Object; delete[] pcObjectPath; delete[] pcAddInf1; delete[] pcAddInf2;} }; template <class T> class TMemoryManager { private: static STListEntry<T>* pObjectList; static int iObjectCount; protected: static T* GetListMember(char* pcObjectPath, char* pcAddInf1, char* pcAddInf2) { //Die Liste durchgehen for (int i = 0; i < iObjectCount; i++) if (pObjectList[i].pcObjectPath == pcObjectPath) //Sind die ZusatzInfos identisch, bzw egal (== NULL) if ((pcAddInf1 == NULL || strcmp(pObjectList[i].pcAddInf1, pcAddInf1) == 0) && (pcAddInf2 == NULL || strcmp(pObjectList[i].pcAddInf2, pcAddInf2) == 0)) //dann gefundenes Objekt zurückgeben return pObjectList[i].Object; //ansonsten kein Objekt übereinstimmend: return NULL; } public: static void InsertEntry(T* Object, char* pcObjectPath, char* pcAddInf1, char* pcAddInf2) { iObjectCount++; pObjectList = tbMemReAlloc(pObjectList, iObjectCount*sizeof(STListEntry<T>)); pObjectList[iObjectCount].Object = Object; //Zuweisen der Strings: pObjectList[iObjectCount].pcObjectPath = new char[255]; pObjectList[iObjectCount].pcAddInf1 = new char[255]; pObjectList[iObjectCount].pcAddInf2 = new char[255]; strcpy(pObjectList[iObjectCount].pcObjectPath, pcObjectPath); strcpy(pObjectList[iObjectCount].pcAddInf1, pcAddInf1); strcpy(pObjectList[iObjectCount].pcAddInf2, pcAddInf2); } //Setzt vorraus, dass die chars zugewiesenen Speicher haben, im Normalfall char* = new char[255] static void GetChars(T* Object, char* pcObjectPath, char* pcAddInf1, char* pcAddInf2) { for (int i = 0; i < iObjectCount; i++) if (Object == pObjectList[i].Object) { strcpy(pcObjectPath, pObjectList[i].pcObjectPath); strcpy(pcAddInf1, pObjectList[i].AddInf1); strcpy(pcAddInf2, pObjectList[i].AddInf2); break; } } static void Release() { tbMemFree(pObjectList); } }; //******************************************************* class CEffectManager : public TMemoryManager<tbEffect> { public: static tbEffect* GetEntry(char* pcObjectPath, char* pcAddInf1, char* pcAddInf2) { tbEffect* Effect = GetListMember(pcObjectPath, pcAddInf1, pcAddInf2); if (Effect == NULL) { Effect->Init(pcObjectPath); InsertEntry(Effect, pcObjectPath, pcAddInf1, pcAddInf2); } return Effect; } }; |
Quellcode |
|
1 2 3 4 5 |
l:\Projekte\SB\Source Code\SphereBots Static Classes.h(196): error C2440: '=' : cannot convert from 'void *' to 'STListEntry<T> *' with [ T=tbEffect ] |
C-/C++-Quelltext |
|
1 |
pObjectList = tbMemReAlloc(pObjectList, iObjectCount*sizeof(STListEntry<T>)); |
C-/C++-Quelltext |
|
1 |
pObjectList = (STListEntry<T>*)tbMemReAlloc(pObjectList, iObjectCount*sizeof(STListEntry<T>)); |
Anonymous
unregistriert
Anonymous
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
static void InsertEntry(T* Object, char* pcObjectPath, char* pcAddInf1, char* pcAddInf2) { iObjectCount++; pObjectList = (STListEntry<T>**)tbMemReAlloc(pObjectList, iObjectCount*sizeof(STListEntry<T>*)); pObjectList[iObjectCount] = new STListEntry<T>; pObjectList[iObjectCount]->Object = Object; //Zuweisen der Strings: pObjectList[iObjectCount]->pcObjectPath = new char[255]; pObjectList[iObjectCount]->pcAddInf1 = new char[255]; pObjectList[iObjectCount]->pcAddInf2 = new char[255]; strcpy(pObjectList[iObjectCount]->pcObjectPath, pcObjectPath); strcpy(pObjectList[iObjectCount]->pcAddInf1, pcAddInf1); strcpy(pObjectList[iObjectCount]->pcAddInf2, pcAddInf2); } |
Anonymous
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
int array[] = new int[ 100 ]; int tmp[] = new int[ 200 ]; for( int i = 0; i < 100; ++i ) tmp[ i ] = array[ i ]; delete[] array; array = tmp; |
Werbeanzeige