Posted by mrx Sat 20th Jan 2007 11:18 - Syntax is C++ - 31 views
Download | New Post | Modify | Hide line numbers
Description:
object arrays

  1.  
  2. class BaseObject { } ;
  3.  
  4. class Type1 : public BaseObject { } ;
  5. class Type2 : public BaseObject { } ;
  6. class Type3 : public BaseObject { } ;
  7.  
  8.  
  9. typedef std::map< int {object id} , BaseObject* >  objarray;
  10.  
  11. typedef std::map< int {object id} , Type1* >  objarray_t1;
  12. typedef std::map< int {object id} , Type2* >  objarray_t2;
  13. typedef std::map< int {object id} , Type3* >  objarray_t3;
  14.  
  15. // typed objects are pointing to the same objects as those in objects array
  16.  
  17. objarray objects;
  18. objarray_t1 t1;
  19. objarray_t1 t2;
  20. objarray_t1 t3;
  21.  
  22. BaseObject* findObject( int id )
  23. {
  24.   objarray::iterator  it;
  25.   it = objects.find( id );
  26.   if ( it == objects.end() )
  27.     return NULL;
  28.   return it->second;
  29. }
  30.  
  31.  
  32. Type1* findObjectType1( int id )
  33. {
  34.   objarray_t1::iterator  it;
  35.   it = t1.find( id );
  36.   if ( it == t1.end() )
  37.     return NULL;
  38.   return it->second;
  39. }
  40. ...
  41.  
  42.  
  43. do you have an idea how to simplyfy this ? by some templates, arrays or such ?
  44.  
  45.  

PermaLink to this entry https://pastebin.co.uk/9361
Posted by mrx Sat 20th Jan 2007 11:18 - Syntax is C++ - 31 views
Download | New Post | Modify | Hide line numbers