Voodoo!

posted in Not dead...
Published September 16, 2007
Advertisement
I've just obtained more proof that Boost is pure voodoo in computer form!

GTL makes use of a boost::multi_index_container in order to peform id -> creator and string -> creator lookups. The same system is staying in place, with a few name changes, in GTL3.

This code is in GTL2;
namespace mi = boost::multi_index;struct FilterCreatorDetails{	FileTypes id_;	std::string key_;	FilterCreator_t creator_;		FilterCreatorDetails(FileTypes id, std::string const &key, FilterCreator_t creator) : id_(id), key_(key), creator_(creator)	{	}	FilterCreatorDetails(FilterCreatorDetails const &lhs) : id_(lhs.id_), key_(lhs.key_), creator_(lhs.creator_)	{	}	bool operator<(FilterCreatorDetails const &lhs) const 	{ 		return id_ < lhs.id_;	};};struct key{};struct id{};class FilterRegister{public:	typedef mi::multi_index_container<		FilterCreatorDetails,		mi::indexed_by<		mi::ordered_unique< mi::tag , mi::member >,		mi::ordered_non_unique< mi::tag , mi::member >		> 	> texmap_t;// rest of class definition}FilterCreator_t FilterRegister::getCreator(std::string const &val){	typedef FilterRegister::texmap_t::index::type tex_by_name;		tex_by_name::iterator it = texturefilters->get().find(val);	if(it == texturefilters->get().end())		throw LoaderNotFoundException("Texture Loader not found for texture type : " + val);	return (*it).creator_;}


This code compiles perfectly.

GTL had this code;
namespace mi = boost::multi_index;struct DecoderCreatorDetails{	GameTextureLoader3::FileTypes id_;	std::string key_;	GameTextureLoader3::DecoderCreator_t creator_;		DecoderCreatorDetails(GameTextureLoader3::FileTypes id, std::string const &key, GameTextureLoader3::DecoderCreator_t creator) : id_(id), key_(key), creator_(creator)	{	}	DecoderCreatorDetails(FilterCreatorDetails const &lhs) : id_(lhs.id_), key_(lhs.key_), creator_(lhs.creator_)	{	}	bool operator<(FilterCreatorDetails const &lhs) const 	{ 		return id_ < lhs.id_;	};};struct key{};struct id{};typedef mi::multi_index_container<	DecoderCreatorDetails,	mi::indexed_by<	mi::ordered_unique< mi::tag , mi::member >,	mi::ordered_non_unique< mi::tag , mi::member >	> > decodermap_t;typedef decodermap_t::index::type tex_by_name;	class DecoderRegistery{public:DecoderCreator_t getCreator(std::string const &val){	tex_by_name::iterator it = imageDataDecoders.get().find(val);	if(it == texturefilters->get().end())		throw "This is bad practice!!"; //throw LoaderNotFoundException("Texture Loader not found for texture type : " + val);	return (*it).creator_;}


A few scope changes and name changes and does it compile? Did it hell.

Some swearing and looking at the docs later we now have;
namespace mi = boost::multi_index;struct DecoderCreatorDetails{	GameTextureLoader3::FileTypes id_;	std::string ext_;	GameTextureLoader3::DecoderCreator_t creator_;	DecoderCreatorDetails(GameTextureLoader3::FileTypes id, std::string const &ext, GameTextureLoader3::DecoderCreator_t creator) : id_(id), ext_(ext), creator_(creator)	{	}	DecoderCreatorDetails(DecoderCreatorDetails const &lhs) : id_(lhs.id_), ext_(lhs.ext_), creator_(lhs.creator_)	{	}	bool operator<(DecoderCreatorDetails const &lhs) const 	{ 		return id_ < lhs.id_;	};};struct extension{};struct id{};typedef mi::multi_index_container<	DecoderCreatorDetails,	mi::indexed_by<		mi::ordered_unique< mi::tag, mi::member >,		mi::ordered_non_unique< mi::tag, mi::member > 	> > decodermap_t;class DecoderRegistry	{	public:	template	GameTextureLoader3::DecoderCreator_t getCreator(T const &val)	{		typedef typename decodermap_t::index::type tex_by_key;		tex_by_key &name_idx = imageDataDecoders.get();		tex_by_key::iterator it = name_idx.find(val);		if(it == name_idx.end())			throw "This is bad practice!!"; // throw LoaderNotFoundException("Texture Loader not found for texture of type : " + boost::lexical_cast(val));					return (*it).creator_;	}// rest of class definition}


This compiles perfectly.
Changes? Well, aside from templating it after I got it working I've moxed the typedef back into function scope and decomposed the lookup operation into two lines.

Even that if() statement was throwing an error, that works now and I haven't changed a thing about it; well as the operations go, techinically it's faster now as we don't perform two lookups.

Voodoo I tell you!
Next Entry GTL3.0 Progress
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Advertisement