Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
JTOOLS::JArray< N, T > Class Template Reference

One dimensional array of template objects with fixed length. More...

#include <JArray.hh>

Inheritance diagram for JTOOLS::JArray< N, T >:
JMATH::JMath< JArray< N, T > > JLANG::JEquals< JArray< N, T > >

Public Types

typedef const T * const_pointer
 
typedef T * pointer
 
typedef const T * const_iterator
 
typedef T * iterator
 
typedef std::reverse_iterator
< const_iterator
const_reverse_iterator
 
typedef std::reverse_iterator
< iterator
reverse_iterator
 
typedef T & reference
 
typedef const T & const_reference
 
typedef unsigned int size_type
 
typedef JLANG::JClass< T >
::argument_type 
argument_type
 

Public Member Functions

 JArray ()
 Default constructor. More...
 
 JArray (const JArray< N-1, T > &array, argument_type value)
 Append constructor. More...
 
 JArray (const JArray< N-1, const T > &array, argument_type value)
 Append constructor. More...
 
template<unsigned int M>
 JArray (const JArray< M, T > &array)
 Copy constructor. More...
 
template<unsigned int M>
 JArray (const JArray< M, const T > &array)
 Copy constructor. More...
 
 JArray (argument_type x, argument_type y,...)
 Initialise constructor. More...
 
 JArray (const T *p)
 Constructor. More...
 
 JArray (const JMultiKey< N, T > &key)
 Constructor. More...
 
 JArray (const JMultiKey< N, const T > &key)
 Constructor. More...
 
const_iterator begin () const
 get iterator to begin of data More...
 
const_iterator end () const
 get iterator to end of data More...
 
iterator begin ()
 get iterator to begin of data More...
 
iterator end ()
 get iterator to end of data More...
 
const_reverse_iterator rbegin () const
 get reverse iterator to begin of data More...
 
const_reverse_iterator rend () const
 get reverse iterator to begin of data More...
 
reverse_iterator rbegin ()
 get reverse iterator to begin of data More...
 
reverse_iterator rend ()
 get reverse iterator to end of data More...
 
const_reference operator[] (int index) const
 Get element at given index. More...
 
reference operator[] (int index)
 Get element at given index. More...
 
const_reference at (int index) const
 Get element at given index. More...
 
reference at (int index)
 Get element at given index. More...
 
const_pointer data () const
 Get pointer to data. More...
 
pointer data ()
 Get pointer to data. More...
 
JArray< N-1, T > pop_front () const
 Make a copy in which the first element is removed. More...
 
JArray< N-1, T > pop_back () const
 Make a copy in which the last element is removed. More...
 
JArraynegate ()
 Negate array. More...
 
JArrayadd (const JArray &array)
 Add array. More...
 
JArraysub (const JArray &array)
 Subtract array. More...
 
JArraymul (const double factor)
 Scale array. More...
 
JArraydiv (const double factor)
 Scale array. More...
 
bool equals (const JArray< N, T > &array) const
 Check equality. More...
 
JArray< N, T > & mul (const JNullType &object)
 Multiply with object. More...
 

Static Public Member Functions

static size_type size ()
 Get size of data. More...
 

Protected Member Functions

template<unsigned int M>
void assign (const JMultiKey< M, T > &key)
 Assign multidimensional key to array. More...
 
template<unsigned int M>
void assign (const JMultiKey< M, const T > &key)
 Assign multidimensional key to array. More...
 
void assign (const JMultiKey< 1, T > &key)
 Assign one-dimensional key to array. More...
 
void assign (const JMultiKey< 1, const T > &key)
 Assign one-dimensional key to array. More...
 

Protected Attributes

buffer [N]
 

Friends

JReaderoperator>> (JReader &in, JArray &buffer)
 Read array from input. More...
 
JWriteroperator<< (JWriter &out, const JArray &buffer)
 Write array to output. More...
 

Detailed Description

