home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / bonus / demos / CS / exp / SOURCES / GLENGINE / entity.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-20  |  1.5 KB  |  83 lines

  1. #ifndef __OGL2_ENTITY__
  2. #define __OGL2_ENTITY__
  3.  
  4. #include "String.h"
  5. #include "List.h"
  6.  
  7. extern "C++" {
  8.  
  9. class Entity
  10. {
  11.   String __entity_name;
  12. public:
  13.   Entity(const char* p = 0) {
  14.     __entity_name = p;
  15.   }
  16.   virtual ~Entity() {}
  17.  
  18.   void Name(const char* p) {
  19.     __entity_name = p;
  20.   }
  21.   void Name(const String& S) {
  22.     __entity_name = S;
  23.   }
  24.   const String& Name() {
  25.     return __entity_name;
  26.   }
  27. };
  28.  
  29. template <class __type>
  30. class EntityList {
  31. protected:
  32.   List<__type*> __entity_list;
  33.  
  34. public:
  35.  
  36.   EntityList<__type>& Add(__type* p) {
  37.     if(p) __entity_list.push_back(p);
  38.     return *this;
  39.   }
  40.   EntityList<__type>& operator += (__type* p) {
  41.     return Add(p);
  42.   }
  43.  
  44.   EntityList<__type>& Add (const EntityList<__type> & A) {
  45.     __entity_list+=A.__entity_list;
  46.     return *this;
  47.   }
  48.   EntityList<__type>& operator += (const EntityList<__type>& A) {
  49.     return Add(A);
  50.   }
  51.  
  52.   __type* Get(const char *p)
  53.   {
  54.     if(__entity_list.size()==0) return 0;
  55.     __type* __temp;
  56.     __entity_list.rewind();
  57.     for(int i=__entity_list.size(); i; i--) {
  58.       __temp = *__entity_list;
  59.       if(__temp->Name()==p)
  60.         return __temp;
  61.       ++__entity_list;
  62.       }
  63.     return 0;
  64.   }
  65.   __type* Get(const String& S) { 
  66.     return Get(S());
  67.   }
  68.  
  69.   void DeleteEntities () {
  70.     __entity_list.rewind();
  71.     for(int i=__entity_list.size(); i; i--) {
  72.       delete *__entity_list;
  73.       ++__entity_list;
  74.     }
  75.     __entity_list.erase();
  76.   }
  77.  
  78. };
  79.  
  80. } // extern "C++"
  81.  
  82. #endif
  83.