#include <vecdouble.h>
Public Member Functions | |
VecDouble () | |
VecDouble (const VecDouble &v) | |
VecDouble (unsigned n) | |
VecDouble (const Point< 3 > &p) | |
VecDouble (const Point< 2 > &p) | |
VecDouble (const Point< 1 > &p) | |
VecDouble (const std::vector< double > &p) | |
bool | is_owner () |
void | swap (VecDouble &v) |
void | reinit (const unsigned int N, const bool fast=false) |
virtual void | reinit (const VecDouble &V, const bool fast=false) |
VecDouble & | operator= (const VecDouble &v) |
VecDouble & | operator= (const Vector< double > &v) |
VecDouble & | operator= (const BlockVector< double > &v) |
void | operator= (double dd) |
void | copyRow (unsigned row, Matrix &M) |
void | getMinMaxValues (double *min, double *max) const |
void | set (double d1, double d2) |
void | setRef (double *p, unsigned size) |
void | setRef (Vector< double > &v) |
virtual | ~VecDouble () |
void | term_mult (const VecDouble &v1, const VecDouble &v2) |
Protected Attributes | |
bool | m_owner |
Friends | |
class | ArrayOfVecDouble |
class | VecIncBC |
VecDouble This class is an extension of the dealII Vector<double> It has a minor difference though. In the usual way the Vector always allocate and deallocate its own memory. Although this is always the safest way, sometimes making the vector to point to someone memory is pretty pretty attractive for efficiency purposes. The old duel between efficiency and manutenability of code.
So this extension of the Vector class, allows the Vector to switch to reference mode. This mode is triggered when the user call setRef method. This is dangerous specially if the user passes a place in memory that does not correspond to the vector size. Segmentation fault may result from that or worse, set a location in memory that belongs to another variable. That why for security measures, once the vector enters this mode, it is not possible anymore to cast it to its base class dealII or even reinitialize the vector. In other words, once the object enters reference mode it cannot own any memory again in its entire lifetime. Also the method setRef is private and can be accessed only by its friend classes. This is done to discourage the use of such method by other programmers. Shallow copy might result in some very nasty errors and sometimes bugs that consumes months of development. So shallow copy can be used here only for some very few and crucial parts of the code and only there.
Right now the only class that is a friend is ArrayOfVecDouble class
Definition at line 38 of file vecdouble.h.
VecDouble::VecDouble | ( | ) |
Definition at line 163 of file vecdouble.cpp.
00164 { 00165 m_owner=true; 00166 }
VecDouble::VecDouble | ( | const VecDouble & | v | ) |
Definition at line 17 of file vecdouble.cpp.
00018 :Vector<double>(v) 00019 { 00020 m_owner=true; 00021 }
VecDouble::VecDouble | ( | unsigned | n | ) |
Definition at line 60 of file vecdouble.cpp.
00061 :Vector<double>(n) 00062 { 00063 m_owner=true; 00064 }
VecDouble::VecDouble | ( | const Point< 3 > & | p | ) |
Definition at line 35 of file vecdouble.cpp.
VecDouble::VecDouble | ( | const Point< 2 > & | p | ) |
Definition at line 42 of file vecdouble.cpp.
VecDouble::VecDouble | ( | const Point< 1 > & | p | ) |
Definition at line 49 of file vecdouble.cpp.
VecDouble::VecDouble | ( | const std::vector< double > & | p | ) |
Definition at line 23 of file vecdouble.cpp.
VecDouble::~VecDouble | ( | ) | [virtual] |
Definition at line 8 of file vecdouble.cpp.
00009 { 00010 if (!m_owner) 00011 { 00012 val=0; 00013 max_vec_size = vec_size = 0; 00014 } 00015 }
void VecDouble::copyRow | ( | unsigned | row, | |
Matrix & | M | |||
) |
Definition at line 210 of file vecdouble.cpp.
void VecDouble::getMinMaxValues | ( | double * | min, | |
double * | max | |||
) | const |
Definition at line 180 of file vecdouble.cpp.
bool VecDouble::is_owner | ( | ) | [inline] |
Definition at line 57 of file vecdouble.h.
00057 {return m_owner;}
void VecDouble::operator= | ( | double | dd | ) |
Definition at line 156 of file vecdouble.cpp.
VecDouble & VecDouble::operator= | ( | const BlockVector< double > & | v | ) |
Definition at line 101 of file vecdouble.cpp.
00102 { 00103 /* 00104 This method is valid only if the vector owns its memory 00105 or in the case that both vectors have equal size 00106 */ 00107 assert(m_owner || (v.size() == size()) ); 00108 Vector<double>::operator=(v); 00109 return *this; 00110 }
VecDouble & VecDouble::operator= | ( | const Vector< double > & | v | ) |
Definition at line 113 of file vecdouble.cpp.
00114 { 00115 assert(m_owner || (v.size() == size()) ); 00116 Vector<double>::operator=(v); 00117 return *this; 00118 }
Definition at line 90 of file vecdouble.cpp.
00091 { 00092 /* 00093 This method is valid only if the vector owns its memory 00094 or in the case that both vectors have equal size 00095 */ 00096 assert(m_owner || (v.size() == size()) ); 00097 Vector< double >::operator=(v); 00098 return *this; 00099 }
void VecDouble::reinit | ( | const VecDouble & | V, | |
const bool | fast = false | |||
) | [virtual] |
Definition at line 78 of file vecdouble.cpp.
00079 { 00080 reinit(V.size(),fast); 00081 }
void VecDouble::reinit | ( | const unsigned int | N, | |
const bool | fast = false | |||
) |
Definition at line 68 of file vecdouble.cpp.
00069 { 00070 if (!m_owner) 00071 { 00072 throw new Exception("VecDouble::reinit Attemp to reinit a vector that does not own its memory\n"); 00073 } 00074 Vector<double>::reinit(N,fast); 00075 }
void VecDouble::set | ( | double | d1, | |
double | d2 | |||
) |
Definition at line 221 of file vecdouble.cpp.
00222 { 00223 reinit(2); 00224 operator()(0)=d1; 00225 operator()(1)=d2; 00226 }
void VecDouble::setRef | ( | Vector< double > & | v | ) |
Definition at line 146 of file vecdouble.cpp.
00147 { 00148 setRef(&(v(0)),v.size()); 00149 }
void VecDouble::setRef | ( | double * | p, | |
unsigned | size | |||
) |
Make the vector to point to someone else memory. Once this function is called, the object is forbidden to allocate memory by its own during its hole like.
p | ||
size |
Reimplemented in VecDoubleRef.
Definition at line 129 of file vecdouble.cpp.
void VecDouble::swap | ( | VecDouble & | v | ) |
Definition at line 83 of file vecdouble.cpp.
00084 { 00085 Vector<double>::swap(v); 00086 std::swap(m_owner,v.m_owner); 00087 }
Definition at line 195 of file vecdouble.cpp.
friend class ArrayOfVecDouble [friend] |
Definition at line 40 of file vecdouble.h.
friend class VecIncBC [friend] |
Definition at line 41 of file vecdouble.h.
bool VecDouble::m_owner [protected] |
Definition at line 46 of file vecdouble.h.