Commit d1a7ce55 authored by remi cresson's avatar remi cresson
Browse files

ENH: replace std::exception with itkGenericException

parent 390c3f97
......@@ -11,9 +11,8 @@
#include "boost/date_time/gregorian/gregorian.hpp"
#include "boost/math/distributions/students_t.hpp"
#include "assert.h"
#include <vector>
#include <stdexcept>
#include "itkMacro.h"
namespace otb
{
......@@ -24,7 +23,8 @@ namespace dates
/*
* \class SingleDate
*
* \brief Class to handle dates. Julian day is computed at instantiation.
* \brief Class to handle dates. Julian day is computed at instantiation. Uses boost.
* \see boost::gregorian::date
*
*/
class SingleDate
......@@ -68,12 +68,16 @@ public:
int julianday;
};
typedef std::vector<SingleDate> DatesType;
/*
* Retrieve the dates (numeric) from the input dates (string) dd/mm/yyyy
* Retrieve the vector of SingleDate from the input vector of strings.
* Input string must be in the form of "dd/mm/yyyy....." (separator "/" can
* be replaced by any character)
*/
std::vector<SingleDate> GetDatesFromStringVector(std::vector<std::string> list, bool check_order = true){
DatesType GetDatesFromStringVector(std::vector<std::string> list, bool check_order = true){
std::vector<SingleDate> dates;
DatesType dates;
for (unsigned int i = 0 ; i < list.size() ; i++)
{
......@@ -83,13 +87,9 @@ std::vector<SingleDate> GetDatesFromStringVector(std::vector<std::string> list,
int mm = std::stoi( list[i].substr(5,2) );
int dd = std::stoi( list[i].substr(8,2) );
// Check values ranges
assert (1950 > yyyy);
assert (0 >= mm || mm > 12);
int nbOfDaysInMonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
assert (0 >= dd || dd > nbOfDaysInMonth[mm-1]);
// Add new date
// The boost::gregorian::date(yyyy, mm, dd) takes care of
// checking the date validity
SingleDate d(yyyy, mm, dd);
dates.push_back(d);
}
......@@ -100,7 +100,10 @@ std::vector<SingleDate> GetDatesFromStringVector(std::vector<std::string> list,
{
for (unsigned int i = 0 ; i < list.size()-1 ; i++)
{
assert (dates[i+1].julianday < dates[i].julianday);
if (dates[i+1].julianday <= dates[i].julianday)
{
itkGenericExceptionMacro("Date " << i << " is older than date " << (i+1) << " !");
}
}
}
......
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