Browse Source

Cleaned up and unified error and assertion messages.

pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
e55b4b80c6
  1. 20
      src/Plugins/MagnumFont/MagnumFont.cpp
  2. 4
      src/Plugins/TgaImageConverter/TgaImageConverter.cpp
  3. 12
      src/Plugins/TgaImporter/TgaImporter.cpp

20
src/Plugins/MagnumFont/MagnumFont.cpp

@ -68,7 +68,7 @@ bool MagnumFont::doIsOpened() const { return _opened; }
void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, const Float) { void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, const Float) {
/* We need just the configuration file and image file */ /* We need just the configuration file and image file */
if(data.size() != 2) { if(data.size() != 2) {
Error() << "Magnum::Text::MagnumFont::openData(): wanted two files, got" << data.size(); Error() << "Text::MagnumFont::openData(): wanted two files, got" << data.size();
return; return;
} }
@ -76,20 +76,20 @@ void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers:
std::istringstream in({reinterpret_cast<const char*>(data[0].second.begin()), data[0].second.size()}); std::istringstream in({reinterpret_cast<const char*>(data[0].second.begin()), data[0].second.size()});
Utility::Configuration conf(in, Utility::Configuration::Flag::SkipComments); Utility::Configuration conf(in, Utility::Configuration::Flag::SkipComments);
if(!conf.isValid() || conf.isEmpty()) { if(!conf.isValid() || conf.isEmpty()) {
Error() << "Magnum::Text::MagnumFont::openData(): cannot open file" << data[0].first << conf.isValid(); Error() << "Text::MagnumFont::openData(): cannot open file" << data[0].first << conf.isValid();
return; return;
} }
/* Check version */ /* Check version */
if(conf.value<UnsignedInt>("version") != 1) { if(conf.value<UnsignedInt>("version") != 1) {
Error() << "Magnum::Text::MagnumFont::openData(): unsupported file version, expected 1 but got" Error() << "Text::MagnumFont::openData(): unsupported file version, expected 1 but got"
<< conf.value<UnsignedInt>("version"); << conf.value<UnsignedInt>("version");
return; return;
} }
/* Check that we have also the image file */ /* Check that we have also the image file */
if(conf.value("image") != data[1].first) { if(conf.value("image") != data[1].first) {
Error() << "Magnum::Text::MagnumFont::openData(): expected file" Error() << "Text::MagnumFont::openData(): expected file"
<< conf.value("image") << "but got" << data[1].first; << conf.value("image") << "but got" << data[1].first;
return; return;
} }
@ -97,12 +97,12 @@ void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers:
/* Open and load image file */ /* Open and load image file */
Trade::TgaImporter importer; Trade::TgaImporter importer;
if(!importer.openData(data[1].second)) { if(!importer.openData(data[1].second)) {
Error() << "Magnum::Text::MagnumFont::openData(): cannot open image file"; Error() << "Text::MagnumFont::openData(): cannot open image file";
return; return;
} }
Trade::ImageData2D* image = importer.image2D(0); Trade::ImageData2D* image = importer.image2D(0);
if(!image) { if(!image) {
Error() << "Magnum::Text::MagnumFont::openData(): cannot load image file"; Error() << "Text::MagnumFont::openData(): cannot load image file";
return; return;
} }
@ -114,13 +114,13 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) {
/* Open the configuration file */ /* Open the configuration file */
Utility::Configuration conf(filename, Utility::Configuration::Flag::ReadOnly|Utility::Configuration::Flag::SkipComments); Utility::Configuration conf(filename, Utility::Configuration::Flag::ReadOnly|Utility::Configuration::Flag::SkipComments);
if(!conf.isValid() || conf.isEmpty()) { if(!conf.isValid() || conf.isEmpty()) {
Error() << "Magnum::Text::MagnumFont::openFile(): cannot open file" << filename << conf.isValid(); Error() << "Text::MagnumFont::openFile(): cannot open file" << filename << conf.isValid();
return; return;
} }
/* Check version */ /* Check version */
if(conf.value<UnsignedInt>("version") != 1) { if(conf.value<UnsignedInt>("version") != 1) {
Error() << "Magnum::Text::MagnumFont::openFile(): unsupported file version, expected 1 but got" Error() << "Text::MagnumFont::openFile(): unsupported file version, expected 1 but got"
<< conf.value<UnsignedInt>("version"); << conf.value<UnsignedInt>("version");
return; return;
} }
@ -129,12 +129,12 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) {
const std::string imageFilename = Utility::Directory::join(Utility::Directory::path(filename), conf.value("image")); const std::string imageFilename = Utility::Directory::join(Utility::Directory::path(filename), conf.value("image"));
Trade::TgaImporter importer; Trade::TgaImporter importer;
if(!importer.openFile(imageFilename)) { if(!importer.openFile(imageFilename)) {
Error() << "Magnum::Text::MagnumFont::openFile(): cannot open image file" << imageFilename; Error() << "Text::MagnumFont::openFile(): cannot open image file" << imageFilename;
return; return;
} }
Trade::ImageData2D* image = importer.image2D(0); Trade::ImageData2D* image = importer.image2D(0);
if(!image) { if(!image) {
Error() << "Magnum::Text::MagnumFont::openFile(): cannot load image file"; Error() << "Text::MagnumFont::openFile(): cannot load image file";
return; return;
} }

4
src/Plugins/TgaImageConverter/TgaImageConverter.cpp

@ -57,12 +57,12 @@ Containers::Array<unsigned char> TgaImageConverter::doExportToData(const ImageRe
image.format() != ImageFormat::Red) image.format() != ImageFormat::Red)
#endif #endif
{ {
Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image.format(); Error() << "Trade::TgaImageConverter::convertToData(): unsupported image format" << image.format();
return nullptr; return nullptr;
} }
if(image.type() != ImageType::UnsignedByte) { if(image.type() != ImageType::UnsignedByte) {
Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type" << image.type(); Error() << "Trade::TgaImageConverter::convertToData(): unsupported image type" << image.type();
return nullptr; return nullptr;
} }

