Xrb::Vector< T, dimension > Class Template Reference

Generalized vector class geared towards high speed efficiency. More...

#include <xrb_vector.hpp>

List of all members.

Public Member Functions

 Vector ()
 Default constructor.
 Vector (T const fill_with)
 Constructs a Vector, setting each component to fill_with.
 Vector (T const component0, T const component1)
 Constructs a vector with the specified ordered pair.
 Vector (T const component0, T const component1, T const component2)
 Constructs a vector with the specified ordered triplet.
 Vector (T const *const components)
 Constructs a vector from an array of component values.
 Vector (Vector< T, dimension > const &source)
 Copy constructor.
 ~Vector ()
 Destructor.
void operator= (Vector< T, dimension > const &operand)
 Assignment operator.
bool operator== (Vector< T, dimension > const &operand) const
 Equality operator.
bool operator!= (Vector< T, dimension > const &operand) const
 Inequality operator.
T const & operator[] (Uint32 const index) const
 Bracket operator with const qualification.
T & operator[] (Uint32 const index)
 Bracket operator.
void operator+= (Vector< T, dimension > const &operand)
 In-place addition operator.
void operator-= (Vector< T, dimension > const &operand)
 In-place addition operator.
void operator*= (Vector< T, dimension > const &operand)
 In-place multiplication operator.
template<typename U >
void operator*= (U const operand)
 In-place multiplication operator.
void operator/= (Vector< T, dimension > const &operand)
 In-place division operator.
template<typename U >
void operator/= (U const operand)
 In-place division operator.
Vector< T, dimension > operator- () const
 Unary negation operator.
Length () const
 Returns the length of this vector.
LengthSquared () const
 Returns the square of the length of this vector.
Vector< T, dimension > Normalization () const
 Returns the normalized version of this vector.
bool IsZero () const
 Test for equality with the zero vector.
template<typename U >
Vector< U, dimension > StaticCast () const
 The Vector equivalent to static_cast.
void FillWith (T const fill_with)
 Sets each component in this vector to the specified value.
void Negate ()
 Sets this vector to the negative of itself.
void Normalize ()
 Sets this vector's length to 1, while preserving its direction.
void SetComponents (T const component0, T const component1)
 Assigns the specified ordered pair to this vector.
void SetComponents (T const component0, T const component1, T const component2)
 Assigns the specified ordered triplet to this vector.
void SetComponents (T const *const components)
 Assigns the specified ordered array of components to the components of this vector.
template<typename U >
void StaticCastAssign (Vector< U, dimension > const &source)
 The Vector equivalent to vector1 = static_cast<T>(vector2).
void Fprint (FILE *const fptr, char const *const component_printf_format, bool const add_newline=true) const
 Prints the dimension and components of this vector to the given file stream.

Public Attributes

m [dimension]
 The array which stores the vector's components.

Static Public Attributes

static Vector< T, dimension > const ms_zero
 The zero vector.


Detailed Description

template<typename T, Uint32 dimension>
class Xrb::Vector< T, dimension >

Generalized vector class geared towards high speed efficiency.

The scalar template type given for each instantiation of Vector must have certain operations defined. Namely, addition, subtraction, unary negation, multiplication, division and a square root function.

The type must be a regular assignable type (not a type with possibly a vtable, and definitely not a type which requires deep copying to perform assignment). This is because if XRB_VECTOR_USES_MEMCPY is defined, memcpy() is used to increase efficiency on certain operations. Also, if XRB_VECTOR_USES_MEMCMP is defined, memcmp() is used on certain operations. The default behavior is to iterate over each component for operations.

Note:
For each instantiation of Vector, there must be a corresponding instance of ms_zero.

Definition at line 56 of file xrb_vector.hpp.


Constructor & Destructor Documentation

template<typename T, Uint32 dimension>
Xrb::Vector< T, dimension >::Vector (  )  [inline]

Default constructor.

Does no initialization for the sake of efficiency.

Definition at line 78 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
Xrb::Vector< T, dimension >::Vector ( T const   fill_with  )  [inline, explicit]

Constructs a Vector, setting each component to fill_with.

Does/can not use any memcpy/memset functions.

Parameters:
fill_with The value to set each component to.

Definition at line 85 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
Xrb::Vector< T, dimension >::Vector ( T const   component0,
T const   component1 
) [inline]

Constructs a vector with the specified ordered pair.

