Adobe Systems, Inc.

type_vector.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2006 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://opensource.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef GIL_DYNAMICIMAGE_TYPE_VECTOR_HPP
00010 #define GIL_DYNAMICIMAGE_TYPE_VECTOR_HPP
00011 
00020 
00021 #include "../../core/gil_config.hpp"
00022 #include <boost/mpl/at.hpp>
00023 #include <boost/mpl/divides.hpp>
00024 #include <boost/mpl/find.hpp>
00025 #include <boost/mpl/front.hpp>
00026 #include <boost/mpl/modulus.hpp>
00027 #include <boost/mpl/order.hpp>
00028 #include <boost/mpl/pop_front.hpp>
00029 #include <boost/mpl/pop_back.hpp>
00030 #include <boost/mpl/set.hpp>
00031 #include <boost/mpl/size.hpp>
00032 #include <boost/mpl/sizeof.hpp>
00033 #include <boost/mpl/times.hpp>
00034 #include <boost/mpl/transform.hpp>
00035 #include <boost/mpl/vector.hpp>
00036 
00037 
00038 namespace boost { 
00039 namespace mpl {
00040 
00059 
00060 template <typename VEC_OF_VECS, typename TYPE_GEN>
00061 struct cross_vector {};
00062 
00065 template <typename VEC_OF_VECS, typename TYPE_GEN, std::size_t K>
00066 struct cross_iterator {
00067     typedef boost::mpl::random_access_iterator_tag category;
00068 };
00069 
00070 namespace detail {
00089     template <typename VEC_OF_VECS, std::size_t N, std::size_t B_SIZE>
00090     struct _select_subvector {
00091     private:
00092         typedef typename front<VEC_OF_VECS>::type cur_vec;
00093         static const std::size_t cur_base = size<cur_vec>::value;
00094         typedef typename pop_front<VEC_OF_VECS>::type                     next_vec_of_vecs; 
00095         typedef typename _select_subvector<next_vec_of_vecs,  N/cur_base, B_SIZE-1>::type next_subvector;
00096     public:
00097         typedef typename push_front<next_subvector, typename at_c<cur_vec, N%cur_base>::type >::type type;
00098     };
00099 
00100     template <typename VEC_OF_VECS, std::size_t N>
00101     struct _select_subvector<VEC_OF_VECS, N, 0> {
00102         typedef vector<>::type type;
00103     };
00104 
00105     template <typename VEC_OF_VECS, std::size_t N>
00106     struct select_subvector_c {
00107         typedef typename _select_subvector<VEC_OF_VECS, N, size<VEC_OF_VECS>::value>::type type;
00108     };
00109 }
00110 
00114 
00120 template <typename VEC_OF_VECS, typename TYPE_GEN, std::size_t K>
00121 struct deref<cross_iterator<VEC_OF_VECS,TYPE_GEN,K> > {
00122 private:
00123     typedef typename detail::select_subvector_c<VEC_OF_VECS, K>::type DerefTypes;
00124 public:
00125     typedef typename TYPE_GEN::template apply<DerefTypes>::type type;
00126 };
00127 
00130 template <typename VEC_OF_VECS, typename TYPE_GEN, std::size_t K>
00131 struct next<cross_iterator<VEC_OF_VECS,TYPE_GEN,K> > {
00132     typedef cross_iterator<VEC_OF_VECS,TYPE_GEN,K+1> type;
00133 };
00134 
00137 template <typename VEC_OF_VECS, typename TYPE_GEN, std::size_t K>
00138 struct prior<cross_iterator<VEC_OF_VECS,TYPE_GEN,K> > {
00139     typedef cross_iterator<VEC_OF_VECS,TYPE_GEN,K-1> type;
00140 };
00141 
00144 template <typename VEC_OF_VECS, typename TYPE_GEN, std::size_t K, typename DISTANCE>
00145 struct advance<cross_iterator<VEC_OF_VECS,TYPE_GEN,K>, DISTANCE > {
00146     typedef cross_iterator<VEC_OF_VECS,TYPE_GEN,K+DISTANCE::value> type;
00147 };
00148 
00151 // (shortened the names of the template arguments - otherwise doxygen cannot parse this...)
00152 template <typename V_OF_V, typename T_GEN, std::size_t K1, std::size_t K2>
00153 struct distance<cross_iterator<V_OF_V,T_GEN,K1>, cross_iterator<V_OF_V,T_GEN,K2> > {
00154     typedef size_t<K2-K1> type;
00155 };
00156 
00162 template <typename VEC_OF_VECS, typename TYPE_GEN>
00163 struct size<cross_vector<VEC_OF_VECS,TYPE_GEN> > {
00164     typedef typename fold<VEC_OF_VECS, size_t<1>, times<_1, size<_2> > >::type type;
00165     static const std::size_t value=type::value;
00166 };
00167 
00170 template <typename VEC_OF_VECS, typename TYPE_GEN>
00171 struct empty<cross_vector<VEC_OF_VECS,TYPE_GEN> > {
00172     typedef typename empty<VEC_OF_VECS>::type type;
00173 };
00174 
00177 template <typename VEC_OF_VECS, typename TYPE_GEN, typename K>
00178 struct at<cross_vector<VEC_OF_VECS,TYPE_GEN>, K> {
00179 private:
00180     typedef cross_iterator<VEC_OF_VECS,TYPE_GEN,K::value> KthIterator;
00181 public:
00182     typedef typename deref<KthIterator>::type type;
00183 };
00184 
00187 template <typename VEC_OF_VECS, typename TYPE_GEN>
00188 struct begin<cross_vector<VEC_OF_VECS,TYPE_GEN> > {
00189     typedef cross_iterator<VEC_OF_VECS,TYPE_GEN,0> type;
00190 };
00191 
00194 template <typename VEC_OF_VECS, typename TYPE_GEN>
00195 struct end<cross_vector<VEC_OF_VECS,TYPE_GEN> > {
00196 private:
00197     typedef cross_vector<VEC_OF_VECS,TYPE_GEN> this_t;
00198 public:
00199     typedef cross_iterator<VEC_OF_VECS,TYPE_GEN,size<this_t>::value> type;
00200 };
00201 
00204 template <typename VEC_OF_VECS, typename TYPE_GEN>
00205 struct front<cross_vector<VEC_OF_VECS,TYPE_GEN> > {
00206 private:
00207     typedef cross_vector<VEC_OF_VECS,TYPE_GEN> this_t;
00208 public:
00209     typedef typename deref<typename begin<this_t>::type>::type type;
00210 };
00211 
00214 template <typename VEC_OF_VECS, typename TYPE_GEN>
00215 struct back<cross_vector<VEC_OF_VECS,TYPE_GEN> > {
00216 private:
00217     typedef cross_vector<VEC_OF_VECS,TYPE_GEN> this_t;
00218     typedef typename size<this_t>::type         size;
00219     typedef typename minus<size, size_t<1> >::type last_index;
00220 public:
00221     typedef typename at<this_t, last_index>::type type;
00222 };
00223 
00226 template <typename VEC_OF_VECS, typename TYPE_GEN, typename OPP>
00227 struct transform<cross_vector<VEC_OF_VECS,TYPE_GEN>, OPP > {
00228     typedef typename lambda<OPP>::type OP;
00229     struct adapter {
00230         template <typename ELEMENTS> 
00231         struct apply {
00232             typedef typename TYPE_GEN::template apply<ELEMENTS>::type orig_t;
00233             typedef typename OP::template apply<orig_t>::type type;
00234         };
00235     };
00236     typedef cross_vector<VEC_OF_VECS, adapter > type; 
00237 };
00238 
00249 
00250 template <typename VEC1, typename VEC2>
00251 struct concat_vector {};
00252 
00255 template <typename VEC1, typename VEC2, std::size_t K>
00256 struct concat_vector_iterator {
00257     typedef random_access_iterator_tag category;
00258 };
00259 
00262 template <typename VEC1, typename VEC2, std::size_t K>
00263 struct deref<concat_vector_iterator<VEC1,VEC2,K> > {
00264 private:
00265     static const std::size_t V1Size = size<VEC1>::value;
00266     typedef typename if_<less<size_t<K>,size_t<V1Size> >, VEC1, VEC2>::type VEC;
00267     static const std::size_t index = K - ((K < V1Size) ? 0 : V1Size);
00268 public:
00269     typedef typename at_c<VEC,index>::type type;
00270 };
00271 
00274 template <typename VEC1, typename VEC2, std::size_t K>
00275 struct next<concat_vector_iterator<VEC1,VEC2,K> > {
00276     typedef concat_vector_iterator<VEC1,VEC2,K+1> type;
00277 };
00278 
00281 template <typename VEC1, typename VEC2, std::size_t K>
00282 struct prior<concat_vector_iterator<VEC1,VEC2,K> > {
00283     typedef concat_vector_iterator<VEC1,VEC2,K-1> type;
00284 };
00285 
00288 template <typename VEC1, typename VEC2, std::size_t K, typename DISTANCE>
00289 struct advance<concat_vector_iterator<VEC1,VEC2,K>, DISTANCE > {
00290     typedef concat_vector_iterator<VEC1,VEC2,K+DISTANCE::value> type;
00291 };
00292 
00295 template <typename VEC1, typename VEC2, std::size_t K1, std::size_t K2>
00296 struct distance<concat_vector_iterator<VEC1,VEC2,K1>, concat_vector_iterator<VEC1,VEC2,K2> > {
00297     typedef size_t<K2-K1> type;
00298 };
00299 
00303 
00306 template <typename VEC1, typename VEC2>
00307 struct size<concat_vector<VEC1,VEC2> > {
00308     static const std::size_t value=size<VEC1>::value+size<VEC2>::value;
00309     typedef size_t<value> type;
00310 };
00311 
00314 template <typename VEC1, typename VEC2>
00315 struct empty<concat_vector<VEC1,VEC2> > {
00316     typedef typename and_<empty<VEC1>,empty<VEC2> >::type type;
00317 };
00318 
00321 template <typename VEC1, typename VEC2, typename K>
00322 struct at<concat_vector<VEC1,VEC2>, K> {
00323 private:
00324     typedef concat_vector_iterator<VEC1,VEC2,K::value> KthIterator;
00325 public:
00326     typedef typename deref<KthIterator>::type type;
00327 };
00328 
00331 template <typename VEC1, typename VEC2>
00332 struct begin<concat_vector<VEC1,VEC2> > {
00333     typedef concat_vector_iterator<VEC1,VEC2,0> type;
00334 };
00335 
00338 template <typename VEC1, typename VEC2>
00339 struct end<concat_vector<VEC1,VEC2> > {
00340 private:
00341     typedef concat_vector<VEC1,VEC2> this_t;
00342 public:
00343     typedef concat_vector_iterator<VEC1,VEC2,size<this_t>::value> type;
00344 };
00345 
00348 template <typename VEC1, typename VEC2>
00349 struct front<concat_vector<VEC1,VEC2> > {
00350 private:
00351     typedef concat_vector<VEC1,VEC2> this_t;
00352 public:
00353     typedef typename deref<typename begin<this_t>::type>::type type;
00354 };
00355 
00358 template <typename VEC1, typename VEC2>
00359 struct back<concat_vector<VEC1,VEC2> > {
00360 private:
00361     typedef concat_vector<VEC1,VEC2>              this_t;
00362     typedef typename size<this_t>::type           size;
00363     typedef typename minus<size, size_t<1> >::type last_index;
00364 public:
00365     typedef typename at<this_t, last_index>::type type;
00366 };
00367 
00370 template <typename VEC1, typename VEC2, typename OP>
00371 struct transform<concat_vector<VEC1,VEC2>, OP> {
00372     typedef concat_vector<typename transform<VEC1,OP>::type, typename transform<VEC2,OP>::type> type;
00373 };
00374 
00375 
00384 
00385 template <typename SRC_TYPES, typename DST_TYPES>
00386 struct mapping_vector {};
00387 
00388 template <typename SRC_TYPES, typename DST_TYPES, long K>
00389 struct at_c<mapping_vector<SRC_TYPES,DST_TYPES>, K> {
00390     static const std::size_t value=size<DST_TYPES>::value - order<DST_TYPES, typename at_c<SRC_TYPES,K>::type>::type::value +1;
00391     typedef size_t<value> type;
00392 };
00393 
00394 template <typename SRC_TYPES, typename DST_TYPES>
00395 struct size<mapping_vector<SRC_TYPES,DST_TYPES> > {
00396     typedef typename size<SRC_TYPES>::type type;
00397     static const std::size_t value=type::value;
00398 };
00399 
00408 
00409 namespace detail {
00410     template <typename S_FIRST, std::size_t N_LEFT>
00411     struct copy_to_vector_impl {
00412     private:
00413         typedef typename deref<S_FIRST>::type T;
00414         typedef typename next<S_FIRST>::type next;
00415         typedef typename copy_to_vector_impl<next, N_LEFT-1>::type rest;
00416     public:
00417         typedef typename push_front<rest, T>::type type;
00418     };
00419 
00420     template <typename S_FIRST> 
00421     struct copy_to_vector_impl<S_FIRST,1> {
00422         typedef vector<typename deref<S_FIRST>::type> type;
00423     };
00424 }
00425 
00426 template <typename SRC>
00427 struct copy_to_vector {
00428     typedef typename detail::copy_to_vector_impl<typename begin<SRC>::type, size<SRC>::value>::type type;
00429 };
00430 
00431 template <>
00432 struct copy_to_vector<set<> > {
00433     typedef vector0<> type;
00434 };
00435 
00436 } }     // namespace boost::mpl
00437 
00438 ADOBE_GIL_NAMESPACE_BEGIN
00439 
00440 
00442 template <typename TYPES, typename T>
00443 struct type_to_index {
00444 private:
00445     typedef typename boost::mpl::find<TYPES, T>::type   it;
00446     typedef typename boost::mpl::begin<TYPES>::type     first;
00447 public:
00448     typedef typename boost::mpl::distance<first, it>::type type;
00449     static const std::size_t value=type::value;
00450 };
00451 
00452 ADOBE_GIL_NAMESPACE_END
00453 
00454 #endif
00455 

Copyright © 2006 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google