xbmc/xbmc — pull request #3401 by Montellese (2013-10-08 20:48:22+00:00)
Title: media type related constants handling

While working on something that required media type describing constants ("movie", "tvshow", "episode" etc) it really started to annoy me having to write those strings out all the time. They are used in various places in our code but with no real "standardisation" or anything. A simple typo in the string and something won't work as expected.

So I tried to come up with a way to
* provide pre-defined constants which would be checked by the compiler and would therefore generate compiler warnings on common mistakes like typos
* provide a way to be able to tell from the type of the parameter / member variable / ... that it should contain a media type describing constant

I'm not 100% fond of the implementation I came up with but I want to keep using strings instead of enum values because strings are much easier to extend than enums (dynamically that is) so if we ever want to support user-defined media types an enum will be a no-go. So I created a typedef for std::string named MediaType, some defines for the currently supported media type describing constants and some helper methods in a "static" class and replaced the string literals in some code places where I stumbled upon them.

Ideally the media types (and there plural form etc) would be registerable/extendable and not the way it is right now but I first wanted to get some feedback on the general idea before re-writing the MediaTypes class.