00001
00002
00003
00004
00020 #if !defined(__ads_index_h__)
00021 #define __ads_index_h__
00022
00023 #include "../defs.h"
00024
00025 #include <iterator>
00026 #include <functional>
00027
00028 BEGIN_NAMESPACE_ADS
00029
00030
00032
00033
00035 template <typename RAIter>
00036 class IndexIteratorFunctor :
00037 public std::binary_function<RAIter,
00038 int,
00039 typename std::iterator_traits
00040 <RAIter>::reference> {
00041 private:
00042 typedef std::binary_function<RAIter,
00043 int,
00044 typename std::iterator_traits
00045 <RAIter>::reference> Base;
00046
00047 public:
00048
00050 typedef typename Base::first_argument_type first_argument_type;
00052 typedef typename Base::second_argument_type second_argument_type;
00054 typedef typename Base::result_type result_type;
00055
00057 result_type
00058 operator()(first_argument_type x, second_argument_type i) const {
00059 return x[i];
00060 }
00061 };
00062
00064 template <typename RAIter>
00065 inline
00066 IndexIteratorFunctor<RAIter>
00067 index_iterator_functor() {
00068 return IndexIteratorFunctor<RAIter>();
00069 }
00070
00071
00072
00073
00075 template <typename RAIter>
00076 class IndexIterUnary :
00077 public std::unary_function<int,
00078 typename std::iterator_traits
00079 <RAIter>::reference> {
00080
00081
00082
00083
00084 private:
00085
00086 typedef std::unary_function<int,
00087 typename std::iterator_traits
00088 <RAIter>::reference> Base;
00089
00090
00091
00092
00093
00094 public:
00095
00097 typedef typename Base::argument_type argument_type;
00099 typedef typename Base::result_type result_type;
00101 typedef RAIter iterator;
00102
00103
00104
00105
00106
00107 private:
00108
00109 iterator _i;
00110
00111
00112
00113
00114
00115 private:
00116
00117 IndexIterUnary();
00118
00119
00120
00121
00122
00123
00124 public:
00125
00127 IndexIterUnary(iterator i) :
00128 _i(i)
00129 {}
00130
00131
00132
00133
00134
00136 result_type
00137 operator()(argument_type n) const {
00138 return _i[n];
00139 }
00140 };
00141
00143 template <typename RAIter>
00144 inline
00145 IndexIterUnary<RAIter>
00146 index_iter_unary(RAIter i) {
00147 return IndexIterUnary<RAIter>(i);
00148 }
00149
00150
00151
00152
00154 template <typename Object>
00155 class IndexObject :
00156 public std::binary_function<Object, int, typename Object::reference> {
00157 private:
00158 typedef std::binary_function<Object, int, typename Object::reference>
00159 Base;
00160
00161 public:
00162
00164 typedef typename Base::first_argument_type first_argument_type;
00166 typedef typename Base::second_argument_type second_argument_type;
00168 typedef typename Base::result_type result_type;
00169
00171 result_type
00172 operator()(first_argument_type& x, second_argument_type i) const {
00173 return x[i];
00174 }
00175 };
00176
00178 template <typename Object>
00179 class IndexConstObject :
00180 public std::binary_function<Object, int, typename Object::parameter_type> {
00181 private:
00182 typedef std::binary_function<Object, int, typename Object::parameter_type>
00183 Base;
00184
00185 public:
00186
00188 typedef typename Base::first_argument_type first_argument_type;
00190 typedef typename Base::second_argument_type second_argument_type;
00192 typedef typename Base::result_type result_type;
00193
00195 result_type
00196 operator()(const first_argument_type& x, second_argument_type i) const {
00197 return x[i];
00198 }
00199 };
00200
00202 template <typename Object>
00203 inline
00204 IndexObject<Object>
00205 index_object() {
00206 return IndexObject<Object>();
00207 }
00208
00210 template <typename Object>
00211 inline
00212 IndexConstObject<Object>
00213 index_const_object() {
00214 return IndexConstObject<Object>();
00215 }
00216
00217
00218
00219 END_NAMESPACE_ADS
00220
00221 #endif