Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into esri
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Jun 19, 2020
2 parents 35323b8 + 3a54bac commit 96856ca
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion io/EptReader.cpp
Expand Up @@ -84,7 +84,7 @@ class EptBounds : public SrsBounds
namespace Utils
{
template<>
bool fromString<EptBounds>(const std::string& s, EptBounds& bounds)
StatusWithReason fromString(const std::string& s, EptBounds& bounds)
{
if (!fromString(s, (SrsBounds&)bounds))
return false;
Expand Down
4 changes: 3 additions & 1 deletion pdal/EigenUtils.hpp
Expand Up @@ -279,7 +279,9 @@ namespace Utils
{

template <>
inline bool fromString<Eigen::MatrixXd>(const std::string& s, Eigen::MatrixXd& matrix) {
inline StatusWithReason fromString(const std::string& s,
Eigen::MatrixXd& matrix)
{
std::stringstream ss(s);
std::string line;
std::vector<std::vector<double>> rows;
Expand Down
2 changes: 1 addition & 1 deletion pdal/SrsBounds.hpp
Expand Up @@ -64,7 +64,7 @@ class PDAL_DLL SrsBounds : public Bounds
namespace Utils
{
template<>
inline bool fromString<SrsBounds>(const std::string& s,
inline StatusWithReason fromString(const std::string& s,
SrsBounds& srsBounds)
{
std::string::size_type pos(0);
Expand Down
25 changes: 20 additions & 5 deletions pdal/util/ProgramArgs.hpp
Expand Up @@ -407,13 +407,20 @@ class TArg : public Arg
}

m_rawVal = s;
if (!Utils::fromString(s, m_var))
auto status = Utils::fromString(s, m_var);
if (!status)
{
std::string error(m_error);

if (error.empty())
error = "Invalid value '" + s + "' for argument '" +
m_longname + "'.";
{
if (status.what().size())
error = "Invalid value for argument '" + m_longname +
"': " + status.what();
else
error = "Invalid value '" + s + "' for argument '" +
m_longname + "'.";
}
throw arg_val_error(error);
}
m_set = true;
Expand Down Expand Up @@ -755,12 +762,20 @@ class VArg : public BaseVArg
T var;

m_rawVal = s;
if (!Utils::fromString(s, var))
auto status = Utils::fromString(s, var);
if (!status)
{
std::string error(m_error);

if (error.empty())
error = "Invalid value for argument '" + m_longname + "'.";
{
if (status.what().size())
error = "Invalid value for argument '" + m_longname +
"': " + status.what();
else
error = "Invalid value '" + s + "' for argument '" +
m_longname + "'.";
}
throw arg_val_error(error);
}
if (!m_set)
Expand Down
23 changes: 15 additions & 8 deletions pdal/util/Utils.hpp
Expand Up @@ -82,6 +82,14 @@ namespace Utils
public:
StatusWithReason() : m_code(0)
{}
StatusWithReason(bool ok)
{
if (ok)
m_code = 0;
else
m_code = -1;
}
StatusWithReason(int code); // Not defined
StatusWithReason(int code, const std::string& what) :
m_code(code), m_what(what)
{}
Expand Down Expand Up @@ -929,7 +937,7 @@ namespace Utils


template<typename T>
bool fromString(const std::string& from, T* & to)
StatusWithReason fromString(const std::string& from, T* & to)
{
void *v;
// Uses sscanf instead of operator>>(istream, void*&) as a workaround
Expand All @@ -951,7 +959,7 @@ namespace Utils
\return \c true if the conversion was successful, \c false otherwise.
*/
template<typename T>
bool fromString(const std::string& from, T& to)
StatusWithReason fromString(const std::string& from, T& to)
{
std::istringstream iss(from);

Expand All @@ -961,7 +969,7 @@ namespace Utils

// Optimization of above.
template<>
inline bool fromString(const std::string& from, std::string& to)
inline StatusWithReason fromString(const std::string& from, std::string& to)
{
to = from;
return true;
Expand All @@ -975,7 +983,7 @@ namespace Utils
\return \c true if the conversion was successful, \c false otherwise.
*/
template<>
inline bool fromString<char>(const std::string& s, char& to)
inline StatusWithReason fromString(const std::string& s, char& to)
{
try
{
Expand Down Expand Up @@ -1006,8 +1014,7 @@ namespace Utils
\return \c true if the conversion was successful, \c false otherwise.
*/
template<>
inline bool fromString<unsigned char>(const std::string& s,
unsigned char& to)
inline StatusWithReason fromString(const std::string& s, unsigned char& to)
{
try
{
Expand Down Expand Up @@ -1039,7 +1046,7 @@ namespace Utils
\return \c true if the conversion was successful, \c false otherwise.
*/
template<>
inline bool fromString<signed char>(const std::string& s, signed char& to)
inline StatusWithReason fromString(const std::string& s, signed char& to)
{
try
{
Expand Down Expand Up @@ -1070,7 +1077,7 @@ namespace Utils
\return \c true if the conversion was successful, \c false otherwise.
*/
template<>
inline bool fromString<double>(const std::string& s, double& d)
inline StatusWithReason fromString(const std::string& s, double& d)
{
if (s == "nan" || s == "NaN")
{
Expand Down

0 comments on commit 96856ca

Please sign in to comment.