template<unsigned int N, class T>
class JTOOLS::JArray< N, T >

One dimensional array of template objects with fixed length.

The internal data structure consists of a standard C-array.

Definition at line 36 of file JArray.hh.

Member Typedef Documentation

template<unsigned int N, class T>
typedef const T* JTOOLS::JArray< N, T >::const_pointer

Definition at line 42 of file JArray.hh.

template<unsigned int N, class T>
typedef T* JTOOLS::JArray< N, T >::pointer

Definition at line 43 of file JArray.hh.

template<unsigned int N, class T>
typedef const T* JTOOLS::JArray< N, T >::const_iterator

Definition at line 44 of file JArray.hh.

template<unsigned int N, class T>
typedef T* JTOOLS::JArray< N, T >::iterator

Definition at line 45 of file JArray.hh.

template<unsigned int N, class T>
typedef std::reverse_iterator<const_iterator> JTOOLS::JArray< N, T >::const_reverse_iterator

Definition at line 46 of file JArray.hh.

template<unsigned int N, class T>
typedef std::reverse_iterator<iterator> JTOOLS::JArray< N, T >::reverse_iterator

Definition at line 47 of file JArray.hh.

template<unsigned int N, class T>
typedef T& JTOOLS::JArray< N, T >::reference

Definition at line 48 of file JArray.hh.

template<unsigned int N, class T>
typedef const T& JTOOLS::JArray< N, T >::const_reference

Definition at line 49 of file JArray.hh.

template<unsigned int N, class T>
typedef unsigned int JTOOLS::JArray< N, T >::size_type

Definition at line 50 of file JArray.hh.

template<unsigned int N, class T>
typedef JLANG::JClass<T>::argument_type JTOOLS::JArray< N, T >::argument_type

Definition at line 51 of file JArray.hh.

Constructor & Destructor Documentation

template<unsigned int N, class T>
JTOOLS::JArray< N, T >::JArray ( )
inline

Default constructor.

Definition at line 57 of file JArray.hh.

58  {}
template<unsigned int N, class T>
JTOOLS::JArray< N, T >::JArray ( const JArray< N-1, T > &  array,
argument_type  value 
)
inline

Append constructor.

Parameters
arrayarray
valuevalue

Definition at line 67 of file JArray.hh.

68  {
69  std::copy_n(array.data(), N-1, this->data());
70 
71  this->buffer[N-1] = value;
72  }
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:247
template<unsigned int N, class T>
JTOOLS::JArray< N, T >::JArray ( const JArray< N-1, const T > &  array,
argument_type  value 
)
inline

Append constructor.

Parameters
arrayarray
valuevalue

Definition at line 81 of file JArray.hh.

82  {
83  std::copy_n(array.data(), N-1, this->data());
84 
85  this->buffer[N-1] = value;
86  }
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:247
template<unsigned int N, class T>
template<unsigned int M>
JTOOLS::JArray< N, T >::JArray ( const JArray< M, T > &  array)
inline

Copy constructor.

Parameters
arrayarray

Definition at line 95 of file JArray.hh.

96  {
97  std::copy_n(array.data(), N-1 < M ? N-1 : M, this->data());
98  }
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:247
template<unsigned int N, class T>
template<unsigned int M>
JTOOLS::JArray< N, T >::JArray ( const JArray< M, const T > &  array)
inline

Copy constructor.

Parameters
arrayarray

Definition at line 107 of file JArray.hh.

108  {
109  std::copy_n(array.data(), N-1 < M ? N-1 : M, this->data());
110  }
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:247
template<unsigned int N, class T>
JTOOLS::JArray< N, T >::JArray ( argument_type  x,
argument_type  y,
  ... 
)
inline

Initialise constructor.

Parameters
xfirst value
ysecond value

Definition at line 119 of file JArray.hh.