I gave up trying for partial template specialization (or whatever it's called) to specify the two-parameter constructor for only Vector<T, 2>, and settled for asserting that dimension is 2.

Parameters:
component0 The value to assign to the first component (m[0]).
component1 The value to assign to the second component (m[1]).

Definition at line 97 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
Xrb::Vector< T, dimension >::Vector ( T const   component0,
T const   component1,
T const   component2 
) [inline]

Constructs a vector with the specified ordered triplet.

I gave up trying for partial template specialization (or whatever it's called) to specify the three-parameter constructor for only Vector<T, 3>, and settled for asserting that dimension is 3.

Parameters:
component0 The value to assign to the first component (m[0]).
component1 The value to assign to the second component (m[1]).
component2 The value to assign to the third component (m[2]).

Definition at line 111 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
Xrb::Vector< T, dimension >::Vector ( T const *const   components  )  [inline]

Constructs a vector from an array of component values.

Parameters:
components The array of ordered components to construct this vector with. Must be at least dimension elements long.

Definition at line 123 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
Xrb::Vector< T, dimension >::Vector ( Vector< T, dimension > const &  source  )  [inline]

Copy constructor.

Parameters:
source The vector to copy.

Definition at line 136 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
Xrb::Vector< T, dimension >::~Vector (  )  [inline]

Destructor.

No cleanup is necessary.

Definition at line 148 of file xrb_vector.hpp.


Member Function Documentation

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::operator= ( Vector< T, dimension > const &  operand  )  [inline]

Assignment operator.

Parameters:
operand The vector to assign.

Definition at line 159 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
bool Xrb::Vector< T, dimension >::operator== ( Vector< T, dimension > const &  operand  )  const [inline]

Equality operator.

Parameters:
operand The vector to test equality against.
Returns:
True iff each component of operand is equal to the corresponding component of this vector.

Definition at line 173 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
bool Xrb::Vector< T, dimension >::operator!= ( Vector< T, dimension > const &  operand  )  const [inline]

Inequality operator.

Parameters:
operand The vector to test inequality against.
Returns:
True iff any component of operand is unequal to the corresponding component of this vector.

Definition at line 189 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
T const& Xrb::Vector< T, dimension >::operator[] ( Uint32 const   index  )  const [inline]

Bracket operator with const qualification.

Array index referencing. Emulates the syntax of a normal array, giving a more appealing usage (vector[1] instead of vector.m[1]).

Parameters:
index The index of the component to reference.
Returns:
A const reference to the desired vector component.

Definition at line 206 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
T& Xrb::Vector< T, dimension >::operator[] ( Uint32 const   index  )  [inline]

Bracket operator.

Array index referencing. Emulates the syntax of a normal array, giving a more appealing usage (vector[1] instead of vector.m[1]).

Parameters:
index The index of the component to reference.
Returns:
A non-const reference to the desired vector component.

Definition at line 217 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::operator+= ( Vector< T, dimension > const &  operand  )  [inline]

In-place addition operator.

Performs vector addition on this and the given vector, storing the result in this vector.

Parameters:
operand The vector to add to this vector.

Definition at line 227 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::operator-= ( Vector< T, dimension > const &  operand  )  [inline]

In-place addition operator.

Performs vector subtraction on this and the given vector, storing the result in this vector.

Parameters:
operand The vector to subtract from this vector.

Definition at line 237 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::operator*= ( Vector< T, dimension > const &  operand  )  [inline]

In-place multiplication operator.

Performs scalar multiplication of the components of operand on each respective component of this vector, storing the result in this vector.

Parameters:
operand The vector to component-wise multiply this vector by.

Definition at line 249 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
template<typename U >
void Xrb::Vector< T, dimension >::operator*= ( U const   operand  )  [inline]

In-place multiplication operator.

Performs scalar multiplication on this vector by the given scalar storing the result in this vector.

Parameters:
operand The scalar value to multiply this vector by.

Definition at line 260 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::operator/= ( Vector< T, dimension > const &  operand  )  [inline]

In-place division operator.

Performs scalar division of the components of this vector by each respective component of operand, storing the result in this vector.

Parameters:
operand The vector to component-wise divide this vector by.
Note:
There is no protection here against dividing by zero.

Definition at line 273 of file xrb_vector.hpp.

Referenced by Xrb::Vector< Float, 2 >::Normalize().

template<typename T, Uint32 dimension>
template<typename U >
void Xrb::Vector< T, dimension >::operator/= ( U const   operand  )  [inline]

In-place division operator.

Performs scalar division on this vector by the given scalar storing the result in this vector.

Parameters:
operand The scalar value to divide this vector by.
Note:
There is no protection here against dividing by zero.

Definition at line 285 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
Vector<T, dimension> Xrb::Vector< T, dimension >::operator- (  )  const [inline]

Unary negation operator.

Returns:
The arithmatic negative of this vector.

Definition at line 293 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
T Xrb::Vector< T, dimension >::Length (  )  const [inline]

Returns the length of this vector.

Uses a square root function specific to Vector<T, dimension, Float>, and thus for integral scalar types, the actual vector length after this procedure may not be 1.

Returns:
The length of this vector.

Definition at line 311 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
T Xrb::Vector< T, dimension >::LengthSquared (  )  const [inline]

Returns the square of the length of this vector.

This is as close as you can come to the length of a vector without needing a square root function.

Returns:
The square of the length of this vector.

Definition at line 320 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
Vector<T, dimension> Xrb::Vector< T, dimension >::Normalization (  )  const [inline]

Returns the normalized version of this vector.

Uses a square root function specific to Vector<T, dimension, Float>, and thus for integral scalar types, the actual vector length after this procedure may not be 1.

Returns:
The normalized version of this vector.

Definition at line 330 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
bool Xrb::Vector< T, dimension >::IsZero (  )  const [inline]

Test for equality with the zero vector.

Returns:
True iff each component of the zero vector is equal to the corresponding component of this vector.

Definition at line 340 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
template<typename U >
Vector<U, dimension> Xrb::Vector< T, dimension >::StaticCast (  )  const [inline]

The Vector equivalent to static_cast.

Performs static_cast on each of this Vector's components to convert the values to the desired.

Definition at line 357 of file xrb_vector.hpp.

Referenced by Xrb::WidgetSkin::RatiosFromScreenCoords().

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::FillWith ( T const   fill_with  )  [inline]

Sets each component in this vector to the specified value.

Parameters:
fill_with The value to assign to each vector component.

Definition at line 372 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::Negate (  )  [inline]

Sets this vector to the negative of itself.

The in-place negation of this vector, or to put another way,

 ms_zero - *this 
(or at least it better equal that!).

Definition at line 381 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::Normalize (  )  [inline]

Sets this vector's length to 1, while preserving its direction.

Uses a square root function specific to Vector<T, dimension, Float>, and thus for integral scalar types, the actual vector length after this procedure may not be 1.

Definition at line 391 of file xrb_vector.hpp.

Referenced by Xrb::Vector< Float, 2 >::Normalization().

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::SetComponents ( T const   component0,
T const   component1 
) [inline]

Assigns the specified ordered pair to this vector.

I gave up trying for partial template specialization (or whatever it's called) to specify the two-parameter SetComponents for only Vector<T, 2>, and settled for asserting that the dimension is 2.

Parameters:
component0 The value to assign to the first component (m[0]).
component1 The value to assign to the second component (m[1]).

Definition at line 402 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::SetComponents ( T const   component0,
T const   component1,
T const   component2 
) [inline]

Assigns the specified ordered triplet to this vector.

I gave up trying for partial template specialization (or whatever it's called) to specify the three-parameter SetComponents for only Vector<T, 3>, and settled for asserting that the dimension is 3.

Parameters:
component0 The value to assign to the first component (m[0]).
component1 The value to assign to the second component (m[1]).
component2 The value to assign to the third component (m[2]).

Definition at line 416 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::SetComponents ( T const *const   components  )  [inline]

Assigns the specified ordered array of components to the components of this vector.

Parameters:
components The array of ordered components to assign to this vector. Must be at least dimension elements long.

Definition at line 429 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
template<typename U >
void Xrb::Vector< T, dimension >::StaticCastAssign ( Vector< U, dimension > const &  source  )  [inline]

The Vector equivalent to vector1 = static_cast<T>(vector2).

Performs static_cast on each of the operand vector's components to convert the values.

Parameters:
source The vector to assign.

Definition at line 445 of file xrb_vector.hpp.

template<typename T, Uint32 dimension>
void Xrb::Vector< T, dimension >::Fprint ( FILE *const   fptr,
char const *const   component_printf_format,
bool const   add_newline = true 
) const [inline]

Prints the dimension and components of this vector to the given file stream.

The format of each vector component is specified by component_printf_format, which should be the printf format string for a single vector component. This value must be passed in because the printf format is not known in the general case.

Parameters:
fptr The file stream to print to (e.g. stderr).
component_printf_format The printf format string for a single vector component.
add_newline Indicates if a newline should be printed as the last character (default value is true).

Definition at line 467 of file xrb_vector.hpp.

Referenced by Xrb::Fprint().


Member Data Documentation

template<typename T, Uint32 dimension>
Vector< T, dimension > const Xrb::Vector< T, dimension >::ms_zero [inline, static]

The zero vector.

Templatized static definition of the ms_zero vector.

This member serves as the type-specific zero vector for use in the IsZero and IsNonZero functions, as well as providing a fast, convenient and elegant way to refer to possibly the most commonly used vector value.

This templatized definition will take care of defining the static ms_zero member vector, assuming that static_cast<T>(0) work.

Definition at line 66 of file xrb_vector.hpp.

Referenced by Xrb::Vector< Float, 2 >::IsZero().


The documentation for this class was generated from the following file:

Hosted by SourceForge.net Logo -- Generated on Fri Aug 21 21:46:39 2009 for XuqRijBuh by doxygen 1.5.8