00001 #ifndef CCTBX_MAPTBX_MAP_OUT_OF_BOUNDS_H
00002 #define CCTBX_MAPTBX_MAP_OUT_OF_BOUNDS_H
00003
00004 namespace cctbx {
00005
00006 namespace maptbx {
00007
00008 struct raise;
00009 struct substitute;
00010 struct clamp;
00011 struct interpolate;
00012
00013
00014 template < typename DealWithItType,
00015 typename FloatType,
00016 typename IntType >
00017 struct out_of_bounds;
00018
00019
00020 template < typename FloatType, typename IntType >
00021 struct out_of_bounds<void,FloatType,IntType> {
00022 typedef out_of_bounds<void,FloatType,IntType> h_oob;
00023 typedef chiltbx::handle::handle<h_oob> handle_type;
00024 virtual handle_type as_handle () const = 0;
00025
00026 virtual FloatType retry (
00027 generic_grid<void,FloatType,IntType> const&,
00028 transform<grid_point<IntType>, fractional<FloatType> > const&,
00029 fractional<FloatType> const& ) const = 0;
00030 };
00031
00032 template < typename FloatType, typename IntType >
00033 struct out_of_bounds<raise,FloatType,IntType>
00034 : public out_of_bounds<void,FloatType,IntType> {
00035 typedef out_of_bounds<void,FloatType,IntType> h_oob;
00036 typedef chiltbx::handle::handle<h_oob> handle_type;
00037 virtual handle_type as_handle () const {
00038 return handle_type(*this);
00039 }
00040
00041 virtual FloatType retry (
00042 generic_grid<void,FloatType,IntType> const&,
00043 transform<grid_point<IntType>, fractional<FloatType> > const&,
00044 fractional<FloatType> const& ) const {
00045 throw error("basic_map<T>: the coordinate is out of bounds.");
00046 }
00047 };
00048
00049 template < typename FloatType, typename IntType >
00050 struct out_of_bounds<clamp,FloatType,IntType>
00051 : public out_of_bounds<void,FloatType,IntType> {
00052 out_of_bounds ( FloatType const& value ) : value_(value) {}
00053 typedef out_of_bounds<void,FloatType,IntType> h_oob;
00054 typedef chiltbx::handle::handle<h_oob> handle_type;
00055 virtual handle_type as_handle () const {
00056 return handle_type(*this);
00057 }
00058
00059 virtual FloatType retry (
00060 generic_grid<void,FloatType,IntType> const&,
00061 transform<grid_point<IntType>, fractional<FloatType> > const&,
00062 fractional<FloatType> const& ) const {
00063 throw this->value_;
00064 }
00065 FloatType value_;
00066 };
00067
00068 template < typename FloatType, typename IntType >
00069 struct out_of_bounds<substitute,FloatType,IntType>
00070 : public out_of_bounds<void,FloatType,IntType> {
00071 out_of_bounds ( FloatType const& value ) : value_(value) {}
00072 typedef out_of_bounds<void,FloatType,IntType> h_oob;
00073 typedef chiltbx::handle::handle<h_oob> handle_type;
00074 virtual handle_type as_handle () const {
00075 return handle_type(*this);
00076 }
00077
00078 virtual FloatType retry (
00079 generic_grid<void,FloatType,IntType> const&,
00080 transform<grid_point<IntType>, fractional<FloatType> > const&,
00081 fractional<FloatType> const& ) const {
00082 return this->value_;
00083 }
00084 FloatType value_;
00085 };
00086
00087 template < typename FloatType, typename IntType >
00088 struct out_of_bounds<interpolate,FloatType,IntType>
00089 : public out_of_bounds<void,FloatType,IntType> {
00090 typedef out_of_bounds<void,FloatType,IntType> h_oob;
00091 typedef chiltbx::handle::handle<h_oob> handle_type;
00092 virtual handle_type as_handle () const {
00093 return handle_type(*this);
00094 }
00095
00096 virtual FloatType retry (
00097 generic_grid<void,FloatType,IntType> const&,
00098 transform<grid_point<IntType>, fractional<FloatType> > const&,
00099 fractional<FloatType> const& ) const {
00100 throw error("basic_mapper<T>: non-trivial interpolation is not implemented.");
00101 }
00102 };
00103
00104 }
00105
00106 }
00107
00108 #endif//CCTBX_MAPTBX_MAP_OUT_OF_BOUNDS_H