120  {
121  va_list ap;
122 
123  va_start(ap, y);
124 
125  buffer[0] = x; // first argument
126  buffer[1] = y; // second argument
127 
128  for (unsigned int i = 2; i != N; ++i) {
129 
130  T value = va_arg(ap, T);
131 
132  buffer[i] = value; // next argument
133  }
134 
135  va_end(ap);
136  }
template<unsigned int N, class T>
JTOOLS::JArray< N, T >::JArray ( const T *  p)
inline

Constructor.

Parameters
ppointer to data

Definition at line 144 of file JArray.hh.

145  {
146  std::copy_n(p, N, data());
147  }
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:247
template<unsigned int N, class T>
JTOOLS::JArray< N, T >::JArray ( const JMultiKey< N, T > &  key)
inline

Constructor.

Parameters
keymulti-dimensional key

Definition at line 155 of file JArray.hh.

156  {
157  assign(key);
158  }
void assign(const JMultiKey< M, T > &key)
Assign multidimensional key to array.
Definition: JArray.hh:441
template<unsigned int N, class T>
JTOOLS::JArray< N, T >::JArray ( const JMultiKey< N, const T > &  key)
inline

Constructor.

Parameters
keymulti-dimensional key

Definition at line 166 of file JArray.hh.

167  {
168  assign(key);
169  }
void assign(const JMultiKey< M, T > &key)
Assign multidimensional key to array.
Definition: JArray.hh:441

Member Function Documentation

template<unsigned int N, class T>
const_iterator JTOOLS::JArray< N, T >::begin ( ) const
inline

get iterator to begin of data

Definition at line 172 of file JArray.hh.

template<unsigned int N, class T>
const_iterator JTOOLS::JArray< N, T >::end ( ) const
inline

get iterator to end of data

Definition at line 173 of file JArray.hh.

template<unsigned int N, class T>
iterator JTOOLS::JArray< N, T >::begin ( )
inline

get iterator to begin of data

Definition at line 176 of file JArray.hh.

template<unsigned int N, class T>
iterator JTOOLS::JArray< N, T >::end ( )
inline

get iterator to end of data

Definition at line 177 of file JArray.hh.

template<unsigned int N, class T>
const_reverse_iterator JTOOLS::JArray< N, T >::rbegin ( ) const
inline

get reverse iterator to begin of data

Definition at line 180 of file JArray.hh.

template<unsigned int N, class T>
const_reverse_iterator JTOOLS::JArray< N, T >::rend ( ) const
inline

get reverse iterator to begin of data

Definition at line 181 of file JArray.hh.

template<unsigned int N, class T>
reverse_iterator JTOOLS::JArray< N, T >::rbegin ( )
inline

get reverse iterator to begin of data

Definition at line 184 of file JArray.hh.

template<unsigned int N, class T>
reverse_iterator JTOOLS::JArray< N, T >::rend ( )
inline

get reverse iterator to end of data

Definition at line 185 of file JArray.hh.

template<unsigned int N, class T>
const_reference JTOOLS::JArray< N, T >::operator[] ( int  index) const
inline

Get element at given index.

Parameters
indexindex
Returns
element

Definition at line 194 of file JArray.hh.

195  {
196  return buffer[index];
197  }
template<unsigned int N, class T>
reference JTOOLS::JArray< N, T >::operator[] ( int  index)
inline

Get element at given index.

Parameters
indexindex
Returns
element

Definition at line 206 of file JArray.hh.

207  {
208  return buffer[index];
209  }
template<unsigned int N, class T>
const_reference JTOOLS::JArray< N, T >::at ( int  index) const
inline

Get element at given index.

Parameters
indexindex
Returns
element at index

Definition at line 218 of file JArray.hh.

219  {
220  if (index >= 0 && index < N)
221  return buffer[index];
222  else
223  throw JIndexOutOfRange("JArray<>::at()");
224  }
template<unsigned int N, class T>
reference JTOOLS::JArray< N, T >::at ( int  index)
inline

Get element at given index.

Parameters
indexindex
Returns
element at index

Definition at line 233 of file JArray.hh.

