src/tools/tSafePTR.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "tSafePTR.h"
00029 #include "tList.h"
00030 
00031 /*
00032 class tPTRList:public tArray<tCheckedPTRBase *> {
00033   friend tCheckedPTRBase;
00034 
00035   // Array<T *> list;
00036 public:
00037   tPTRList():tArray<tCheckedPTRBase *>(10000){}
00038 
00039   void Add(tCheckedPTRBase *t){
00040     if (t->id<0){    // tEventQueue relies on the fact that we put t in
00041       t->id=Len();   // the last place.
00042 
00043       operator[](t->id)=t;
00044       if ((t->id)==710)
00045         st_Breakpoint();
00046     }
00047   }
00048   void Remove(tCheckedPTRBase *t){
00049     // con << "offset=" << offset << '\n';
00050     if (t->id>=0 && Len()>0){
00051 #ifdef DEBUG
00052       if ((t->id)==710)
00053         st_Breakpoint();
00054 
00055       if (t->id>=Len())
00056         tERR_ERROR("Scr. list structure!");
00057       
00058       tCheckedPTRBase *test=operator()(t->id);
00059       if (test!=t)
00060         tERR_ERROR("Screwed list structure!");
00061 #endif
00062     // the check for Len() is done, since this may be
00063       // called on an allready descructed list.
00064       tCheckedPTRBase *other=operator()(Len()-1);
00065       operator()(t->id)=other;
00066 
00067       if ((other->id)==710)
00068         st_Breakpoint();
00069 
00070       other->id=t->id;
00071       SetLen(Len()-1);
00072     }
00073     t->id=-1;
00074   }
00075 };
00076 */
00077 
00078 tList<tCheckedPTRBase> tCheckedPTRs;
00079 
00080 tCheckedPTRBase::tCheckedPTRBase(void *x):id(-1),target(x){
00081     tCheckedPTRs.Add(this,id);
00082 }
00083 
00084 tCheckedPTRBase::tCheckedPTRBase(const tCheckedPTRBase& x)
00085         :id(-1),target(x.target){
00086     tCheckedPTRs.Add(this,id);
00087 }
00088 
00089 tCheckedPTRBase::tCheckedPTRBase():id(-1),target(NULL){
00090     tCheckedPTRs.Add(this,id);
00091 }
00092 
00093 
00094 tCheckedPTRBase::~tCheckedPTRBase(){
00095     tCheckedPTRs.Remove(this,id);
00096 }
00097 
00098 #ifdef DEBUG
00099 static void * watchobject = NULL;
00100 
00101 // functions to watch reference counting of specific objects
00102 void st_AddRefBreakpint( void const * object )
00103 {
00104     if ( object == watchobject )
00105     {
00106         int x;
00107         x = 0;
00108     }
00109 }
00110 
00111 void st_ReleaseBreakpint( void const * object )
00112 {
00113     if ( object == watchobject )
00114     {
00115         int x;
00116         x = 0;
00117     }
00118 }
00119 #endif
00120 
00121 
00122 /*
00123 
00124 class gWallRim;
00125 class gNetPlayerWall;
00126 class eCamera;
00127 class tConfItemBase;
00128 class ePlayer;
00129 class ePlayerNetID;
00130 class uAction;
00131 class eGameObject;
00132 class ePoint;
00133 class eEdge;
00134 class eFace;
00135 
00136 extern List<gWallRim> se_rimWalls;
00137 extern List<gNetPlayerWall> sg_netPlayerWalls;
00138 extern List<gNetPlayerWall> gridded_sg_netPlayerWalls;
00139 extern List<eCamera> se_cameras;
00140 extern List<tConfItemBase> tConfItemBase::tConfItems;
00141 extern List<eGameObject> eGameObject::gameObjects;
00142 extern List<ePlayer> PlayerConfig;
00143 extern List<ePlayerNetID> se_PlayerNetIDs;
00144 extern List<uAction> s_playerActions;
00145 extern List<uAction> s_cameraActions;
00146 extern List<uAction> s_globalActions;
00147 extern List<uAction> su_allActions;
00148 extern List<ePoint> ePoint::points;
00149 extern List<eEdge> eEdge::edges;
00150 extern List<eFace> eFace::faces;
00151 
00152 
00153 template<class T> void suspicious(const List<T> &l,tCheckedPTRBase *adr){
00154   T *best=NULL;
00155   int best_ind=-1;
00156   int i;
00157   for (i=l.Len()-1;i>=0;i--){
00158     T *t=l(i);
00159     int dist=int(adr)-int(t);
00160     if (dist>=0 && dist < 100 && int(t)>int(best)){
00161       best=t;
00162       best_ind=i;
00163     }
00164   }
00165   if (best){
00166     tERR_ERROR("Suspicious object " << l(best_ind) << " has index " << best_ind << " and is at adress " 
00167           << best << ".");
00168   }
00169 }
00170 
00171 
00172 
00173 
00174 
00175 void tCheckedPTRBase::CheckDestructed(void *test){
00176   // return;
00177 
00178   for(int i=tCheckedPTRs.Len()-1;i>=0;i--){
00179     tCheckedPTRBase * adr=tCheckedPTRs(i);
00180     if (adr->target==test){
00181       suspicious(se_rimWalls,adr);
00182       suspicious(sg_netPlayerWalls,adr);
00183       suspicious(gridded_sg_netPlayerWalls,adr);
00184       suspicious(se_cameras,adr);
00185       suspicious(tConfItemBase::tConfItems,adr);
00186       suspicious(eGameObject::gameObjects,adr);
00187       suspicious(eGameObject::gameObjectsInactive,adr);
00188       suspicious(PlayerConfig,adr);
00189       suspicious(se_PlayerNetIDs,adr);
00190       suspicious(s_playerActions,adr);
00191       suspicious(s_cameraActions,adr);
00192       suspicious(s_globalActions,adr);
00193       suspicious(su_allActions,adr);
00194       suspicious(ePoint::points,adr);
00195       suspicious(eEdge::edges,adr);
00196       suspicious(eFace::faces,adr);
00197       
00198       
00199       tERR_ERROR("Object destroyed, but pointer at " << adr << 
00200             " still points to it!");
00201     }
00202   }
00203 
00204 }
00205 
00206 */
00207 

Generated on Sat Mar 15 22:56:01 2008 for Armagetron Advanced by  doxygen 1.5.4