Torque3D Documentation / _generateds / tFixedSizeVector.h

tFixedSizeVector.h

Engine/source/core/util/tFixedSizeVector.h

More...

Classes:

class

A vector with a compile-time constant size.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _TFIXEDSIZEVECTOR_H_
 25#define _TFIXEDSIZEVECTOR_H_
 26
 27
 28/// A vector with a compile-time constant size.
 29template< typename T, S32 SIZE >
 30class FixedSizeVector
 31{
 32   protected:
 33
 34      T mArray[ SIZE ];
 35
 36   public:
 37
 38      typedef T* iterator;
 39      typedef const T* const_iterator;
 40
 41      FixedSizeVector() {}
 42      FixedSizeVector( const T& a ) { mArray[ 0 ] = a; }
 43      FixedSizeVector( const T& a, const T& b ) { mArray[ 0 ] = a; mArray[ 1 ] = b; }
 44      FixedSizeVector( const T& a, const T& b, const T& c ) { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; }
 45      FixedSizeVector( const T& a, const T& b, const T& c, const T& d ) { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; }
 46      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e ) { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; }
 47      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f )
 48         { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; }
 49      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g )
 50         { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; }
 51      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h )
 52         { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; }
 53      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i )
 54         { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; }
 55      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i, const T& j )
 56         { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; }
 57      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i, const T& j, const T& k )
 58         { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; }
 59      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i, const T& j, const T& k, const T& l )
 60         { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; mArray[ 11 ] = l; }
 61      FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i, const T& j, const T& k, const T& l, const T& m )
 62         { mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; mArray[ 11 ] = l; mArray[ 12 ] =m; }
 63
 64      U32 size() const { return SIZE; }
 65      bool empty() const { return ( SIZE == 0 ); }
 66      const T* address() const { return mArray; }
 67      T* address() { return mArray; }
 68
 69      iterator begin() { return &mArray[ 0 ]; }
 70      iterator end() { return &mArray[ SIZE ]; }
 71      const_iterator begin() const { return &mArray[ 0 ]; }
 72      const_iterator end() const { return &mArray[ SIZE ]; }
 73
 74      const T& first() const
 75      {
 76         AssertFatal( !empty(), "FixedSizeVector::first - Vector is empty" );
 77         return mArray[ 0 ];
 78      }
 79      T& first()
 80      {
 81         AssertFatal( !empty(), "FixedSizeVector::first - Vector is empty" );
 82         return mArray[ 0 ];
 83      }
 84      const T& last() const
 85      {
 86         AssertFatal( !empty(), "FixedSizeVector::last - Vector is empty" );
 87         return mArray[ size() - 1 ];
 88      }
 89      T& last()
 90      {
 91         AssertFatal( !empty(), "FixedSizeVector::last - Vector is empty" );
 92         return mArray[ size() - 1 ];
 93      }
 94
 95      const T& operator []( U32 index ) const
 96      {
 97         AssertFatal( index <= size(), "FixedSizeVector::operator[] - Index out of range" );
 98         return mArray[ index ];
 99      }
100      T& operator []( U32 index )
101      {
102         AssertFatal( index <= size(), "FixedSizeVector::operator[] - Index out of range" );
103         return mArray[ index ];
104      }
105};
106
107#endif // !_TFIXEDSIZEVECTOR_H_
108