12
src/Plugins/TgaImporter/TgaImporter.cpp

@ -60,7 +60,7 @@ void TgaImporter::doOpenFile(const std::string& filename) {
in = new std::ifstream(filename.c_str()); in = new std::ifstream(filename.c_str());
if(in->good()) return; if(in->good()) return;
Error() << "Trade::TgaImporter::TgaImporter::openFile(): cannot open file" << filename; Error() << "Trade::TgaImporter::openFile(): cannot open file" << filename;
close(); close();
} }
@ -77,7 +77,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
std::streampos filesize = in->tellg(); std::streampos filesize = in->tellg();
in->seekg(0, std::istream::beg); in->seekg(0, std::istream::beg);
if(filesize < std::streampos(sizeof(TgaHeader))) { if(filesize < std::streampos(sizeof(TgaHeader))) {
Error() << "Trade::TgaImporter::TgaImporter::image2D(): the file is too short:" << filesize << "bytes"; Error() << "Trade::TgaImporter::image2D(): the file is too short:" << filesize << "bytes";
return nullptr; return nullptr;
} }
@ -91,7 +91,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
/* Image format */ /* Image format */
ImageFormat format; ImageFormat format;
if(header.colorMapType != 0) { if(header.colorMapType != 0) {
Error() << "Trade::TgaImporter::TgaImporter::image2D(): paletted files are not supported"; Error() << "Trade::TgaImporter::image2D(): paletted files are not supported";
return nullptr; return nullptr;
} }
@ -113,7 +113,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
#endif #endif
break; break;
default: default:
Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp; Error() << "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp;
return nullptr; return nullptr;
} }
@ -126,13 +126,13 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
format = ImageFormat::Red; format = ImageFormat::Red;
#endif #endif
if(header.bpp != 8) { if(header.bpp != 8) {
Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; Error() << "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp;
return nullptr; return nullptr;
} }
/* Compressed files */ /* Compressed files */
} else { } else {
Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType; Error() << "Trade::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType;
return nullptr; return nullptr;
} }

Loading…
Cancel
Save