double_vector.cpp

Go to the documentation of this file.
00001 /*
00002 **    Mesh Converter
00003 **    Copyright (C) 2008  Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 
00021 #include <double_vector.h>
00022 
00023 double_vector::double_vector():
00024 double_list()
00025 {
00026   double_list.resize(0);
00027 }
00028 
00029 double_vector::double_vector(const double_vector &_V):
00030   double_list()
00031 {
00032   double_list.resize(_V.double_list.size());
00033   for(int k=0;k<int(double_list.size());double_list[k]=_V.double_list[k],k++);
00034 }
00035 
00036 double_vector::~double_vector()
00037 {
00038   double_list.resize(0);
00039 }
00040 
00041 int double_vector::size() const
00042 {
00043   return double_list.size();
00044 }
00045 
00046 int double_vector::resize(int _size)
00047 {
00048   if(_size>=0)
00049     {
00050       double_list.resize(_size);
00051       return(0);
00052     }
00053   else
00054     {printf("error in resize in double_vector, size[%d] is not correct\n",_size);exit(-1);}
00055 
00056   return(-1);
00057 }
00058 
00059 double& double_vector::operator[](int k_vertex)
00060 {
00061   if(k_vertex<0 || k_vertex>=int(double_list.size()))
00062     {printf("Error in operator [] in double_vector, k_vertex [%d] is not correct because double_list.size()=[%d] \n",k_vertex,double_list.size());exit(-1);}
00063   return double_list[k_vertex];
00064 }  
00065 double double_vector::operator[](int k_vertex) const
00066 {
00067   if(k_vertex<0 || k_vertex>=int(double_list.size()))
00068     {printf("Error in operator [] in double_vector, k_vertex [%d] is not correct because double_list.size()=[%d] \n",k_vertex,double_list.size());exit(-1);}
00069   return double_list[k_vertex];
00070 }  
00071 
00072 
00073 double_vector& double_vector::operator=(const double_vector& _V)
00074 {
00075   double_list.resize(_V.double_list.size());
00076   for(int k=0;k<int(_V.double_list.size());k++)
00077     double_list[k] = _V.double_list[k];
00078   return *this;
00079 }
00080 
00081 
00082 int double_vector::add(double value)
00083 {
00084   double_list.push_back(value);
00085   return(0);
00086 }
00087 
00088 int double_vector::add(std::vector <double>& _double_list)
00089 {
00090   int k=0;
00091   for(k=0;k<int(_double_list.size());k++)
00092     add(_double_list[k]);
00093   return 0;
00094 }
00095 
00096 bool operator==(const double_vector& cont_1,const double_vector& cont_2)
00097 {
00098   double epsilon=0.00001;
00099   if(cont_1.size()!=cont_2.size())
00100     return 0;
00101   for(int k=0;k<int(cont_1.size());k++)
00102     if(fabs(cont_1[k]-cont_2[k])>epsilon)
00103       return 0;
00104   return 1;
00105 }
00106 bool operator!=(const double_vector& cont_1,const double_vector& cont_2)
00107 {
00108   if(cont_1==cont_2)
00109     return 0;
00110   return 1;
00111 }

Generated on Mon Mar 30 16:55:54 2009 by  doxygen 1.5.6