(svn r26209) -Codechange: remove some template magic and simplify some code

This commit is contained in:
rubidium
2014-01-02 22:41:58 +00:00
parent 456dba4889
commit 2618d960e3
28 changed files with 100 additions and 112 deletions

View File

@@ -56,10 +56,9 @@ public:
};
/** Factory for the 32bpp blitter with animation. */
class FBlitter_32bppAnim : public BlitterFactory<FBlitter_32bppAnim> {
class FBlitter_32bppAnim : public BlitterFactory {
public:
/* virtual */ const char *GetName() { return "32bpp-anim"; }
/* virtual */ const char *GetDescription() { return "32bpp Animation Blitter (palette animation)"; }
FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppAnim(); }
};

View File

@@ -32,10 +32,9 @@ public:
};
/** Factory for the optimised 32 bpp blitter (without palette animation). */
class FBlitter_32bppOptimized : public BlitterFactory<FBlitter_32bppOptimized> {
class FBlitter_32bppOptimized : public BlitterFactory {
public:
/* virtual */ const char *GetName() { return "32bpp-optimized"; }
/* virtual */ const char *GetDescription() { return "32bpp Optimized Blitter (no palette animation)"; }
FBlitter_32bppOptimized() : BlitterFactory("32bpp-optimized", "32bpp Optimized Blitter (no palette animation)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppOptimized(); }
};

View File

@@ -34,10 +34,9 @@ public:
};
/** Factory for the simple 32 bpp blitter. */
class FBlitter_32bppSimple : public BlitterFactory<FBlitter_32bppSimple> {
class FBlitter_32bppSimple : public BlitterFactory {
public:
/* virtual */ const char *GetName() { return "32bpp-simple"; }
/* virtual */ const char *GetDescription() { return "32bpp Simple Blitter (no palette animation)"; }
FBlitter_32bppSimple() : BlitterFactory("32bpp-simple", "32bpp Simple Blitter (no palette animation)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSimple(); }
};

View File

@@ -31,10 +31,9 @@ public:
};
/** Factory for the 8bpp blitter optimised for speed. */
class FBlitter_8bppOptimized : public BlitterFactory<FBlitter_8bppOptimized> {
class FBlitter_8bppOptimized : public BlitterFactory {
public:
/* virtual */ const char *GetName() { return "8bpp-optimized"; }
/* virtual */ const char *GetDescription() { return "8bpp Optimized Blitter (compression + all-ZoomLevel cache)"; }
FBlitter_8bppOptimized() : BlitterFactory("8bpp-optimized", "8bpp Optimized Blitter (compression + all-ZoomLevel cache)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppOptimized(); }
};

View File

@@ -25,10 +25,9 @@ public:
};
/** Factory for the most trivial 8bpp blitter. */
class FBlitter_8bppSimple : public BlitterFactory<FBlitter_8bppSimple> {
class FBlitter_8bppSimple : public BlitterFactory {
public:
/* virtual */ const char *GetName() { return "8bpp-simple"; }
/* virtual */ const char *GetDescription() { return "8bpp Simple Blitter (relative slow, but never wrong)"; }
FBlitter_8bppSimple() : BlitterFactory("8bpp-simple", "8bpp Simple Blitter (relative slow, but never wrong)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppSimple(); }
};

View File

@@ -25,11 +25,12 @@ bool QZ_CanDisplay8bpp();
/**
* The base factory, keeping track of all blitters.
*/
class BlitterFactoryBase {
class BlitterFactory {
private:
const char *name; ///< The name of the blitter factory.
const char *name; ///< The name of the blitter factory.
const char *description; ///< The description of the blitter.
typedef std::map<const char *, BlitterFactoryBase *, StringCompare> Blitters; ///< Map of blitter factories.
typedef std::map<const char *, BlitterFactory *, StringCompare> Blitters; ///< Map of blitter factories.
/**
* Get the map with currently known blitters.
@@ -53,32 +54,28 @@ private:
protected:
/**
* Register a blitter internally, based on his name.
* @param name the name of the blitter.
* @note an assert() will be trigger if 2 blitters with the same name try to register.
* Construct the blitter, and register it.
* @param name The name of the blitter.
* @param description A longer description for the blitter.
* @pre name != NULL.
* @pre description != NULL.
* @pre There is no blitter registered with this name.
*/
void RegisterBlitter(const char *name)
BlitterFactory(const char *name, const char *description) :
name(strdup(name)), description(strdup(description))
{
/* Don't register nameless Blitters */
if (name == NULL) return;
this->name = strdup(name);
std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(name, this));
std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(this->name, this));
assert(P.second);
}
public:
BlitterFactoryBase() :
name(NULL)
{}
virtual ~BlitterFactoryBase()
virtual ~BlitterFactory()
{
if (this->name == NULL) return;
GetBlitters().erase(this->name);
if (GetBlitters().empty()) delete &GetBlitters();
free(this->name);
free(this->description);
}
/**
@@ -108,7 +105,7 @@ public:
Blitters::iterator it = GetBlitters().begin();
for (; it != GetBlitters().end(); it++) {
BlitterFactoryBase *b = (*it).second;
BlitterFactory *b = (*it).second;
if (strcasecmp(bname, b->name) == 0) {
Blitter *newb = b->CreateInstance();
delete *GetActiveBlitter();
@@ -140,7 +137,7 @@ public:
p += seprintf(p, last, "List of blitters:\n");
Blitters::iterator it = GetBlitters().begin();
for (; it != GetBlitters().end(); it++) {
BlitterFactoryBase *b = (*it).second;
BlitterFactory *b = (*it).second;
p += seprintf(p, last, "%18s: %s\n", b->name, b->GetDescription());
}
p += seprintf(p, last, "\n");
@@ -148,10 +145,21 @@ public:
return p;
}
/**
* Get the long, human readable, name for the Blitter-class.
*/
const char *GetName() const
{
return this->name;
}
/**
* Get a nice description of the blitter-class.
*/
virtual const char *GetDescription() = 0;
const char *GetDescription() const
{
return this->description;
}
/**
* Create an instance of this Blitter-class.
@@ -159,20 +167,6 @@ public:
virtual Blitter *CreateInstance() = 0;
};
/**
* A template factory, so ->GetName() works correctly. This because else some compiler will complain.
*/
template <class T>
class BlitterFactory : public BlitterFactoryBase {
public:
BlitterFactory() { this->RegisterBlitter(((T *)this)->GetName()); }
/**
* Get the long, human readable, name for the Blitter-class.
*/
const char *GetName();
};
extern char *_ini_blitter;
extern bool _blitter_autodetected;

View File

@@ -38,10 +38,9 @@ public:
};
/** Factory for the blitter that does nothing. */
class FBlitter_Null : public BlitterFactory<FBlitter_Null> {
class FBlitter_Null : public BlitterFactory {
public:
/* virtual */ const char *GetName() { return "null"; }
/* virtual */ const char *GetDescription() { return "Null Blitter (does nothing)"; }
FBlitter_Null() : BlitterFactory("null", "Null Blitter (does nothing)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_Null(); }
};