int_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 "../header/int_vector.h"
00022 
00023 int_vector::int_vector():
00024 int_list()
00025 {
00026   int_list.resize(0);
00027 }
00028 
00029 int_vector::int_vector(const int_vector &_V):
00030   int_list()
00031 {
00032   int_list.resize(_V.int_list.size());
00033   for(int k=0;k<int(int_list.size());int_list[k]=_V.int_list[k],k++);
00034 }
00035 int_vector::int_vector(const std::vector<int>& _V):
00036   int_list()
00037 {
00038   int_list.resize(_V.size());
00039   for(int k=0;k<int(int_list.size());int_list[k]=_V[k],k++);  
00040 }
00041 
00042 int_vector::~int_vector()
00043 {
00044   int_list.resize(0);
00045 }
00046 
00047 int int_vector::size() const
00048 {
00049   return int_list.size();
00050 }
00051 
00052 int int_vector::resize(int _size)
00053 {
00054   if(_size>=0)
00055     {
00056       int_list.resize(_size);
00057       return(0);
00058     }
00059   else
00060     {printf("error in resize in int_vector, size[%d] is not correct\n",_size);exit(-1);}
00061 
00062   return(-1);
00063 }
00064 
00065 int& int_vector::operator[](int k_vertex)
00066 {
00067   if(k_vertex<0 || k_vertex>=int(int_list.size()))
00068     {printf("Error in operator [] in int_vector, k_vertex [%d] is not correct because int_list.size()=[%d] \n",k_vertex,int_list.size());exit(-1);}
00069   return int_list[k_vertex];
00070 }  
00071 int int_vector::operator[](int k_vertex) const
00072 {
00073   if(k_vertex<0 || k_vertex>=int(int_list.size()))
00074     {printf("Error in operator [] in int_vector, k_vertex [%d] is not correct because int_list.size()=[%d] \n",k_vertex,int_list.size());exit(-1);}
00075   return int_list[k_vertex];
00076 }  
00077 
00078 
00079 int_vector& int_vector::operator=(const int_vector& _V)
00080 {
00081   int_list.resize(_V.int_list.size());
00082   for(int k=0;k<int(_V.int_list.size());k++)
00083     int_list[k] = _V.int_list[k];
00084   return *this;
00085 }
00086 
00087 
00088 int int_vector::add_unique(int k_index)
00089 {
00090   int k=0;
00091   for(k=0;k<int(int_list.size());k++)//go through the entire list
00092     if(int_list[k]==k_index)//if already exists
00093       return(-1);
00094 
00095   int_list.push_back(k_index);//in the other case, add the vertex number
00096   return 0;
00097 }
00098 
00099 int int_vector::add(int k_vertex)
00100 {
00101   int_list.push_back(k_vertex);
00102   return(0);
00103 }
00104 
00105 int int_vector::add(const std::vector <int>& _int_list)
00106 {
00107   int k=0;
00108   for(k=0;k<int(_int_list.size());k++)
00109     add(_int_list[k]);
00110   return 0;
00111 }
00112 
00113 int int_vector::exists(int index_to_find) const
00114 {
00115   int k=0;
00116   int N=size();
00117   for(k=0;k<N;k++)
00118     if(index_to_find==int_list[k])
00119       return k;
00120   return -1;
00121 }
00122 
00123 bool operator==(const int_vector& cont_1,const int_vector& cont_2)
00124 {
00125   if(cont_1.size()!=cont_2.size())
00126     return 0;
00127   for(int k=0;k<cont_1.size();k++)
00128     if(cont_1[k]!=cont_2[k])
00129       return 0;
00130   return 1;
00131 }
00132 bool operator!=(const int_vector& cont_1,const int_vector& cont_2)
00133 {
00134   if(cont_1==cont_2)
00135     return 0;
00136   return 1;
00137 }

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