00001 #ifndef GRAL_GB_BASE_MAPPED_GRID_FUNCTION_H
00002 #define GRAL_GB_BASE_MAPPED_GRID_FUNCTION_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "Gral/Base/common-grid-basics.h"
00019 #include "Utility/ref-ptr.h"
00020 #include "Container/mapped-value-iterator.h"
00021
00022
00023 namespace GrAL {
00024
00034 template<class GF, class F>
00035 class mapped_grid_function {
00036 typedef GF base_grid_function;
00037 typedef typename GF::const_iterator base_const_iterator;
00038
00039 public:
00040 typedef grid_function_view_category<typename category<GF>::type> category;
00041
00042 typedef F mapping_type;
00043 typedef typename F::result_type value_type;
00044 typedef value_type& reference;
00045 typedef value_type const_reference;
00046 typedef typename GF::element_type element_type;
00047 typedef typename GF::size_type size_type;
00048 typedef typename GF::pointer pointer;
00049 typedef typename GF::difference_type difference_type;
00050
00051 typedef typename GF::grid_type grid_type;
00052 typedef mapped_value_const_iterator<base_const_iterator, mapping_type>
00053 const_iterator;
00054
00055
00056 typedef value_type result_type;
00057 typedef element_type argument_type;
00058 private:
00059 ref_ptr<base_grid_function> gf;
00060 ref_ptr<mapping_type> f;
00061 public:
00062 mapped_grid_function() {}
00063 mapped_grid_function(base_grid_function & gf1, mapping_type & f1)
00064 : gf(gf1), f(f1) {}
00065 mapped_grid_function(ref_ptr<base_grid_function> gf1,
00066 ref_ptr<mapping_type> f1)
00067 : gf(gf1), f(f1) {}
00068
00069 void init(base_grid_function & gf1, mapping_type & f1)
00070 {
00071 gf = ref_ptr<base_grid_function>(gf1);
00072 f = ref_ptr<mapping_type> (f);
00073 }
00074 void init(ref_ptr<base_grid_function> gf1,
00075 ref_ptr<mapping_type> f1)
00076 {
00077 gf = gf1;
00078 f = f1;
00079 }
00080
00081 value_type operator()(element_type const& e) const { return (*f)((*gf)(e));}
00082
00083 size_type size() const { return gf->size();}
00084 const_iterator begin() const { return const_iterator(gf->begin(), f);}
00085 const_iterator end () const { return const_iterator(gf->end (), f);}
00086
00087
00088 bool defined(element_type const& e) const { return gf->defined(e);}
00089
00090 grid_type const& TheGrid() const { return gf->TheGrid();}
00091 mapping_type const& TheMapping() const { return *f;}
00092 };
00093
00094 }
00095
00096 #endif
00097