123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187 |
- #ifndef GIL_CONCEPT_H
- #define GIL_CONCEPT_H
- #include <functional>
- #include "gil_config.hpp"
- #include <boost/type_traits.hpp>
- #include <boost/utility/enable_if.hpp>
- #include <boost/concept_check.hpp>
- #include <boost/iterator/iterator_concepts.hpp>
- #include <boost/mpl/and.hpp>
- #include <boost/mpl/size.hpp>
- namespace boost { namespace gil {
- template <typename T> struct channel_traits;
- template <typename P> struct is_pixel;
- template <typename dstT, typename srcT>
- typename channel_traits<dstT>::value_type channel_convert(const srcT& val);
- template <typename T> class point2;
- template <std::size_t K, typename T> const T& axis_value(const point2<T>& p);
- template <std::size_t K, typename T> T& axis_value( point2<T>& p);
- template <typename ColorBase, int K> struct kth_element_type;
- template <typename ColorBase, int K> struct kth_element_reference_type;
- template <typename ColorBase, int K> struct kth_element_const_reference_type;
- template <typename ColorBase, int K> struct kth_semantic_element_reference_type;
- template <typename ColorBase, int K> struct kth_semantic_element_const_reference_type;
- template <typename ColorBase> struct size;
- template <typename ColorBase> struct element_type;
- template <typename T> struct channel_type;
- template <typename T> struct color_space_type;
- template <typename T> struct channel_mapping_type;
- template <typename T> struct is_planar;
- template <typename T> struct num_channels;
- template <typename It> struct const_iterator_type;
- template <typename It> struct iterator_is_mutable;
- template <typename It> struct is_iterator_adaptor;
- template <typename It, typename NewBaseIt> struct iterator_adaptor_rebind;
- template <typename It> struct iterator_adaptor_get_base;
- namespace detail { template <typename Element, typename Layout, int K> struct homogeneous_color_base; }
- template <int K, typename E, typename L, int N>
- typename add_reference<E>::type at_c( detail::homogeneous_color_base<E,L,N>& p);
- template <int K, typename E, typename L, int N>
- typename add_reference<typename add_const<E>::type>::type at_c(const detail::homogeneous_color_base<E,L,N>& p);
- #if !defined(_MSC_VER) || _MSC_VER > 1310
- template <typename P, typename C, typename L> struct packed_pixel;
- template <int K, typename P, typename C, typename L>
- typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type
- at_c(packed_pixel<P,C,L>& p);
- template <int K, typename P, typename C, typename L>
- typename kth_element_const_reference_type<packed_pixel<P,C,L>,K>::type
- at_c(const packed_pixel<P,C,L>& p);
- template <typename B, typename C, typename L, bool M> struct bit_aligned_pixel_reference;
- template <int K, typename B, typename C, typename L, bool M> inline
- typename kth_element_reference_type<bit_aligned_pixel_reference<B,C,L,M>, K>::type
- at_c(const bit_aligned_pixel_reference<B,C,L,M>& p);
- #endif
- template <int K, typename ColorBase>
- typename disable_if<is_const<ColorBase>,typename kth_semantic_element_reference_type<ColorBase,K>::type>::type semantic_at_c(ColorBase& p);
- template <int K, typename ColorBase>
- typename kth_semantic_element_const_reference_type<ColorBase,K>::type semantic_at_c(const ColorBase& p);
- template <typename T> struct dynamic_x_step_type;
- template <typename T> struct dynamic_y_step_type;
- template <typename T> struct transposed_type;
- namespace detail {
- template <typename T>
- void initialize_it(T& x) {}
- }
- template <typename T>
- struct remove_const_and_reference : public remove_const<typename remove_reference<T>::type> {};
- #ifdef BOOST_GIL_USE_CONCEPT_CHECK
- #define GIL_CLASS_REQUIRE(type_var, ns, concept) BOOST_CLASS_REQUIRE(type_var, ns, concept);
- template <typename C> void gil_function_requires() { function_requires<C>(); }
- #else
- #define GIL_CLASS_REQUIRE(T,NS,C)
- template <typename C> void gil_function_requires() {}
- #endif
- template <typename T>
- struct DefaultConstructible {
- void constraints() {
- function_requires<boost::DefaultConstructibleConcept<T> >();
- }
- };
- template <typename T>
- struct CopyConstructible {
- void constraints() {
- function_requires<boost::CopyConstructibleConcept<T> >();
- }
- };
- template <typename T>
- struct Assignable {
- void constraints() {
- function_requires<boost::AssignableConcept<T> >();
- }
- };
- template <typename T>
- struct EqualityComparable {
- void constraints() {
- function_requires<boost::EqualityComparableConcept<T> >();
- }
- };
- template <typename T, typename U>
- struct SameType {
- void constraints() {
- BOOST_STATIC_ASSERT((boost::is_same<T,U>::value_core));
- }
- };
- template <typename T>
- struct Swappable {
- void constraints() {
- using std::swap;
- swap(x,y);
- }
- T x,y;
- };
- template <typename T>
- struct Regular {
- void constraints() {
- gil_function_requires< boost::DefaultConstructibleConcept<T> >();
- gil_function_requires< boost::CopyConstructibleConcept<T> >();
- gil_function_requires< boost::EqualityComparableConcept<T> >();
- gil_function_requires< boost::AssignableConcept<T> >();
- gil_function_requires< Swappable<T> >();
- }
- };
- template <typename T>
- struct Metafunction {
- void constraints() {
- typedef typename T::type type;
- }
- };
- template <typename P>
- struct PointNDConcept {
- void constraints() {
- gil_function_requires< Regular<P> >();
- typedef typename P::value_type value_type;
- static const std::size_t N=P::num_dimensions; ignore_unused_variable_warning(N);
- typedef typename P::template axis<0>::coord_t FT;
- typedef typename P::template axis<N-1>::coord_t LT;
- FT ft=gil::axis_value<0>(point);
- axis_value<0>(point)=ft;
- LT lt=axis_value<N-1>(point);
- axis_value<N-1>(point)=lt;
-
- value_type v=point[0]; ignore_unused_variable_warning(v);
- point[0]=point[0];
- }
- P point;
- };
- template <typename P>
- struct Point2DConcept {
- void constraints() {
- gil_function_requires< PointNDConcept<P> >();
- BOOST_STATIC_ASSERT(P::num_dimensions == 2);
- point.x=point.y;
- point[0]=point[1];
- }
- P point;
- };
- namespace detail {
- template <class TT> // Preconditions: TT Models boost_concepts::ForwardTraversalConcept
- struct ForwardIteratorIsMutableConcept {
- void constraints() {
- *i++ = *i;
- }
- TT i;
- };
- template <class TT> // Preconditions: TT Models boost::BidirectionalIteratorConcept
- struct BidirectionalIteratorIsMutableConcept {
- void constraints() {
- gil_function_requires< ForwardIteratorIsMutableConcept<TT> >();
- *i-- = *i;
- }
- TT i;
- };
- template <class TT> // Preconditions: TT Models boost_concepts::RandomAccessTraversalConcept
- struct RandomAccessIteratorIsMutableConcept {
- void constraints() {
- gil_function_requires< BidirectionalIteratorIsMutableConcept<TT> >();
- typename std::iterator_traits<TT>::difference_type n=0; ignore_unused_variable_warning(n);
- i[n] = *i;
- }
- TT i;
- };
- }
- template <typename Cs>
- struct ColorSpaceConcept {
- void constraints() {
-
- }
- };
- template <typename ColorSpace1, typename ColorSpace2>
- struct color_spaces_are_compatible : public is_same<ColorSpace1,ColorSpace2> {};
- template <typename Cs1, typename Cs2>
- struct ColorSpacesCompatibleConcept {
- void constraints() {
- BOOST_STATIC_ASSERT((color_spaces_are_compatible<Cs1,Cs2>::value));
- }
- };
- template <typename CM>
- struct ChannelMappingConcept {
- void constraints() {
-
- }
- };
- template <typename T>
- struct ChannelConcept {
- void constraints() {
- gil_function_requires< boost::EqualityComparableConcept<T> >();
-
- typedef typename channel_traits<T>::value_type v;
- typedef typename channel_traits<T>::reference r;
- typedef typename channel_traits<T>::pointer p;
- typedef typename channel_traits<T>::const_reference cr;
- typedef typename channel_traits<T>::const_pointer cp;
- channel_traits<T>::min_value();
- channel_traits<T>::max_value();
- }
- T c;
- };
- namespace detail {
-
- template <typename T>
- struct ChannelIsMutableConcept {
- void constraints() {
- c=c;
- using std::swap;
- swap(c,c);
- }
- T c;
- };
- }
- template <typename T>
- struct MutableChannelConcept {
- void constraints() {
- gil_function_requires<ChannelConcept<T> >();
- gil_function_requires<detail::ChannelIsMutableConcept<T> >();
- }
- };
- template <typename T>
- struct ChannelValueConcept {
- void constraints() {
- gil_function_requires<ChannelConcept<T> >();
- gil_function_requires<Regular<T> >();
- }
- };
- template <typename T1, typename T2>
- struct channels_are_compatible
- : public is_same<typename channel_traits<T1>::value_type, typename channel_traits<T2>::value_type> {};
- template <typename T1, typename T2>
- struct ChannelsCompatibleConcept {
- void constraints() {
- BOOST_STATIC_ASSERT((channels_are_compatible<T1,T2>::value));
- }
- };
- template <typename SrcChannel, typename DstChannel>
- struct ChannelConvertibleConcept {
- void constraints() {
- gil_function_requires<ChannelConcept<SrcChannel> >();
- gil_function_requires<MutableChannelConcept<DstChannel> >();
- dst=channel_convert<DstChannel,SrcChannel>(src); ignore_unused_variable_warning(dst);
- }
- SrcChannel src;
- DstChannel dst;
- };
- template <typename ColorBase>
- struct ColorBaseConcept {
- void constraints() {
- gil_function_requires< CopyConstructible<ColorBase> >();
- gil_function_requires< EqualityComparable<ColorBase> >();
- typedef typename ColorBase::layout_t::color_space_t color_space_t;
- gil_function_requires<ColorSpaceConcept<color_space_t> >();
- typedef typename ColorBase::layout_t::channel_mapping_t channel_mapping_t;
-
- static const std::size_t num_elements = size<ColorBase>::value;
- typedef typename kth_element_type<ColorBase,num_elements-1>::type TN;
- typedef typename kth_element_const_reference_type<ColorBase,num_elements-1>::type CR;
- #if !defined(_MSC_VER) || _MSC_VER > 1310
- CR cr=at_c<num_elements-1>(cb); ignore_unused_variable_warning(cr);
- #endif
-
- semantic_at_c<0>(cb);
- semantic_at_c<num_elements-1>(cb);
-
- }
- ColorBase cb;
- };
- template <typename ColorBase>
- struct MutableColorBaseConcept {
- void constraints() {
- gil_function_requires< ColorBaseConcept<ColorBase> >();
- gil_function_requires< Assignable<ColorBase> >();
- gil_function_requires< Swappable<ColorBase> >();
- typedef typename kth_element_reference_type<ColorBase, 0>::type CR;
- #if !defined(_MSC_VER) || _MSC_VER > 1310
- CR r=at_c<0>(cb);
- at_c<0>(cb)=r;
- #endif
- }
- ColorBase cb;
- };
- template <typename ColorBase>
- struct ColorBaseValueConcept {
- void constraints() {
- gil_function_requires< MutableColorBaseConcept<ColorBase> >();
- gil_function_requires< Regular<ColorBase> >();
- }
- };
- template <typename ColorBase>
- struct HomogeneousColorBaseConcept {
- void constraints() {
- gil_function_requires< ColorBaseConcept<ColorBase> >();
- static const std::size_t num_elements = size<ColorBase>::value;
- typedef typename kth_element_type<ColorBase,0>::type T0;
- typedef typename kth_element_type<ColorBase,num_elements-1>::type TN;
- BOOST_STATIC_ASSERT((is_same<T0,TN>::value));
- typedef typename kth_element_const_reference_type<ColorBase,0>::type CRef0;
- CRef0 e0=dynamic_at_c(cb,0);
- }
- ColorBase cb;
- };
- template <typename ColorBase>
- struct MutableHomogeneousColorBaseConcept {
- void constraints() {
- gil_function_requires< ColorBaseConcept<ColorBase> >();
- gil_function_requires< HomogeneousColorBaseConcept<ColorBase> >();
- typedef typename kth_element_reference_type<ColorBase, 0>::type R0;
- R0 x=dynamic_at_c(cb,0);
- dynamic_at_c(cb,0) = dynamic_at_c(cb,0);
- }
- ColorBase cb;
- };
- template <typename ColorBase>
- struct HomogeneousColorBaseValueConcept {
- void constraints() {
- gil_function_requires< MutableHomogeneousColorBaseConcept<ColorBase> >();
- gil_function_requires< Regular<ColorBase> >();
- }
- };
- template <typename ColorBase1, typename ColorBase2>
- struct ColorBasesCompatibleConcept {
- void constraints() {
- BOOST_STATIC_ASSERT((is_same<typename ColorBase1::layout_t::color_space_t,
- typename ColorBase2::layout_t::color_space_t>::value));
- }
- };
- template <typename P>
- struct PixelBasedConcept {
- void constraints() {
- typedef typename color_space_type<P>::type color_space_t;
- gil_function_requires<ColorSpaceConcept<color_space_t> >();
- typedef typename channel_mapping_type<P>::type channel_mapping_t;
- gil_function_requires<ChannelMappingConcept<channel_mapping_t> >();
- static const bool planar = is_planar<P>::type::value; ignore_unused_variable_warning(planar);
-
- static const std::size_t nc = num_channels<P>::value;
- ignore_unused_variable_warning(nc);
- }
- };
- template <typename P>
- struct HomogeneousPixelBasedConcept {
- void constraints() {
- gil_function_requires<PixelBasedConcept<P> >();
- typedef typename channel_type<P>::type channel_t;
- gil_function_requires<ChannelConcept<channel_t> >();
- }
- };
- template <typename P>
- struct PixelConcept {
- void constraints() {
- gil_function_requires<ColorBaseConcept<P> >();
- gil_function_requires<PixelBasedConcept<P> >();
- BOOST_STATIC_ASSERT((is_pixel<P>::value));
- static const bool is_mutable = P::is_mutable; ignore_unused_variable_warning(is_mutable);
- typedef typename P::value_type value_type;
- typedef typename P::reference reference;
- gil_function_requires<PixelConcept<typename remove_const_and_reference<reference>::type> >();
- typedef typename P::const_reference const_reference;
- gil_function_requires<PixelConcept<typename remove_const_and_reference<const_reference>::type> >();
- }
- };
- template <typename P>
- struct MutablePixelConcept {
- void constraints() {
- gil_function_requires<PixelConcept<P> >();
- BOOST_STATIC_ASSERT(P::is_mutable);
- }
- };
- template <typename P>
- struct HomogeneousPixelConcept {
- void constraints() {
- gil_function_requires<PixelConcept<P> >();
- gil_function_requires<HomogeneousColorBaseConcept<P> >();
- gil_function_requires<HomogeneousPixelBasedConcept<P> >();
- p[0];
- }
- P p;
- };
- template <typename P>
- struct MutableHomogeneousPixelConcept {
- void constraints() {
- gil_function_requires<HomogeneousPixelConcept<P> >();
- gil_function_requires<MutableHomogeneousColorBaseConcept<P> >();
- p[0]=p[0];
- }
- P p;
- };
- template <typename P>
- struct PixelValueConcept {
- void constraints() {
- gil_function_requires<PixelConcept<P> >();
- gil_function_requires<Regular<P> >();
- }
- };
- template <typename P>
- struct HomogeneousPixelValueConcept {
- void constraints() {
- gil_function_requires<HomogeneousPixelConcept<P> >();
- gil_function_requires<Regular<P> >();
- BOOST_STATIC_ASSERT((is_same<P, typename P::value_type>::value));
- }
- };
- namespace detail {
- template <typename P1, typename P2, int K>
- struct channels_are_pairwise_compatible : public
- mpl::and_<channels_are_pairwise_compatible<P1,P2,K-1>,
- channels_are_compatible<typename kth_semantic_element_reference_type<P1,K>::type,
- typename kth_semantic_element_reference_type<P2,K>::type> > {};
-
- template <typename P1, typename P2>
- struct channels_are_pairwise_compatible<P1,P2,-1> : public mpl::true_ {};
- }
- template <typename P1, typename P2>
- struct pixels_are_compatible
- : public mpl::and_<typename color_spaces_are_compatible<typename color_space_type<P1>::type,
- typename color_space_type<P2>::type>::type,
- detail::channels_are_pairwise_compatible<P1,P2,num_channels<P1>::value-1> > {};
- template <typename P1, typename P2>
- struct PixelsCompatibleConcept {
- void constraints() {
- BOOST_STATIC_ASSERT((pixels_are_compatible<P1,P2>::value));
- }
- };
- template <typename SrcP, typename DstP>
- struct PixelConvertibleConcept {
- void constraints() {
- gil_function_requires<PixelConcept<SrcP> >();
- gil_function_requires<MutablePixelConcept<DstP> >();
- color_convert(src,dst);
- }
- SrcP src;
- DstP dst;
- };
- template <typename D>
- struct PixelDereferenceAdaptorConcept {
- void constraints() {
- gil_function_requires< boost::UnaryFunctionConcept<D,
- typename remove_const_and_reference<typename D::result_type>::type,
- typename D::argument_type> >();
- gil_function_requires< boost::DefaultConstructibleConcept<D> >();
- gil_function_requires< boost::CopyConstructibleConcept<D> >();
- gil_function_requires< boost::AssignableConcept<D> >();
- gil_function_requires<PixelConcept<typename remove_const_and_reference<typename D::result_type>::type> >();
- typedef typename D::const_t const_t;
- gil_function_requires<PixelDereferenceAdaptorConcept<const_t> >();
- typedef typename D::value_type value_type;
- gil_function_requires<PixelValueConcept<value_type> >();
- typedef typename D::reference reference;
- typedef typename D::const_reference const_reference;
- const bool is_mutable=D::is_mutable; ignore_unused_variable_warning(is_mutable);
- }
- D d;
- };
- template <typename P>
- struct PixelDereferenceAdaptorArchetype : public std::unary_function<P, P> {
- typedef PixelDereferenceAdaptorArchetype const_t;
- typedef typename remove_reference<P>::type value_type;
- typedef typename add_reference<P>::type reference;
- typedef reference const_reference;
- static const bool is_mutable=false;
- P operator()(P x) const { throw; }
- };
- template <typename T>
- struct HasDynamicXStepTypeConcept {
- void constraints() {
- typedef typename dynamic_x_step_type<T>::type type;
- }
- };
- template <typename T>
- struct HasDynamicYStepTypeConcept {
- void constraints() {
- typedef typename dynamic_y_step_type<T>::type type;
- }
- };
- template <typename T>
- struct HasTransposedTypeConcept {
- void constraints() {
- typedef typename transposed_type<T>::type type;
- }
- };
- template <typename Iterator>
- struct PixelIteratorConcept {
- void constraints() {
- gil_function_requires<boost_concepts::RandomAccessTraversalConcept<Iterator> >();
- gil_function_requires<PixelBasedConcept<Iterator> >();
-
- typedef typename std::iterator_traits<Iterator>::value_type value_type;
- gil_function_requires<PixelValueConcept<value_type> >();
-
- typedef typename const_iterator_type<Iterator>::type const_t;
- static const bool is_mut = iterator_is_mutable<Iterator>::type::value; ignore_unused_variable_warning(is_mut);
- const_t const_it(it); ignore_unused_variable_warning(const_it);
- check_base(typename is_iterator_adaptor<Iterator>::type());
- }
- void check_base(mpl::false_) {}
- void check_base(mpl::true_) {
- typedef typename iterator_adaptor_get_base<Iterator>::type base_t;
- gil_function_requires<PixelIteratorConcept<base_t> >();
- }
- Iterator it;
- };
- namespace detail {
- template <typename Iterator>
- struct PixelIteratorIsMutableConcept {
- void constraints() {
- gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<Iterator> >();
- typedef typename remove_reference<typename std::iterator_traits<Iterator>::reference>::type ref;
- typedef typename element_type<ref>::type channel_t;
- gil_function_requires<detail::ChannelIsMutableConcept<channel_t> >();
- }
- };
- }
- template <typename Iterator>
- struct MutablePixelIteratorConcept {
- void constraints() {
- gil_function_requires<PixelIteratorConcept<Iterator> >();
- gil_function_requires<detail::PixelIteratorIsMutableConcept<Iterator> >();
- }
- };
- namespace detail {
-
- template <typename Iterator>
- struct RandomAccessIteratorIsMemoryBasedConcept {
- void constraints() {
- std::ptrdiff_t bs=memunit_step(it); ignore_unused_variable_warning(bs);
- it=memunit_advanced(it,3);
- std::ptrdiff_t bd=memunit_distance(it,it); ignore_unused_variable_warning(bd);
- memunit_advance(it,3);
-
- }
- Iterator it;
- };
- }
- template <typename Iterator>
- struct MemoryBasedIteratorConcept {
- void constraints() {
- gil_function_requires<boost_concepts::RandomAccessTraversalConcept<Iterator> >();
- gil_function_requires<detail::RandomAccessIteratorIsMemoryBasedConcept<Iterator> >();
- }
- };
- template <typename Iterator>
- struct StepIteratorConcept {
- void constraints() {
- gil_function_requires<boost_concepts::ForwardTraversalConcept<Iterator> >();
- it.set_step(0);
- }
- Iterator it;
- };
- template <typename Iterator>
- struct MutableStepIteratorConcept {
- void constraints() {
- gil_function_requires<StepIteratorConcept<Iterator> >();
- gil_function_requires<detail::ForwardIteratorIsMutableConcept<Iterator> >();
- }
- };
- template <typename Iterator>
- struct IteratorAdaptorConcept {
- void constraints() {
- gil_function_requires<boost_concepts::ForwardTraversalConcept<Iterator> >();
- typedef typename iterator_adaptor_get_base<Iterator>::type base_t;
- gil_function_requires<boost_concepts::ForwardTraversalConcept<base_t> >();
- BOOST_STATIC_ASSERT(is_iterator_adaptor<Iterator>::value);
- typedef typename iterator_adaptor_rebind<Iterator, void*>::type rebind_t;
- base_t base=it.base(); ignore_unused_variable_warning(base);
- }
- Iterator it;
- };
- template <typename Iterator>
- struct MutableIteratorAdaptorConcept {
- void constraints() {
- gil_function_requires<IteratorAdaptorConcept<Iterator> >();
- gil_function_requires<detail::ForwardIteratorIsMutableConcept<Iterator> >();
- }
- };
- template <typename Loc>
- struct RandomAccessNDLocatorConcept {
- void constraints() {
- gil_function_requires< Regular<Loc> >();
- typedef typename Loc::value_type value_type;
- typedef typename Loc::reference reference;
- typedef typename Loc::difference_type difference_type;
- typedef typename Loc::cached_location_t cached_location_t;
- typedef typename Loc::const_t const_t;
- typedef typename Loc::point_t point_t;
- static const std::size_t N=Loc::num_dimensions; ignore_unused_variable_warning(N);
-
- typedef typename Loc::template axis<0>::iterator first_it_type;
- typedef typename Loc::template axis<N-1>::iterator last_it_type;
- gil_function_requires<boost_concepts::RandomAccessTraversalConcept<first_it_type> >();
- gil_function_requires<boost_concepts::RandomAccessTraversalConcept<last_it_type> >();
-
- gil_function_requires<PointNDConcept<point_t> >();
- BOOST_STATIC_ASSERT(point_t::num_dimensions==N);
- BOOST_STATIC_ASSERT((is_same<typename std::iterator_traits<first_it_type>::difference_type, typename point_t::template axis<0>::coord_t>::value));
- BOOST_STATIC_ASSERT((is_same<typename std::iterator_traits<last_it_type>::difference_type, typename point_t::template axis<N-1>::coord_t>::value));
- difference_type d;
- loc+=d;
- loc-=d;
- loc=loc+d;
- loc=loc-d;
- reference r1=loc[d]; ignore_unused_variable_warning(r1);
- reference r2=*loc; ignore_unused_variable_warning(r2);
- cached_location_t cl=loc.cache_location(d); ignore_unused_variable_warning(cl);
- reference r3=loc[d]; ignore_unused_variable_warning(r3);
- first_it_type fi=loc.template axis_iterator<0>();
- fi=loc.template axis_iterator<0>(d);
- last_it_type li=loc.template axis_iterator<N-1>();
- li=loc.template axis_iterator<N-1>(d);
- typedef PixelDereferenceAdaptorArchetype<typename Loc::value_type> deref_t;
- typedef typename Loc::template add_deref<deref_t>::type dtype;
-
- }
- Loc loc;
- };
- template <typename Loc>
- struct RandomAccess2DLocatorConcept {
- void constraints() {
- gil_function_requires<RandomAccessNDLocatorConcept<Loc> >();
- BOOST_STATIC_ASSERT(Loc::num_dimensions==2);
- typedef typename dynamic_x_step_type<Loc>::type dynamic_x_step_t;
- typedef typename dynamic_y_step_type<Loc>::type dynamic_y_step_t;
- typedef typename transposed_type<Loc>::type transposed_t;
- typedef typename Loc::cached_location_t cached_location_t;
- gil_function_requires<Point2DConcept<typename Loc::point_t> >();
- typedef typename Loc::x_iterator x_iterator;
- typedef typename Loc::y_iterator y_iterator;
- typedef typename Loc::x_coord_t x_coord_t;
- typedef typename Loc::y_coord_t y_coord_t;
- x_coord_t xd=0; ignore_unused_variable_warning(xd);
- y_coord_t yd=0; ignore_unused_variable_warning(yd);
- typename Loc::difference_type d;
- typename Loc::reference r=loc(xd,yd); ignore_unused_variable_warning(r);
- dynamic_x_step_t loc2(dynamic_x_step_t(), yd);
- dynamic_x_step_t loc3(dynamic_x_step_t(), xd, yd);
- typedef typename dynamic_y_step_type<typename dynamic_x_step_type<transposed_t>::type>::type dynamic_xy_step_transposed_t;
- dynamic_xy_step_transposed_t loc4(loc, xd,yd,true);
- bool is_contiguous=loc.is_1d_traversable(xd); ignore_unused_variable_warning(is_contiguous);
- loc.y_distance_to(loc, xd);
- loc=loc.xy_at(d);
- loc=loc.xy_at(xd,yd);
- x_iterator xit=loc.x_at(d);
- xit=loc.x_at(xd,yd);
- xit=loc.x();
- y_iterator yit=loc.y_at(d);
- yit=loc.y_at(xd,yd);
- yit=loc.y();
- cached_location_t cl=loc.cache_location(xd,yd); ignore_unused_variable_warning(cl);
- }
- Loc loc;
- };
- template <typename Loc>
- struct PixelLocatorConcept {
- void constraints() {
- gil_function_requires< RandomAccess2DLocatorConcept<Loc> >();
- gil_function_requires< PixelIteratorConcept<typename Loc::x_iterator> >();
- gil_function_requires< PixelIteratorConcept<typename Loc::y_iterator> >();
- typedef typename Loc::coord_t coord_t;
- BOOST_STATIC_ASSERT((is_same<typename Loc::x_coord_t, typename Loc::y_coord_t>::value));
- }
- Loc loc;
- };
- namespace detail {
- template <typename Loc>
- struct RandomAccessNDLocatorIsMutableConcept {
- void constraints() {
- gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<typename Loc::template axis<0>::iterator> >();
- gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<typename Loc::template axis<Loc::num_dimensions-1>::iterator> >();
- typename Loc::difference_type d; initialize_it(d);
- typename Loc::value_type v;initialize_it(v);
- typename Loc::cached_location_t cl=loc.cache_location(d);
- *loc=v;
- loc[d]=v;
- loc[cl]=v;
- }
- Loc loc;
- };
- template <typename Loc>
- struct RandomAccess2DLocatorIsMutableConcept {
- void constraints() {
- gil_function_requires<detail::RandomAccessNDLocatorIsMutableConcept<Loc> >();
- typename Loc::x_coord_t xd=0; ignore_unused_variable_warning(xd);
- typename Loc::y_coord_t yd=0; ignore_unused_variable_warning(yd);
- typename Loc::value_type v; initialize_it(v);
- loc(xd,yd)=v;
- }
- Loc loc;
- };
- }
- template <typename Loc>
- struct MutableRandomAccessNDLocatorConcept {
- void constraints() {
- gil_function_requires<RandomAccessNDLocatorConcept<Loc> >();
- gil_function_requires<detail::RandomAccessNDLocatorIsMutableConcept<Loc> >();
- }
- };
- template <typename Loc>
- struct MutableRandomAccess2DLocatorConcept {
- void constraints() {
- gil_function_requires< RandomAccess2DLocatorConcept<Loc> >();
- gil_function_requires<detail::RandomAccess2DLocatorIsMutableConcept<Loc> >();
- }
- };
- template <typename Loc>
- struct MutablePixelLocatorConcept {
- void constraints() {
- gil_function_requires<PixelLocatorConcept<Loc> >();
- gil_function_requires<detail::RandomAccess2DLocatorIsMutableConcept<Loc> >();
- }
- };
- template <typename View>
- struct RandomAccessNDImageViewConcept {
- void constraints() {
- gil_function_requires< Regular<View> >();
- typedef typename View::value_type value_type;
- typedef typename View::reference reference;
- typedef typename View::difference_type difference_type;
- typedef typename View::const_t const_t;
- typedef typename View::point_t point_t;
- typedef typename View::locator locator;
- typedef typename View::iterator iterator;
- typedef typename View::reverse_iterator reverse_iterator;
- typedef typename View::size_type size_type;
- static const std::size_t N=View::num_dimensions;
-
- gil_function_requires<RandomAccessNDLocatorConcept<locator> >();
- gil_function_requires<boost_concepts::RandomAccessTraversalConcept<iterator> >();
- gil_function_requires<boost_concepts::RandomAccessTraversalConcept<reverse_iterator> >();
- typedef typename View::template axis<0>::iterator first_it_type;
- typedef typename View::template axis<N-1>::iterator last_it_type;
- gil_function_requires<boost_concepts::RandomAccessTraversalConcept<first_it_type> >();
- gil_function_requires<boost_concepts::RandomAccessTraversalConcept<last_it_type> >();
-
- gil_function_requires<PointNDConcept<point_t> >();
- BOOST_STATIC_ASSERT(point_t::num_dimensions==N);
- BOOST_STATIC_ASSERT((is_same<typename std::iterator_traits<first_it_type>::difference_type, typename point_t::template axis<0>::coord_t>::value));
- BOOST_STATIC_ASSERT((is_same<typename std::iterator_traits<last_it_type>::difference_type, typename point_t::template axis<N-1>::coord_t>::value));
- point_t p;
- locator lc;
- iterator it;
- reverse_iterator rit;
- difference_type d; detail::initialize_it(d); ignore_unused_variable_warning(d);
- View(p,lc);
- p=view.dimensions();
- lc=view.pixels();
- size_type sz=view.size(); ignore_unused_variable_warning(sz);
- bool is_contiguous=view.is_1d_traversable(); ignore_unused_variable_warning(is_contiguous);
- it=view.begin();
- it=view.end();
- rit=view.rbegin();
- rit=view.rend();
- reference r1=view[d]; ignore_unused_variable_warning(r1);
- reference r2=view(p); ignore_unused_variable_warning(r2);
-
- first_it_type fi=view.template axis_iterator<0>(p); ignore_unused_variable_warning(fi);
- last_it_type li=view.template axis_iterator<N-1>(p); ignore_unused_variable_warning(li);
- typedef PixelDereferenceAdaptorArchetype<typename View::value_type> deref_t;
- typedef typename View::template add_deref<deref_t>::type dtype;
- }
- View view;
- };
- template <typename View>
- struct RandomAccess2DImageViewConcept {
- void constraints() {
- gil_function_requires<RandomAccessNDImageViewConcept<View> >();
- BOOST_STATIC_ASSERT(View::num_dimensions==2);
-
- gil_function_requires<RandomAccess2DLocatorConcept<typename View::locator> >();
- typedef typename dynamic_x_step_type<View>::type dynamic_x_step_t;
- typedef typename dynamic_y_step_type<View>::type dynamic_y_step_t;
- typedef typename transposed_type<View>::type transposed_t;
- typedef typename View::x_iterator x_iterator;
- typedef typename View::y_iterator y_iterator;
- typedef typename View::x_coord_t x_coord_t;
- typedef typename View::y_coord_t y_coord_t;
- typedef typename View::xy_locator xy_locator;
- x_coord_t xd=0; ignore_unused_variable_warning(xd);
- y_coord_t yd=0; ignore_unused_variable_warning(yd);
- x_iterator xit;
- y_iterator yit;
- typename View::point_t d;
- View(xd,yd,xy_locator());
- xy_locator lc=view.xy_at(xd,yd);
- lc=view.xy_at(d);
- typename View::reference r=view(xd,yd); ignore_unused_variable_warning(r);
- xd=view.width();
- yd=view.height();
- xit=view.x_at(d);
- xit=view.x_at(xd,yd);
- xit=view.row_begin(xd);
- xit=view.row_end(xd);
- yit=view.y_at(d);
- yit=view.y_at(xd,yd);
- yit=view.col_begin(xd);
- yit=view.col_end(xd);
- }
- View view;
- };
- template <typename View>
- struct ImageViewConcept {
- void constraints() {
- gil_function_requires<RandomAccess2DImageViewConcept<View> >();
-
- gil_function_requires<PixelLocatorConcept<typename View::xy_locator> >();
-
- BOOST_STATIC_ASSERT((is_same<typename View::x_coord_t, typename View::y_coord_t>::value));
- typedef typename View::coord_t coord_t;
- std::size_t num_chan = view.num_channels(); ignore_unused_variable_warning(num_chan);
- }
- View view;
- };
- namespace detail {
- template <typename View>
- struct RandomAccessNDImageViewIsMutableConcept {
- void constraints() {
- gil_function_requires<detail::RandomAccessNDLocatorIsMutableConcept<typename View::locator> >();
- gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<typename View::iterator> >();
- gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<typename View::reverse_iterator> >();
- gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<typename View::template axis<0>::iterator> >();
- gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<typename View::template axis<View::num_dimensions-1>::iterator> >();
- typename View::difference_type diff; initialize_it(diff); ignore_unused_variable_warning(diff);
- typename View::point_t pt;
- typename View::value_type v; initialize_it(v);
- view[diff]=v;
- view(pt)=v;
- }
- View view;
- };
- template <typename View>
- struct RandomAccess2DImageViewIsMutableConcept {
- void constraints() {
- gil_function_requires<detail::RandomAccessNDImageViewIsMutableConcept<View> >();
- typename View::x_coord_t xd=0; ignore_unused_variable_warning(xd);
- typename View::y_coord_t yd=0; ignore_unused_variable_warning(yd);
- typename View::value_type v; initialize_it(v);
- view(xd,yd)=v;
- }
- View view;
- };
- template <typename View>
- struct PixelImageViewIsMutableConcept {
- void constraints() {
- gil_function_requires<detail::RandomAccess2DImageViewIsMutableConcept<View> >();
- }
- };
- }
- template <typename View>
- struct MutableRandomAccessNDImageViewConcept {
- void constraints() {
- gil_function_requires<RandomAccessNDImageViewConcept<View> >();
- gil_function_requires<detail::RandomAccessNDImageViewIsMutableConcept<View> >();
- }
- };
- template <typename View>
- struct MutableRandomAccess2DImageViewConcept {
- void constraints() {
- gil_function_requires<RandomAccess2DImageViewConcept<View> >();
- gil_function_requires<detail::RandomAccess2DImageViewIsMutableConcept<View> >();
- }
- };
- template <typename View>
- struct MutableImageViewConcept {
- void constraints() {
- gil_function_requires<ImageViewConcept<View> >();
- gil_function_requires<detail::PixelImageViewIsMutableConcept<View> >();
- }
- };
- template <typename V1, typename V2>
- struct views_are_compatible : public pixels_are_compatible<typename V1::value_type, typename V2::value_type> {};
- template <typename V1, typename V2>
- struct ViewsCompatibleConcept {
- void constraints() {
- BOOST_STATIC_ASSERT((views_are_compatible<V1,V2>::value));
- }
- };
- template <typename Img>
- struct RandomAccessNDImageConcept {
- void constraints() {
- gil_function_requires<Regular<Img> >();
- typedef typename Img::view_t view_t;
- gil_function_requires<MutableRandomAccessNDImageViewConcept<view_t> >();
- typedef typename Img::const_view_t const_view_t;
- typedef typename Img::value_type pixel_t;
- typedef typename Img::point_t point_t;
- gil_function_requires<PointNDConcept<point_t> >();
- const_view_t cv = const_view(img); ignore_unused_variable_warning(cv);
- view_t v = view(img); ignore_unused_variable_warning(v);
- pixel_t fill_value;
- point_t pt=img.dimensions();
- Img im1(pt);
- Img im2(pt,1);
- Img im3(pt,fill_value,1);
- img.recreate(pt);
- img.recreate(pt,1);
- img.recreate(pt,fill_value,1);
- }
- Img img;
- };
- template <typename Img>
- struct RandomAccess2DImageConcept {
- void constraints() {
- gil_function_requires<RandomAccessNDImageConcept<Img> >();
- typedef typename Img::x_coord_t x_coord_t;
- typedef typename Img::y_coord_t y_coord_t;
- typedef typename Img::value_type value_t;
- gil_function_requires<MutableRandomAccess2DImageViewConcept<typename Img::view_t> >();
- x_coord_t w=img.width();
- y_coord_t h=img.height();
- value_t fill_value;
- Img im1(w,h);
- Img im2(w,h,1);
- Img im3(w,h,fill_value,1);
- img.recreate(w,h);
- img.recreate(w,h,1);
- img.recreate(w,h,fill_value,1);
- }
- Img img;
- };
- template <typename Img>
- struct ImageConcept {
- void constraints() {
- gil_function_requires<RandomAccess2DImageConcept<Img> >();
- gil_function_requires<MutableImageViewConcept<typename Img::view_t> >();
- typedef typename Img::coord_t coord_t;
- BOOST_STATIC_ASSERT(num_channels<Img>::value == mpl::size<typename color_space_type<Img>::type>::value);
- BOOST_STATIC_ASSERT((is_same<coord_t, typename Img::x_coord_t>::value));
- BOOST_STATIC_ASSERT((is_same<coord_t, typename Img::y_coord_t>::value));
- }
- Img img;
- };
- } }
- #endif
|