mirror of
https://github.com/glest/glest-source.git
synced 2025-08-13 20:03:58 +02:00
- some cleanup related to image loaders (valgrind complaints)
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
#include <vector>
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
@@ -42,12 +43,14 @@ namespace Shared{
|
|||||||
template <class T>
|
template <class T>
|
||||||
class FileReader {
|
class FileReader {
|
||||||
public:
|
public:
|
||||||
string const * extensions;
|
//string const * extensions;
|
||||||
|
std::vector<string> extensions;
|
||||||
|
|
||||||
/**Creates a filereader being able to possibly load files
|
/**Creates a filereader being able to possibly load files
|
||||||
* from the specified extension
|
* from the specified extension
|
||||||
**/
|
**/
|
||||||
FileReader(string const * extensions);
|
//FileReader(string const * extensions);
|
||||||
|
FileReader(std::vector<string> extensions);
|
||||||
|
|
||||||
/**Creates a low-priority filereader
|
/**Creates a low-priority filereader
|
||||||
**/
|
**/
|
||||||
@@ -234,16 +237,20 @@ T* FileReader<T>::readPath(const string& filepath, T* object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FileReader<T>::FileReader(string const * extensions): extensions(extensions) {
|
FileReader<T>::FileReader(std::vector<string> extensions): extensions(extensions) {
|
||||||
getFileReaders().push_back(this);
|
getFileReaders().push_back(this);
|
||||||
string const * nextExtension = extensions;
|
//string const * nextExtension = extensions;
|
||||||
while (((*nextExtension) != "")) {
|
std::vector<string> nextExtension = extensions;
|
||||||
vector<FileReader<T> const* >* curPossibleReaders = (getFileReadersMap())[*nextExtension];
|
//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) {
|
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);
|
curPossibleReaders->push_back(this);
|
||||||
++nextExtension;
|
//++nextExtension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,12 +261,15 @@ FileReader<T>::FileReader(string const * extensions): extensions(extensions) {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
bool FileReader<T>::canRead(const string& filepath) const {
|
bool FileReader<T>::canRead(const string& filepath) const {
|
||||||
const string& realExtension = extractExtension(filepath);
|
const string& realExtension = extractExtension(filepath);
|
||||||
const string* haveExtension = extensions;
|
//const string* haveExtension = extensions;
|
||||||
while (*haveExtension != "") {
|
std::vector<string> haveExtension = extensions;
|
||||||
if (realExtension == *haveExtension) {
|
//while (*haveExtension != "") {
|
||||||
|
for(int i = 0; i < haveExtension.size(); ++i) {
|
||||||
|
//if (realExtension == *haveExtension) {
|
||||||
|
if (realExtension == haveExtension[i]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
++haveExtension;
|
//++haveExtension;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -52,8 +52,15 @@ struct BitmapInfoHeader{
|
|||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
/**Returns a string containing the extensions we want, intitialisation is guaranteed*/
|
/**Returns a string containing the extensions we want, intitialisation is guaranteed*/
|
||||||
static inline const string* getExtensionsBmp() {
|
//static inline const string* getExtensionsBmp() {
|
||||||
static const string extensions[] = {"bmp", ""};
|
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;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,8 +56,15 @@ static void term_source (j_decompress_ptr cinfo) {
|
|||||||
|
|
||||||
/**Return an array containing the used extensions,
|
/**Return an array containing the used extensions,
|
||||||
* initialized*/
|
* initialized*/
|
||||||
static inline const string* getExtensions() {
|
//static inline const string* getExtensions() {
|
||||||
static const string extensions[] = {"jpg", "jpeg", ""};
|
//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;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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) {}
|
static void user_flush_data(png_structp png_ptr) {}
|
||||||
|
|
||||||
/**Get Extension array, initialised*/
|
/**Get Extension array, initialised*/
|
||||||
static inline const string* getExtensionsPng() {
|
//static inline const string* getExtensionsPng() {
|
||||||
static const string extensions[] = {"png", ""};
|
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;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,8 +52,14 @@ static const int tgaUncompressedBw= 3;
|
|||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
/**Get Extension array, initialised*/
|
/**Get Extension array, initialised*/
|
||||||
static inline const string* getExtensionStrings() {
|
//static inline const string* getExtensionStrings() {
|
||||||
static const string extensions[] = {"tga", ""};
|
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;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user