Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2194 in orxonox.OLD for orxonox/branches/chris/src/world_entity.cc


Ignore:
Timestamp:
Jul 18, 2004, 12:03:57 PM (21 years ago)
Author:
chris
Message:

orxonox/branches/chris: Implemented is_a() query for WorldEntities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/chris/src/world_entity.cc

    r2192 r2194  
    2323
    2424using namespace std;
     25
     26// initialize the pointers used for is_a identification
     27bool (*WorldEntity::basefunc)(char*) = WorldEntity::is_none;
     28char *WorldEntity::is = "WorldEntity";
    2529
    2630/**
     
    183187*/
    184188void WorldEntity::left_world () {}
     189
     190/**
     191        \brief this method can be used to determine what type of WorldEntity a particular pointer represents at runtime
     192        \param name: a string specifying the type (use the name of the class)
     193        \return true if the entity is in fact of that type or a derivation thereof false if the entity is not related to the specifiead type
     194
     195        Since this funtion is declared static, it has to be redeclaed and reimplemented in every derivation of WorldEntity, but since it is written
     196        very generally you just have to copy paste this function and initialize the two static is_a variables (basefunc and is) correctly.
     197        Note that these have to be redeclared as well or you will get a compiler error.
     198*/
     199bool WorldEntity::is_a (char* name)
     200{
     201        if( !strcmp( name, is)) return true;
     202        else return basefunc (name);
     203}
     204
     205/**
     206        \brief basefunc of WorldEntity
     207        \param name: not relevant
     208        \return false
     209       
     210        dummy is_a() implementation that returns false only
     211*/
     212bool WorldEntity::is_none (char* name)
     213{
     214        return false;
     215}
Note: See TracChangeset for help on using the changeset viewer.