234  {
235  if (index >= 0 && index < N)
236  return buffer[index];
237  else
238  throw JIndexOutOfRange("JArray<>::at()");
239  }
template<unsigned int N, class T>
const_pointer JTOOLS::JArray< N, T >::data ( ) const
inline

Get pointer to data.

Returns
pointer to data

Definition at line 247 of file JArray.hh.

248  {
249  return buffer;
250  }
template<unsigned int N, class T>
pointer JTOOLS::JArray< N, T >::data ( )
inline

Get pointer to data.

Returns
pointer to data

Definition at line 258 of file JArray.hh.

259  {
260  return buffer;
261  }
template<unsigned int N, class T>
static size_type JTOOLS::JArray< N, T >::size ( )
inlinestatic

Get size of data.

Returns
size of data

Definition at line 269 of file JArray.hh.

270  {
271  return N;
272  }
template<unsigned int N, class T>
JArray<N-1, T> JTOOLS::JArray< N, T >::pop_front ( ) const
inline

Make a copy in which the first element is removed.

Returns
array

Definition at line 280 of file JArray.hh.

281  {
282  return JArray<N-1, T>(&buffer[1]);
283  }
One dimensional array of template objects with fixed length.
Definition: JArray.hh:36
template<unsigned int N, class T>
JArray<N-1, T> JTOOLS::JArray< N, T >::pop_back ( ) const
inline

Make a copy in which the last element is removed.

Returns
array

Definition at line 291 of file JArray.hh.

292  {
293  return JArray<N-1, T>(buffer);
294  }
One dimensional array of template objects with fixed length.
Definition: JArray.hh:36
template<unsigned int N, class T>
JArray& JTOOLS::JArray< N, T >::negate ( )
inline

Negate array.

Returns
this array

Definition at line 302 of file JArray.hh.

303  {
304  for (iterator i = this->begin(); i != this->end(); ++i) {
305  *i = -(*i);
306  }
307 
308  return *this;
309  }
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:172
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:173
T * iterator
Definition: JArray.hh:45
template<unsigned int N, class T>
JArray& JTOOLS::JArray< N, T >::add ( const JArray< N, T > &  array)
inline

Add array.

Parameters
arrayarray
Returns
this array

Definition at line 318 of file JArray.hh.

319  {
320  const_iterator j = array.begin();
321 
322  for (iterator i = this->begin(); i != this->end(); ++i, ++j) {
323  *i += *j;
324  }
325 
326  return *this;
327  }
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:172
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:173
T * iterator
Definition: JArray.hh:45
const T * const_iterator
Definition: JArray.hh:44
template<unsigned int N, class T>
JArray& JTOOLS::JArray< N, T >::sub ( const JArray< N, T > &  array)
inline

Subtract array.

Parameters
arrayarray
Returns
this array

Definition at line 336 of file JArray.hh.

337  {
338  const_iterator j = array.begin();
339 
340  for (iterator i = this->begin(); i != this->end(); ++i, ++j) {
341  *i -= *j;
342  }
343 
344  return *this;
345  }
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:172
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:173
T * iterator
Definition: JArray.hh:45
const T * const_iterator
Definition: JArray.hh:44
template<unsigned int N, class T>
JArray& JTOOLS::JArray< N, T >::mul ( const double  factor)
inline

Scale array.

Parameters
factormultiplication factor
Returns
this array

Definition at line 354 of file JArray.hh.

355  {
356  for (iterator i = this->begin(); i != this->end(); ++i) {
357  *i *= factor;
358  }
359 
360  return *this;
361  }
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:172
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:173
T * iterator
Definition: JArray.hh:45
template<unsigned int N, class T>
JArray& JTOOLS::JArray< N, T >::div ( const double  factor)
inline

Scale array.

Parameters
factordivision factor
Returns
this array

Definition at line 370 of file JArray.hh.

