Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Public Member Functions | Protected Attributes | List of all members
kome::core::Vector Class Reference

vector class More...

#include <Vector.h>

Public Member Functions

 Vector (const unsigned int dim)
 constructor More...
 
 Vector (const Vector &v)
 copy constructor More...
 
virtual ~Vector ()
 destructor
 
unsigned int getDimention ()
 gets the dimention size of vector More...
 
double norm ()
 gets the norm of the vector More...
 
double dot (const Vector &v)
 gets dot production More...
 
Vector cross (const Vector &v)
 get cross production More...
 
Vector operator= (const Vector &v)
 copy vector More...
 
double & operator() (const unsigned int index)
 gets reference of value of specified element More...
 
Vectoroperator+= (const Vector &v)
 vector addition More...
 
Vectoroperator-= (const Vector &v)
 vector subtraction More...
 
Vectoroperator*= (const double k)
 scalar multiplication More...
 
Vectoroperator/= (const double k)
 scalar division More...
 
Vector operator+ (const Vector &v)
 vector addition More...
 
Vector operator- (const Vector &v)
 vector subtraction More...
 
Vector operator* (const double k)
 scalar multiplication More...
 
Vector operator/ (const double k)
 scalar division More...
 

Protected Attributes

const unsigned int m_dim
 
double *const m_array
 

Detailed Description

vector class

Definition at line 22 of file Vector.h.

Constructor & Destructor Documentation

kome::core::Vector::Vector ( const unsigned int  dim)

constructor

Parameters
[in]dimdimention size

Definition at line 30 of file Vector.cpp.

