home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 06 General Architectures / 06 Rabin / database.cpp next >
Encoding:
C/C++ Source or Header  |  2001-12-10  |  1.2 KB  |  73 lines

  1. /* Copyright (C) Steve Rabin, 2001. 
  2.  * All rights reserved worldwide.
  3.  *
  4.  * This software is provided "as is" without express or implied
  5.  * warranties. You may freely copy and compile this source into
  6.  * applications you distribute provided that the copyright text
  7.  * below is included in the resulting source code, for example:
  8.  * "Portions Copyright (C) Steve Rabin, 2001"
  9.  */
  10.  
  11. #include "database.h"
  12. #include "gameobject.h"
  13.  
  14.  
  15. Database::Database( void )
  16. {
  17.     nextFreeID = 1;
  18. }
  19.     
  20.  
  21. Database::~Database( void )
  22. {
  23.  
  24. }
  25.  
  26.  
  27. void Database::Store( GameObject & object )
  28. {
  29.     if( Find( object.GetID() ) == 0 ) {
  30.         database.push_back( &object );
  31.     }
  32.     else {
  33.         assert( !"Database::Store - Object ID already represented in database." );
  34.     }
  35. }
  36.  
  37.  
  38. void Database::Remove( objectID id )
  39. {
  40.     dbContainer::iterator i;
  41.     for( i=database.begin(); i!=database.end(); ++i )
  42.     {
  43.         if( (*i)->GetID() == id ) {
  44.             database.erase(i);    
  45.             return;
  46.         }
  47.     }
  48.  
  49.     return;
  50. }
  51.  
  52.  
  53. GameObject* Database::Find( objectID id )
  54. {
  55.     dbContainer::iterator i;
  56.     for( i=database.begin(); i!=database.end(); ++i )
  57.     {
  58.         if( (*i)->GetID() == id ) {
  59.             return( *i );
  60.         }
  61.     }
  62.  
  63.     return(0);
  64.  
  65. }
  66.  
  67.  
  68. objectID Database::GetNewObjectID( void )
  69. {
  70.     return( nextFreeID++ );
  71.  
  72. }
  73.