371  {
372  for (iterator i = this->begin(); i != this->end(); ++i) {
373  *i /= factor;
374  }
375 
376  return *this;
377  }
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:172
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:173
T * iterator
Definition: JArray.hh:45
template<unsigned int N, class T>
bool JTOOLS::JArray< N, T >::equals ( const JArray< N, T > &  array) const
inline

Check equality.

Parameters
arrayarray
Returns
true if arrays are equal; else false

Definition at line 386 of file JArray.hh.

387  {
388  for (const_iterator i = this->begin(), j = array.begin(); i != this->end(); ++i, ++j) {
389  if (*i != *j) {
390  return false;
391  }
392  }
393 
394  return true;
395  }
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:172
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:173
const T * const_iterator
Definition: JArray.hh:44
template<unsigned int N, class T>
template<unsigned int M>
void JTOOLS::JArray< N, T >::assign ( const JMultiKey< M, T > &  key)
inlineprotected

Assign multidimensional key to array.

Parameters
keymulti-dimensional key

Definition at line 441 of file JArray.hh.

442  {
443  buffer[N-M] = key.first;
444 
445  assign(key.second);
446  }
void assign(const JMultiKey< M, T > &key)
Assign multidimensional key to array.
Definition: JArray.hh:441
template<unsigned int N, class T>
template<unsigned int M>
void JTOOLS::JArray< N, T >::assign ( const JMultiKey< M, const T > &  key)
inlineprotected

Assign multidimensional key to array.

Parameters
keymulti-dimensional key

Definition at line 455 of file JArray.hh.

456  {
457  buffer[N-M] = key.first;
458 
459  assign(key.second);
460  }
void assign(const JMultiKey< M, T > &key)
Assign multidimensional key to array.
Definition: JArray.hh:441
template<unsigned int N, class T>
void JTOOLS::JArray< N, T >::assign ( const JMultiKey< 1, T > &  key)
inlineprotected

Assign one-dimensional key to array.

Parameters
keyone-dimensional key

Definition at line 468 of file JArray.hh.

469  {
470  buffer[N-1] = key.first;
471  }
template<unsigned int N, class T>
void JTOOLS::JArray< N, T >::assign ( const JMultiKey< 1, const T > &  key)
inlineprotected

Assign one-dimensional key to array.

Parameters
keyone-dimensional key

Definition at line 479 of file JArray.hh.

480  {
481  buffer[N-1] = key.first;
482  }
JArray< N, T > & JMATH::JMath< JArray< N, T > , JNullType >::mul ( const JNullType object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 273 of file JMath.hh.

274  {
275  return static_cast<JFirst_t&>(*this) = JCalculator<JFirst_t>::calculator.mul(static_cast<const JFirst_t&>(*this), object);
276  }
Auxiliary class for product evaluation of objects.
Definition: JCalculator.hh:18

Friends And Related Function Documentation

template<unsigned int N, class T>
JReader& operator>> ( JReader in,
JArray< N, T > &  buffer 
)
friend

Read array from input.

Parameters
inreader
bufferarray
Returns
reader

Definition at line 405 of file JArray.hh.

406  {
407  for (iterator i = buffer.begin(); i != buffer.end(); ++i) {
408  in >> *i;
409  }
410 
411  return in;
412  }
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:172
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:173
T * iterator
Definition: JArray.hh:45
template<unsigned int N, class T>
JWriter& operator<< ( JWriter out,
const JArray< N, T > &  buffer 
)
friend

Write array to output.

Parameters
outwriter
bufferarray
Returns
writer

Definition at line 422 of file JArray.hh.

423  {
424  for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
425  out << *i;
426  }
427 
428  return out;
429  }
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:172
const_iterator end() const
get iterator to end of data
Definition: JArray.hh:173
const T * const_iterator
Definition: JArray.hh:44

Member Data Documentation

template<unsigned int N, class T>
T JTOOLS::JArray< N, T >::buffer[N]
protected

Definition at line 433 of file JArray.hh.


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