- some cleanup related to image loaders (valgrind complaints)

This commit is contained in:
Mark Vejvoda 2010-09-14 15:59:04 +00:00
parent e7efda5080
commit 689b810d46
5 changed files with 55 additions and 20 deletions

View File

@ -20,6 +20,7 @@
#include <iostream>
#include <stdexcept>
#include <typeinfo>
#include <vector>
#include "leak_dumper.h"
using std::map;
@ -42,12 +43,14 @@ namespace Shared{
template <class T>
class FileReader {
public:
string const * extensions;
//string const * extensions;
std::vector<string> extensions;
/**Creates a filereader being able to possibly load files
* from the specified extension
**/
FileReader(string const * extensions);
//FileReader(string const * extensions);
FileReader(std::vector<string> extensions);
/**Creates a low-priority filereader
**/
@ -234,16 +237,20 @@ T* FileReader<T>::readPath(const string& filepath, T* object) {
}
template <typename T>
FileReader<T>::FileReader(string const * extensions): extensions(extensions) {
FileReader<T>::FileReader(std::vector<string> extensions): extensions(extensions) {
getFileReaders().push_back(this);
string const * nextExtension = extensions;
while (((*nextExtension) != "")) {
vector<FileReader<T> const* >* curPossibleReaders = (getFileReadersMap())[*nextExtension];
//string const * nextExtension = extensions;
std::vector<string> nextExtension = extensions;
//while (((*nextExtension) != "")) {
for(int i = 0; i < nextExtension.size(); ++i) {
//vector<FileReader<T> const* >* curPossibleReaders = (getFileReadersMap())[*nextExtension];
vector<FileReader<T> const* >* curPossibleReaders = (getFileReadersMap())[nextExtension[i]];
if (curPossibleReaders == NULL) {
(getFileReadersMap())[*nextExtension] = (curPossibleReaders = new vector<FileReader<T> const *>());
//(getFileReadersMap())[*nextExtension] = (curPossibleReaders = new vector<FileReader<T> const *>());
(getFileReadersMap())[nextExtension[i]] = (curPossibleReaders = new vector<FileReader<T> const *>());
}
curPossibleReaders->push_back(this);
++nextExtension;
//++nextExtension;
}
}
@ -254,12 +261,15 @@ FileReader<T>::FileReader(string const * extensions): extensions(extensions) {
template <typename T>
bool FileReader<T>::canRead(const string& filepath) const {
const string& realExtension = extractExtension(filepath);
const string* haveExtension = extensions;
while (*haveExtension != "") {
if (realExtension == *haveExtension) {
//const string* haveExtension = extensions;
std::vector<string> haveExtension = extensions;
//while (*haveExtension != "") {
for(int i = 0; i < haveExtension.size(); ++i) {
//if (realExtension == *haveExtension) {
if (realExtension == haveExtension[i]) {
return true;
}
++haveExtension;
//++haveExtension;
}
return false;
}

View File

@ -52,8 +52,15 @@ struct BitmapInfoHeader{
#pragma pack(pop)
/**Returns a string containing the extensions we want, intitialisation is guaranteed*/
static inline const string* getExtensionsBmp() {
static const string extensions[] = {"bmp", ""};
//static inline const string* getExtensionsBmp() {
static inline std::vector<string> getExtensionsBmp() {
//static const string extensions[] = {"bmp", ""};
static std::vector<string> extensions;
if(extensions.size() == 0) {
extensions.push_back("bmp");
}
return extensions;
}

View File

@ -56,8 +56,15 @@ static void term_source (j_decompress_ptr cinfo) {
/**Return an array containing the used extensions,
* initialized*/
static inline const string* getExtensions() {
static const string extensions[] = {"jpg", "jpeg", ""};
//static inline const string* getExtensions() {
//static const string extensions[] = {"jpg", "jpeg", ""};
static inline std::vector<string> getExtensions() {
static std::vector<string> extensions;
if(extensions.size() == 0) {
extensions.push_back("jpg");
extensions.push_back("jpeg");
}
return extensions;
}

View File

@ -44,8 +44,13 @@ static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t leng
static void user_flush_data(png_structp png_ptr) {}
/**Get Extension array, initialised*/
static inline const string* getExtensionsPng() {
static const string extensions[] = {"png", ""};
//static inline const string* getExtensionsPng() {
static inline std::vector<string> getExtensionsPng() {
//static const string extensions[] = {"png", ""};
static std::vector<string> extensions;
if(extensions.size() == 0) {
extensions.push_back("png");
}
return extensions;
}

View File

@ -52,8 +52,14 @@ static const int tgaUncompressedBw= 3;
// =====================================================
/**Get Extension array, initialised*/
static inline const string* getExtensionStrings() {
static const string extensions[] = {"tga", ""};
//static inline const string* getExtensionStrings() {
static inline std::vector<string> getExtensionStrings() {
//static const string extensions[] = {"tga", ""};
static std::vector<string> extensions;
if(extensions.size() == 0) {
extensions.push_back("tga");
}
return extensions;
}