aimstil  5.0.5
point_operators.h
Go to the documentation of this file.
1 #ifndef TIL_POINT_OPERATORS_H_
2 #define TIL_POINT_OPERATORS_H_
3 
4 namespace til
5 {
6  namespace functor
7  {
9  template < typename X, typename T, std::size_t D, typename TStorage >
10  struct CastTo<Point<T,D,TStorage>,X> : std::binary_function<Point<T,D,TStorage> &, const X &, void>
11  {
12  typedef std::binary_function<Point<T,D,TStorage> &, const X &, void> Base;
13  typedef typename Base::first_argument_type first_argument_type;
14  typedef typename Base::second_argument_type second_argument_type;
15  void operator()(first_argument_type p, second_argument_type x)
16  {
17  CastTo<TStorage,X>()(p.data(),x);
18  }
19  };
20  }
21 
22 
23 #define TIL_BOUNCE_BOOL_OP_TO_DATA(op) \
24  template < typename T1, typename T2, std::size_t D, typename TStorage1, typename TStorage2 > \
25  inline bool operator op (const Point<T1,D,TStorage1> & x, const Point<T2,D,TStorage2> & y) \
26  { return x.data() op y.data(); } \
27 
30 
31 #undef TIL_BOUNCE_BOOL_OP_TO_DATA
32 
33 #define TIL_BOUNCE_VEC_OP_TO_DATA(op, arg1, arg2, res, functor) \
34  template < typename T, std::size_t D, typename TStorage > \
35  inline res <T,D,TStorage> operator op (const arg1 <T,D,TStorage> & x, const arg2 <T,D,TStorage> & y) \
36  { return functor<TStorage,TStorage,res <T,D,TStorage> >()(x.data(), y.data()); }
37 
38  TIL_BOUNCE_VEC_OP_TO_DATA(+, Point, Vector, Point, functor::Add);
39  TIL_BOUNCE_VEC_OP_TO_DATA(+, Vector, Point, Point, functor::Add);
40  TIL_BOUNCE_VEC_OP_TO_DATA(-, Point, Vector, Point, functor::Sub);
41  TIL_BOUNCE_VEC_OP_TO_DATA(-, Point, Point, Vector, functor::Sub);
42 
43 #undef TIL_BOUNCE_VEC_OP_TO_DATA
44 
45 
46 #define TIL_BOUNCE_SCALAR_OP_TO_DATA(op, functor) \
47  template < typename T, std::size_t D, typename TStorage > \
48  inline Point<T,D,TStorage> operator op (const Point<T,D,TStorage> & x, T y) \
49  { return functor <TStorage,T,Point<T,D,TStorage> >()(x.data(), y); } \
50  template < typename T, std::size_t D, typename TStorage > \
51  inline Point<T,D,TStorage> operator op (T y, const Point<T,D,TStorage> & x) \
52  { return functor <T,TStorage,Point<T,D,TStorage> >()(y, x.data()); } \
53 
54 
55  TIL_BOUNCE_SCALAR_OP_TO_DATA(+, functor::Add)
56  TIL_BOUNCE_SCALAR_OP_TO_DATA(-, functor::Sub)
57 
58 #undef TIL_BOUNCE_SCALAR_OP_TO_DATA
59 
60 
61  template < typename T, std::size_t D, typename TStorage >
62  std::ostream & operator<<(std::ostream & os, const Point<T,D,TStorage> & p)
63  {
64  return os << p.data();
65  }
66 
67 }
68 
69 #endif /*POINT_OPERATORS_H_*/
std::binary_function< Point< T, D, TStorage > &, const X &, void > Base
void operator()(first_argument_type p, second_argument_type x)
TIL_BOUNCE_VEC_OP_TO_DATA(+, Point, Vector, Point, functor::Add)
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
#define TIL_BOUNCE_BOOL_OP_TO_DATA(op)
#define TIL_BOUNCE_SCALAR_OP_TO_DATA(op, functor)
Static cast functor.
Definition: functors.h:136