Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9723 in orxonox.OLD


Ignore:
Timestamp:
Sep 7, 2006, 10:33:06 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: safer smart-pointer

Location:
branches/new_class_id/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/graphics/text_engine/font.cc

    r9718 r9723  
    132132
    133133  this->registerObject(this, Font::_objectList);
    134   if (Font::defaultFontData.get() == NULL)
     134  if (Font::defaultFontData.isNull())
    135135  {
    136136    Font::initDefaultFont();
  • branches/new_class_id/src/lib/util/count_pointer.h

    r8761 r9723  
    99{
    1010public:
    11     explicit CountPointer(X* p = 0) // allocate a new counter
    12         : itsCounter(0) { if (p) itsCounter = new counter(p); }
    13     virtual ~CountPointer() { release(); }
    14     CountPointer(const CountPointer& r) { acquire(r.itsCounter); }
    15     CountPointer& operator=(const CountPointer& r)
     11  explicit CountPointer(X* p = NULL) // allocate a new counter
     12      : itsCounter(NULL) { if (p) itsCounter = new counter(p); }
     13virtual ~CountPointer() { release(); }
     14  CountPointer(const CountPointer& r) { acquire(r.itsCounter); }
     15  CountPointer& operator=(const CountPointer& r)
     16  {
     17    if (this != &r)
    1618    {
    17         if (this != &r) {
    18             release();
    19             acquire(r.itsCounter);
    20         }
    21         return *this;
     19      release();
     20      acquire(r.itsCounter);
    2221    }
    23     bool operator==(const CountPointer& r) const { return this->itsCounter->ptr == r.itsCounter->ptr; };
    24     X& operator*()  const { return *itsCounter->ptr; }
    25     X* operator->() const { return itsCounter->ptr; }
    26     X* get()        const { return itsCounter ? itsCounter->ptr : 0; }
    27     bool unique()   const { return (itsCounter ? itsCounter->count == 1 : true); }
    28     virtual unsigned int count() const { return (this->itsCounter ? itsCounter->count : 0); }
     22    return *this;
     23  }
     24  bool operator==(const CountPointer& r) const { return this->itsCounter->ptr == r.itsCounter->ptr; };
     25  inline X& operator*()  const { return *itsCounter->ptr; }
     26  inline X* operator->() const { return itsCounter->ptr; }
     27inline bool unique()   const { return (itsCounter ? itsCounter->count == 1 : true); }
     28  inline bool isNull()   const { return (!itsCounter); }
     29
     30virtual unsigned int count() const { return (this->itsCounter ? itsCounter->count : 0); }
    2931private:
    3032
    31     struct counter {
    32         counter(X* p = 0, unsigned c = 1) : ptr(p), count(c) {}
    33         X*          ptr;
    34         unsigned    count;
    35     }* itsCounter;
     33  struct counter
     34  {
     35    counter(X* p = NULL, unsigned c = 1) : ptr(p), count(c) {}
     36    X*          ptr;
     37    unsigned    count;
     38  }
     39  * itsCounter;
    3640
    37     void acquire(counter* c)
     41  void acquire(counter* c)
     42  {
     43    // increment the count
     44    itsCounter = c;
     45    if (c) ++c->count;
     46  }
     47
     48  void release()
     49  {
     50    // decrement the count, delete if it is 0
     51    if (itsCounter)
    3852    {
    39       // increment the count
    40         itsCounter = c;
    41         if (c) ++c->count;
     53      if (--itsCounter->count == 0)
     54      {
     55        delete itsCounter->ptr;
     56        delete itsCounter;
     57      }
     58      itsCounter = NULL;
    4259    }
    43 
    44     void release()
    45     {
    46       // decrement the count, delete if it is 0
    47         if (itsCounter) {
    48             if (--itsCounter->count == 0) {
    49                 delete itsCounter->ptr;
    50                 delete itsCounter;
    51             }
    52             itsCounter = 0;
    53         }
    54     }
     60  }
    5561};
    5662
  • branches/new_class_id/src/story_entities/game_world.cc

    r9715 r9723  
    415415    if (currentFrame - this->lastFrame < .01)
    416416    {
    417       SDL_Delay(1000.0 * (0.01 - (currentFrame - lastFrame)));
     417      SDL_Delay((int)1000.0 * (0.01 - (currentFrame - lastFrame)));
    418418      currentFrame = Timer::getNow();
    419419    }
  • branches/new_class_id/src/world_entities/weapons/weapon.cc

    r9715 r9723  
    542542{
    543543  PRINTF(4)("Reloading Weapon %s\n", this->getCName());
    544   if (this->ammoContainer.get() != NULL &&
     544  if (!this->ammoContainer.isNull() &&
    545545      unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge))
    546546  {
     
    554554    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
    555555
    556   if (this->ammoContainer.get() != NULL)
     556  if (!this->ammoContainer.isNull())
    557557    this->ammoContainer->fillWeapon(this);
    558558  else
Note: See TracChangeset for help on using the changeset viewer.