31  : m_dim( dim ), m_array( ( dim == 0 ) ? NULL : new double[ dim ] ) {
32  if( m_array != NULL ) {
33  fillzero( m_array, sizeof( double ) * m_dim );
34  }
35 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
#define NULL
Definition: CoreMacros.h:18
void fillzero(void *p, size_t n)
This function fills a block of memory zeros.

Here is the call graph for this function:

kome::core::Vector::Vector ( const Vector v)

copy constructor

Parameters
[in]vVector object to be copied

Definition at line 38 of file Vector.cpp.

39  : m_dim( v.m_dim ), m_array( ( v.m_array == NULL ) ? NULL : new double[ v.m_dim ] ) {
40  if( m_array != NULL ) {
41  memcpy( m_array, v.m_array, sizeof( double ) * v.m_dim );
42  }
43 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
#define NULL
Definition: CoreMacros.h:18

Member Function Documentation

Vector kome::core::Vector::cross ( const Vector v)

get cross production

Parameters
[in]vvector to product
Returns
cross production vector

Definition at line 84 of file Vector.cpp.

84  {
85  if( m_dim != 3 || v.m_dim != 3 ) {
86  throw FMT( "Vector size is illegal." );
87  }
88 
89  Vector tmp( 3 );
90  tmp( 0 ) = m_array[ 1 ] * v.m_array[ 2 ] - m_array[ 2 ] * v.m_array[ 1 ];
91  tmp( 1 ) = m_array[ 2 ] * v.m_array[ 0 ] - m_array[ 0 ] * v.m_array[ 2 ];
92  tmp( 2 ) = m_array[ 0 ] * v.m_array[ 1 ] - m_array[ 1 ] * v.m_array[ 0 ];
93 
94  return tmp;
95 }
vector class
Definition: Vector.h:22
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
double kome::core::Vector::dot ( const Vector v)

gets dot production

Parameters
[in]vvector to product
Returns
dot production

Definition at line 70 of file Vector.cpp.

70  {
71  if( v.m_dim != m_dim ) {
72  throw FMT( "Vector size is illegal." );
73  }
74 
75  double dp = 0.0;
76  for( unsigned int i = 0; i < m_dim; i++ ) {
77  dp += m_array[ i ] * v.m_array[ i ];
78  }
79 
80  return dp;
81 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
unsigned int kome::core::Vector::getDimention ( )

gets the dimention size of vector

Returns
the dimention size of vector

Definition at line 53 of file Vector.cpp.

53  {
54  return m_dim;
55 }
const unsigned int m_dim
Definition: Vector.h:46
double kome::core::Vector::norm ( )

gets the norm of the vector

Returns
norm

Definition at line 58 of file Vector.cpp.

58  {
59  double n = 0.0;
60  for( unsigned int i = 0; i < m_dim; i++ ) {
61  n += ( m_array[ i ] * m_array[ i ] );
62  }
63 
64  n = sqrt( n );
65 
66  return n;
67 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
double & kome::core::Vector::operator() ( const unsigned int  index)

gets reference of value of specified element

Parameters
[in]indexindex
Returns
reference of value of specified element

Definition at line 111 of file Vector.cpp.

111  {
112  // check parameter
113  if( index >= m_dim ) {
114  throw FMT( "The specified element does not exist. [dimension=%d, index=%d]", m_dim, index );
115  }
116 
117  return m_array[ index ];
118 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
Vector kome::core::Vector::operator* ( const double  k)

scalar multiplication

Parameters
[in]kreal number to multiple
Returns
multiplication vector

Definition at line 187 of file Vector.cpp.

187  {
188  Vector tmp = *this;
189  tmp *= k;
190 
191  return tmp;
192 }
vector class
Definition: Vector.h:22
Vector & kome::core::Vector::operator*= ( const double  k)

scalar multiplication

Parameters
[in]kreal number to multiple
Returns
multiplication vector

Definition at line 151 of file Vector.cpp.

151  {
152  // multiplication
153  for( unsigned int i = 0; i < m_dim; i++ ) {
154  m_array[ i ] *= k;
155  }
156 
157  return *this;
158 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
Vector kome::core::Vector::operator+ ( const Vector v)

vector addition

Parameters
[in]vvector to add
Returns
addition vector

Definition at line 171 of file Vector.cpp.

171  {
172  Vector tmp = *this;
173  tmp += v;
174 
175  return tmp;
176 }
vector class
Definition: Vector.h:22
Vector & kome::core::Vector::operator+= ( const Vector v)

vector addition

Parameters
[in]vvector to add
Returns
addition vector

Definition at line 121 of file Vector.cpp.

121  {
122  // check size
123  if( v.m_dim != m_dim ) {
124  throw FMT( "Vector size is illegal." );
125  }
126 
127  // addition
128  for( unsigned int i = 0; i < m_dim; i++ ) {
129  m_array[ i ] += v.m_array[ i ];
130  }
131 
132  return *this;
133 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
Vector kome::core::Vector::operator- ( const Vector v)

vector subtraction

Parameters
[in]vvector to subtract
Returns
subtraction vector

Definition at line 179 of file Vector.cpp.

179  {
180  Vector tmp = *this;
181  tmp -= v;
182 
183  return tmp;
184 }
vector class
Definition: Vector.h:22
Vector & kome::core::Vector::operator-= ( const Vector v)

vector subtraction

Parameters
[in]vvector to subtract
Returns
subtraction vector

Definition at line 136 of file Vector.cpp.

136  {
137  // check size
138  if( v.m_dim != m_dim ) {
139  throw FMT( "Vector size is illegal." );
140  }
141 
142  // addition
143  for( unsigned int i = 0; i < m_dim; i++ ) {
144  m_array[ i ] -= v.m_array[ i ];
145  }
146 
147  return *this;
148 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
Vector kome::core::Vector::operator/ ( const double  k)

scalar division

Parameters
[in]kreal number to divide
Returns
division vector

Definition at line 195 of file Vector.cpp.

195  {
196  Vector tmp = *this;
197  tmp /= k;
198 
199  return tmp;
200 }
vector class
Definition: Vector.h:22
Vector & kome::core::Vector::operator/= ( const double  k)

scalar division

Returns
k real number to divide
division vector

Definition at line 161 of file Vector.cpp.

161  {
162  // division
163  for( unsigned int i = 0; i < m_dim; i++ ) {
164  m_array[ i ] /= k;
165  }
166 
167  return *this;
168 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
Vector kome::core::Vector::operator= ( const Vector v)

copy vector

Parameters
[in]vsource vector to be copied
Returns
copied vector

Definition at line 98 of file Vector.cpp.

98  {
99  if( v.m_dim != m_dim ) {
100  throw FMT( "Vector size is illegal." );
101  }
102 
103  if( m_array != NULL ) {
104  memcpy( m_array, v.m_array, sizeof( double ) * m_dim );
105  }
106 
107  return *this;
108 }
const unsigned int m_dim
Definition: Vector.h:46
double *const m_array
Definition: Vector.h:48
#define NULL
Definition: CoreMacros.h:18

Member Data Documentation

double* const kome::core::Vector::m_array
protected

value array

Definition at line 48 of file Vector.h.

const unsigned int kome::core::Vector::m_dim
protected

dimention size

Definition at line 46 of file Vector.h.


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