2 Copyright (C) 2009 Sony Computer Entertainment Inc.
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
21 namespace Vectormath {
25 //--------------------------------------------------------------------------------------------------
35 // Default constructor; does no initialization
37 inline boolInVec( ) { };
39 // Construct from a value converted from float
41 inline boolInVec(floatInVec vec);
43 // Explicit cast from bool
45 explicit inline boolInVec(bool scalar);
47 // Explicit cast to bool
49 inline bool getAsBool() const;
51 #ifndef _VECTORMATH_NO_SCALAR_CAST
52 // Implicit cast to bool
54 inline operator bool() const;
57 // Boolean negation operator
59 inline const boolInVec operator ! () const;
61 // Assignment operator
63 inline boolInVec& operator = (boolInVec vec);
65 // Boolean and assignment operator
67 inline boolInVec& operator &= (boolInVec vec);
69 // Boolean exclusive or assignment operator
71 inline boolInVec& operator ^= (boolInVec vec);
73 // Boolean or assignment operator
75 inline boolInVec& operator |= (boolInVec vec);
81 inline const boolInVec operator == (boolInVec vec0, boolInVec vec1);
85 inline const boolInVec operator != (boolInVec vec0, boolInVec vec1);
89 inline const boolInVec operator & (boolInVec vec0, boolInVec vec1);
91 // Exclusive or operator
93 inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1);
97 inline const boolInVec operator | (boolInVec vec0, boolInVec vec1);
99 // Conditionally select between two values
101 inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1);
104 } // namespace Vectormath
107 //--------------------------------------------------------------------------------------------------
108 // boolInVec implementation
111 #include "floatInVec.h"
113 namespace Vectormath {
116 boolInVec::boolInVec(floatInVec vec)
118 *this = (vec != floatInVec(0.0f));
122 boolInVec::boolInVec(bool scalar)
124 mData = -(int)scalar;
129 boolInVec::getAsBool() const
134 #ifndef _VECTORMATH_NO_SCALAR_CAST
136 boolInVec::operator bool() const
144 boolInVec::operator ! () const
146 return boolInVec(!mData);
151 boolInVec::operator = (boolInVec vec)
159 boolInVec::operator &= (boolInVec vec)
167 boolInVec::operator ^= (boolInVec vec)
175 boolInVec::operator |= (boolInVec vec)
183 operator == (boolInVec vec0, boolInVec vec1)
185 return boolInVec(vec0.getAsBool() == vec1.getAsBool());
190 operator != (boolInVec vec0, boolInVec vec1)
192 return !(vec0 == vec1);
197 operator & (boolInVec vec0, boolInVec vec1)
199 return boolInVec(vec0.getAsBool() & vec1.getAsBool());
204 operator | (boolInVec vec0, boolInVec vec1)
206 return boolInVec(vec0.getAsBool() | vec1.getAsBool());
211 operator ^ (boolInVec vec0, boolInVec vec1)
213 return boolInVec(vec0.getAsBool() ^ vec1.getAsBool());
218 select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1)
220 return (select_vec1.getAsBool() == 0) ? vec0 : vec1;
223 } // namespace Vectormath
225 #endif // boolInVec_h