Tulip  5.3.0
Large graphs analysis and drawing
VectorCast.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 //@TLPGEOLICENCE#
22 
23 #ifndef _TLP_VECTORCAST_H
24 #define _TLP_VECTORCAST_H
25 
26 #include <cassert>
27 #include <tulip/Vector.h>
28 
29 #define TEMPLATEVECTORCAST template <typename Obj, unsigned int SIZE, typename TYPE>
30 
31 #define VECTORCAST tlp::VectorCast<Obj, SIZE, TYPE>
32 
33 namespace tlp {
34 /**
35  * @ingroup Structures
36  * \brief class for mathematical vector
37  *
38  * Enables to create a Vector of Obj with a
39  * fixed size and provides Mathematical operation. Mathematical
40  * operators must be defined for Obj. Out of bound accesses are only checked
41  * in debug mode.
42  *
43  * \author : David Auber auber@labri.fr
44  * \version 0.0.1 24/01/2003
45  */
46 TEMPLATEVECTORCAST
47 class TLP_SCOPE VectorCast : public Vector<Obj, SIZE> {
48 public:
49  VectorCast() {}
50  inline explicit VectorCast(const tlp::Vector<float, 3> &v) : Vector<Obj, SIZE>(v) {}
51 
52  inline TYPE &operator*=(const Obj obj) {
53  return (TYPE &)this->Vector<Obj, SIZE>::operator*=(obj);
54  }
55  inline TYPE &operator*=(const Vector<Obj, SIZE> &vec) {
56  return (TYPE &)this->Vector<Obj, SIZE>::operator*=(vec);
57  }
58  inline TYPE &operator/=(const Obj obj) {
59  return (TYPE &)this->Vector<Obj, SIZE>::operator/=(obj);
60  }
61  inline TYPE &operator/=(const Vector<Obj, SIZE> &vec) {
62  return (TYPE &)this->Vector<Obj, SIZE>::operator/=(vec);
63  }
64  inline TYPE &operator+=(const Obj obj) {
65  return (TYPE &)this->Vector<Obj, SIZE>::operator+=(obj);
66  }
67  inline TYPE &operator+=(const Vector<Obj, SIZE> &vec) {
68  return (TYPE &)this->Vector<Obj, SIZE>::operator+=(vec);
69  }
70  inline TYPE &operator-=(const Obj obj) {
71  return (TYPE &)this->Vector<Obj, SIZE>::operator-=(obj);
72  }
73  inline TYPE &operator-=(const Vector<Obj, SIZE> &vec) {
74  return (TYPE &)this->Vector<Obj, SIZE>::operator-=(vec);
75  }
76  inline TYPE &operator^=(const Vector<Obj, SIZE> &vec) {
77  return (TYPE &)this->Vector<Obj, SIZE>::operator^=(vec);
78  }
79  inline TYPE &fill(const Obj obj) {
80  return (TYPE &)this->Vector<Obj, SIZE>::fill(obj);
81  }
82 
83  inline TYPE operator*(const Vector<Obj, SIZE> &v) const {
84  return VECTORCAST(*this) *= v;
85  }
86  inline TYPE operator*(const Obj v) const {
87  return VECTORCAST(*this) *= v;
88  }
89  inline TYPE operator+(const Vector<Obj, SIZE> &v) const {
90  return VECTORCAST(*this) += v;
91  }
92  inline TYPE operator+(const Obj v) const {
93  return VECTORCAST(*this) += v;
94  }
95  inline TYPE operator-(const Vector<Obj, SIZE> &v) const {
96  return VECTORCAST(*this) -= v;
97  }
98  inline TYPE operator-(const Obj v) const {
99  return VECTORCAST(*this) -= v;
100  }
101  inline TYPE operator/(const Vector<Obj, SIZE> &v) const {
102  return VECTORCAST(*this) /= v;
103  }
104  inline TYPE operator/(const Obj v) const {
105  return VECTORCAST(*this) /= v;
106  }
107  inline TYPE operator^(const Vector<Obj, SIZE> &v) const {
108  return VECTORCAST(*this) ^= v;
109  }
110 };
111 } // namespace tlp
112 
113 #endif
114 ///@endcond