Honeycomb  0.1
Component-Model Framework
Swiz.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
5 
6 namespace honey
7 {
8 
10 template<sdt Dim, class Real, int Options> class VecSwizCon;
11 
12 template<sdt Dim, class Real, int Options>
13 struct matrix::priv::Traits<VecSwizCon<Dim,Real,Options>> : Traits<Vec<Dim,Real,Options>> {};
14 
15 template<class SwizT>
16 class VecSwizConBase : public Vec< matrix::priv::Traits<SwizT>::dim, typename matrix::priv::Traits<SwizT>::Real,
17  matrix::priv::Traits<SwizT>::options>
18 {
19 private:
20  SwizT& fromZero();
21  SwizT& fromScalar(Real f);
22  SwizT& operator=(const VecSwizConBase& rhs);
23  template<class T>
24  SwizT& operator+=(const MatrixBase<T>& rhs);
25  template<class T>
26  SwizT& operator-=(const MatrixBase<T>& rhs);
27  SwizT& operator*=(Real rhs);
28  SwizT& operator/=(Real rhs);
29  SwizT& elemAddEq(Real rhs);
30  SwizT& elemSubEq(Real rhs);
31  template<class T>
32  SwizT& elemMulEq(const MatrixBase<T>& rhs);
33  template<class T>
34  SwizT& elemDivEq(const MatrixBase<T>& rhs);
35 };
36 
38 template<class T_, sdt D, class R, int Opt>
39 struct priv::map_impl<T_, VecSwizCon<D,R,Opt>>
40 {
41  template<class T, class O, class Func>
42  static O&& func(T&&, O&&, Func&&) { static_assert(!mt::True<T>::value, "Can't map with const swizzle output"); }
43 };
44 
45 template<class T_, sdt D, class R, int Opt, class T2_>
46 struct priv::map_impl<T_, VecSwizCon<D,R,Opt>, T2_>
47 {
48  template<class T, class T2, class O, class Func>
49  static O&& func(T&&, T2&&, O&&, Func&&) { static_assert(!mt::True<T>::value, "Can't map with const swizzle output"); }
50 };
53 template<sdt Dim, class Real, int Options> class VecSwizRef;
55 
56 template<sdt Dim, class Real, int Options>
57 struct matrix::priv::Traits<VecSwizRef<Dim,Real,Options>> : Traits<Vec<Dim,Real,Options>> {};
58 
59 template<class SwizT>
60 class VecSwizRefBase : public Vec< matrix::priv::Traits<SwizT>::dim, typename matrix::priv::Traits<SwizT>::Real,
61  matrix::priv::Traits<SwizT>::options>
62 {
63 public:
66 
68  SwizT& operator=(Real rhs) { return fromScalar(rhs); }
69  SwizT& operator+=(Real rhs) { return elemAddEq(rhs); }
70  SwizT& operator-=(Real rhs) { return elemSubEq(rhs); }
71 
73  SwizT& fromZero() { Super::fromZero(); return swiz().commit(); }
74  SwizT& fromScalar(Real f) { Super::fromScalar(f); return swiz().commit(); }
75  SwizT& operator=(const VecSwizRefBase& rhs) { Super::operator=(rhs); return swiz().commit(); }
76  template<class T>
77  SwizT& operator=(const MatrixBase<T>& rhs) { Super::operator=(rhs.subc()); return swiz().commit(); }
78  template<class T>
79  SwizT& operator+=(const MatrixBase<T>& rhs) { Super::operator+=(rhs.subc()); return swiz().commit(); }
80  template<class T>
81  SwizT& operator-=(const MatrixBase<T>& rhs) { Super::operator-=(rhs.subc()); return swiz().commit(); }
82  SwizT& operator*=(Real rhs) { Super::operator*=(rhs); return swiz().commit(); }
83  SwizT& operator/=(Real rhs) { Super::operator/=(rhs); return swiz().commit(); }
84  SwizT& elemAddEq(Real rhs) { Super::elemAddEq(rhs); return swiz().commit(); }
85  SwizT& elemSubEq(Real rhs) { Super::elemSubEq(rhs); return swiz().commit(); }
86  template<class T>
87  SwizT& elemMulEq(const MatrixBase<T>& rhs) { Super::elemMulEq(rhs.subc()); return swiz().commit(); }
88  template<class T>
89  SwizT& elemDivEq(const MatrixBase<T>& rhs) { Super::elemDivEq(rhs.subc()); return swiz().commit(); }
90 
92  const SwizT& swiz() const { return static_cast<const SwizT&>(*this); }
93  SwizT& swiz() { return static_cast<SwizT&>(*this); }
94 };
95 
97 template<class T_, sdt D, class R, int Opt>
98 struct priv::map_impl<T_, VecSwizRef<D,R,Opt>>
99 {
100  template<class T, class O, class Func>
101  static O&& func(T&& v, O&& o, Func&& f) { map(forward<T>(v), forward<typename O::Super>(o), forward<Func>(f)); o.swiz().commit(); return forward<O>(o); }
102 };
103 
104 template<class T_, sdt D, class R, int Opt, class T2_>
105 struct priv::map_impl<T_, VecSwizRef<D,R,Opt>, T2_>
106 {
107  template<class T, class T2, class O, class Func>
108  static O&& func(T&& v, T2&& v2, O&& o, Func&& f) { map(forward<T>(v), forward<T2>(v2), forward<typename O::Super>(o), forward<Func>(f)); o.swiz().commit(); return forward<O>(o); }
109 };
112 }
MatrixS & fromScalar(Real f)
Initialize with scalar in every element.
Definition: Base.h:72
SwizT & operator=(const VecSwizRefBase &rhs)
Definition: Swiz.h:75
MatrixS & operator+=(const MatrixBase< T > &rhs)
Definition: Base.h:147
Definition: Swiz.h:16
Vector for const swizzle operators.
Definition: Swiz.h:10
SwizT & swiz()
Definition: Swiz.h:93
SwizT & operator-=(const MatrixBase< T > &rhs)
Definition: Swiz.h:81
SwizT & operator=(const MatrixBase< T > &rhs)
Definition: Swiz.h:77
SwizT & operator*=(Real rhs)
Definition: Swiz.h:82
SwizT & operator+=(Real rhs)
Definition: Swiz.h:69
SwizT & operator/=(Real rhs)
Definition: Swiz.h:83
MatrixS & elemDivEq(const MatrixBase< T > &rhs)
Divide each element by its corresponding element in rhs.
Definition: Base.h:208
SwizT & fromZero()
Wrapper ops.
Definition: Swiz.h:73
SwizT & operator=(Real rhs)
Allow scalar ops.
Definition: Swiz.h:68
const SwizT & swiz() const
Get subclass.
Definition: Swiz.h:92
N-dimensional vector.
Definition: Traits.h:12
Definition: Traits.h:20
Always returns true. Can be used to force a clause to be type dependent.
Definition: Meta.h:31
SwizT & elemAddEq(Real rhs)
Definition: Swiz.h:84
SwizT & operator-=(Real rhs)
Definition: Swiz.h:70
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
MatrixS & fromZero()
Zero all elements.
Definition: Base.h:70
Vec & operator=(const MatrixBase< T > &rhs)
Assign to row or column vector of any dimension. Asserts that if this vector has a fixed dimension th...
Definition: Vec.h:56
MatrixS & operator*=(const MatrixBase< T > &rhs)
Definition: Base.h:181
MatrixS & elemAddEq(Real rhs)
Add rhs to each element.
Definition: Base.h:192
SwizT & elemDivEq(const MatrixBase< T > &rhs)
Definition: Swiz.h:89
MatrixS & elemMulEq(const MatrixBase< T > &rhs)
Multiply each element with its corresponding element in rhs.
Definition: Base.h:202
Definition: Swiz.h:60
MatrixS & operator/=(Real rhs)
Definition: Base.h:185
MatrixS & elemSubEq(Real rhs)
Subtract rhs from each element.
Definition: Base.h:196
SwizT & elemMulEq(const MatrixBase< T > &rhs)
Definition: Swiz.h:87
Matrix base class.
Definition: Base.h:17
SwizT & elemSubEq(Real rhs)
Definition: Swiz.h:85
MatrixS & operator-=(const MatrixBase< T > &rhs)
Definition: Base.h:157
Vector reference holder for mutable swizzle operators.
Definition: Swiz.h:54
Global Honeycomb namespace.
Vec< matrix::priv::Traits< SwizT >::dim, typename matrix::priv::Traits< SwizT >::Real, matrix::priv::Traits< SwizT >::options > Super
Definition: Swiz.h:65
SwizT & operator+=(const MatrixBase< T > &rhs)
Definition: Swiz.h:79
SwizT & fromScalar(Real f)
Definition: Swiz.h:74
OutSeq && map(Range &&, Seqs &&..., OutSeq &&, Func &&)
Transform a series of sequences into an output.