(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)

This commit is contained in:
celestar
2007-01-17 11:15:51 +00:00
parent decd7fbe31
commit bdb9543f7c
4 changed files with 121 additions and 93 deletions

View File

@@ -53,6 +53,20 @@ typedef struct RoadStop {
StationID station;
struct RoadStop *next;
struct RoadStop *prev;
static const int cDebugCtorLevel = 3;
RoadStop(TileIndex tile, StationID index);
~RoadStop();
void *operator new (size_t size);
void operator delete(void *rs);
/* For loading games */
void *operator new (size_t size, int index);
void operator delete(void *rs, int index);
static RoadStop *AllocateRaw( void );
} RoadStop;
typedef struct StationSpecList {
@@ -248,14 +262,6 @@ static inline bool IsValidRoadStop(const RoadStop *rs)
return rs->used;
}
void DestroyRoadStop(RoadStop* rs);
static inline void DeleteRoadStop(RoadStop *rs)
{
DestroyRoadStop(rs);
rs->used = false;
}
#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) if (IsValidRoadStop(rs))
#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)