Commit 46f6c305 authored by Ludovic Courtès's avatar Ludovic Courtès

data: Move I/O error handling to user interfaces.

parent 047aef1e
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2014 CNRS
Copyright (C) 2013, 2014 Inria
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -385,3 +385,34 @@ class timer
unsigned int _start, _stop;
unsigned int _elapsed;
};
// I/O error handling in user interfaces.
#include <iostream>
#include <cstdlib>
#ifndef _WIN32
# define CATCH_FILE_IO_ERROR(file) \
catch (std::ios_base::failure& e) { \
std::cerr << "<<ERROR>> failed to load '" \
<< (file) << "'" \
<< ": " << strerror(errno) \
<< std::endl; \
exit(EXIT_FAILURE); \
}
#else
// We cannot rely on 'errno' on Windows.
# define CATCH_FILE_IO_ERROR(file) \
catch (std::ios_base::failure& e) { \
std::cerr << "<<ERROR>> failed to load '" \
<< (file) << "'" \
<< std::endl; \
exit(EXIT_FAILURE); \
}
#endif /* _WIN32 */
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014 Inria
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -61,12 +61,12 @@ void vertical_segment::load(const std::string& filename)
void vertical_segment::load(const std::string& filename, const arguments& args)
{
std::ifstream file(filename.c_str()) ;
if(!file.is_open())
{
std::cerr << "<<ERROR>> unable to open file \"" << filename << "\"" << std::endl ;
throw std::exception();
}
std::ifstream file;
// Raise an exception when 'open' fails.
file.exceptions (std::ios::failbit);
file.open(filename.c_str());
file.exceptions (std::ios::goodbit);
vec min, max ;
vec ymin, ymax;
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014 Inria
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -71,7 +71,11 @@ int main(int argc, char** argv)
ptr<data> d = plugins_manager::get_data(args["data"]) ;
if(args.is_defined("data-file"))
{
d->load(args["data-file"]);
try
{
d->load(args["data-file"]);
}
CATCH_FILE_IO_ERROR(args["data-file"]);
}
// Get the output object. In the case where it is not a VS file, we use
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014 Inria
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -82,14 +82,11 @@ int main(int argc, char** argv)
// Load data file if the plugin manager created a plugin object.
if(d)
{
try
{
d->load(args["data-file"]);
}
catch(...)
{
return EXIT_FAILURE;
}
try
{
d->load(args["data-file"]);
}
CATCH_FILE_IO_ERROR (args["data-file"]);
}
else
{
......
......@@ -114,7 +114,12 @@ int main(int argc, char** argv)
ptr<function> f = plugins_manager::get_function(args);
ptr<data> d = plugins_manager::get_data(args["data"]);
d->load(args["input"], args);
try
{
d->load(args["input"], args);
}
CATCH_FILE_IO_ERROR(args["input"]);
if(!f || !d)
{
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2014 CNRS
Copyright (C) 2013, 2014 Inria
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -111,7 +111,12 @@ int main(int argc, char** argv)
// Import data
ptr<data> d_in = plugins_manager::get_data(args["in-data"]) ;
d_in->load(args["input"], args);
try
{
d_in->load(args["input"], args);
}
CATCH_FILE_IO_ERROR(args["input"]);
if(!d_in)
{
std::cout << "<<INFO>> input data will be treated as ALTA format" << std::endl;
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014, 2013, 2014 Inria
Copyright (C) 2013, 2014, 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -55,7 +55,11 @@ int main(int argc, char** argv)
// Import data
ptr<data> d = NULL ;
d = plugins_manager::get_data(args["data"]) ;
d->load(args["input"]);
try
{
d->load(args["input"]);
}
CATCH_FILE_IO_ERROR(args["input"]);
// Create output file
std::ofstream file(args["output"].c_str(), std::ios_base::trunc);
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014 Inria
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -44,7 +44,11 @@ int main(int argc, char** argv)
}
ptr<data> d = plugins_manager::get_data(args["data"]) ;
d->load(args["input"], args);
try
{
d->load(args["input"], args);
}
CATCH_FILE_IO_ERROR(args["input"]);
// Create output file
std::ofstream file(args["output"].c_str(), std::ios_base::trunc);
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014 Inria
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -85,7 +85,11 @@ int main(int argc, char** argv)
std::cerr << "<<ERROR>> this data object is not interpolant." << std::endl;
return 1;
}
d->load(args["input"]);
try
{
d->load(args["input"]);
}
CATCH_FILE_IO_ERROR(args["input"]);
// Create output file
std::ofstream file(args["output"].c_str(), std::ios_base::trunc);
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014 Inria
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
......@@ -51,7 +51,11 @@ int main(int argc, char** argv)
ptr<data> d = NULL ;
d = manager.get_data(args["loader"]) ;
d->load(args["input"]);
try
{
d->load(args["input"]);
}
CATCH_FILE_IO_ERROR(args["input"])
// Create output file
std::ofstream file(args["output"].c_str(), std::ios_base::trunc);
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013 Inria
Copyright (C) 2013, 2015 Inria
This file is part of ALTA.
......@@ -43,22 +43,26 @@ int main(int argc, char** argv)
// Load the data
rational_1d_data data ;
if(args.is_defined("min") && args.is_defined("max"))
try
{
data.load(args["input"], args.get_float("min", 0.0f), args.get_float("max", 1.0f));
}
else if(args.is_defined("min") && !args.is_defined("max"))
{
data.load(args["input"], args.get_float("min", 0.0f), std::numeric_limits<double>::max());
}
else if(args.is_defined("min") && !args.is_defined("max"))
{
data.load(args["input"], -std::numeric_limits<double>::max(), args.get_float("min", 0.0f));
}
else
{
data.load(args["input"]);
if(args.is_defined("min") && args.is_defined("max"))
{
data.load(args["input"], args.get_float("min", 0.0f), args.get_float("max", 1.0f));
}
else if(args.is_defined("min") && !args.is_defined("max"))
{
data.load(args["input"], args.get_float("min", 0.0f), std::numeric_limits<double>::max());
}
else if(args.is_defined("min") && !args.is_defined("max"))
{
data.load(args["input"], -std::numeric_limits<double>::max(), args.get_float("min", 0.0f));
}
else
{
data.load(args["input"]);
}
}
CATCH_FILE_IO_ERROR(args["input"]);
// Fitting call
rational_1d_fitter* fitter ;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment