Posted by mrx Sat 20th Jan 2007 11:18 - Syntax is C++ - 31 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Description:
object arrays
object arrays
-
-
class BaseObject { } ;
-
-
class Type1 : public BaseObject { } ;
-
class Type2 : public BaseObject { } ;
-
class Type3 : public BaseObject { } ;
-
-
-
typedef std::map< int {object id} , BaseObject* > objarray;
-
-
typedef std::map< int {object id} , Type1* > objarray_t1;
-
typedef std::map< int {object id} , Type2* > objarray_t2;
-
typedef std::map< int {object id} , Type3* > objarray_t3;
-
-
// typed objects are pointing to the same objects as those in objects array
-
-
objarray objects;
-
objarray_t1 t1;
-
objarray_t1 t2;
-
objarray_t1 t3;
-
-
BaseObject* findObject( int id )
-
{
-
objarray::iterator it;
-
it = objects.find( id );
-
if ( it == objects.end() )
-
return NULL;
-
return it->second;
-
}
-
-
-
Type1* findObjectType1( int id )
-
{
-
objarray_t1::iterator it;
-
it = t1.find( id );
-
if ( it == t1.end() )
-
return NULL;
-
return it->second;
-
}
-
...
-
-
-
do you have an idea how to simplyfy this ? by some templates, arrays or such ?
-
-
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
Download | New Post | Modify | Hide line numbers