Mercurial > hg > octave-image
diff src/conndef.h @ 893:f34897bc944f
connectivity: move the validate() static methods into the constructor.
* conndef.cc (Fiptconncheck): this function performs a bunch of logic
that is useful for a constructor from octave_value. But if we move it
there, then all the validate static methods are no longer needed, and
we can just check by calling the constructor.
(invalid_connectivity): an exception class so we can give meaningful
error messages on why the constructor failed (and the check failed).
(Fconncheck): make the position arg optional.
* conndef.h: declare new exception class for incorrect connectivity
arguments, remove the validate methods and add them to the constructor
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Thu, 02 Oct 2014 16:39:05 +0100 (2014-10-02) |
parents | a2140b980079 |
children |
line wrap: on
line diff
--- a/src/conndef.h +++ b/src/conndef.h @@ -17,6 +17,8 @@ #ifndef OCTAVE_IMAGE_CONNDEF #define OCTAVE_IMAGE_CONNDEF +#include <stdexcept> + #include <octave/oct.h> namespace octave @@ -27,6 +29,10 @@ { public: connectivity (); + + //! Will throw if val is bad + connectivity (const octave_value& val); + connectivity (const boolNDArray& mask); connectivity (const octave_idx_type& conn); connectivity (const octave_idx_type& ndims, const std::string& type); @@ -36,8 +42,23 @@ // connected elements (will have negative and positive values). Array<octave_idx_type> offsets (const dim_vector& size) const; - static bool validate (const boolNDArray& mask); - static bool validate (const double& conn); + private: + void ctor (const boolNDArray& mask); + void ctor (const octave_idx_type& conn); + + //! Like octave_value::double_value() but actually checks if scalar. + static double double_value (const octave_value& val); + + //! Like octave_value::bool_array_value() but actually checks if + //! all values are zeros and one. + static boolNDArray bool_array_value (const octave_value& val); + }; + + class invalid_connectivity : public std::invalid_argument + { + public: + invalid_connectivity (const std::string& what_arg) + : std::invalid_argument (what_arg) { } }; } }