MC_int_vector_vector.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include <MC_int_vector_vector.hpp>
00004 
00005 
00006 namespace mesh_conv
00007 {
00008 
00009     MC_int_vector_vector::MC_int_vector_vector(){}
00010     MC_int_vector_vector::MC_int_vector_vector(const MC_int_vector& v0){int_vec_list.push_back(v0);}
00011     MC_int_vector_vector::MC_int_vector_vector(const MC_int_vector& v0,const MC_int_vector& v1)
00012     {int_vec_list.push_back(v0);int_vec_list.push_back(v1);}
00013     MC_int_vector_vector::MC_int_vector_vector(const MC_int_vector& v0,const MC_int_vector& v1,const MC_int_vector& v2)
00014     {int_vec_list.push_back(v0);int_vec_list.push_back(v1);int_vec_list.push_back(v2);}
00015     MC_int_vector_vector::MC_int_vector_vector(const MC_int_vector& v0,const MC_int_vector& v1,const MC_int_vector& v2,const MC_int_vector& v3)
00016     {int_vec_list.push_back(v0);int_vec_list.push_back(v1);int_vec_list.push_back(v2);int_vec_list.push_back(v3);}
00017 
00018     inline void MC_int_vector_vector::assert_bounds(const int& u) const
00019     {
00020         if(u<0 || u>=int(int_vec_list.size()))
00021         {std::cout<<"Assert mesh_conv::MC_int_vector_vector::assert_bounds("<<u<<") failed, because size="<<int_vec_list.size()<<std::endl;}
00022     }
00023 
00024     const MC_int_vector& MC_int_vector_vector::operator()(const int& index) const
00025     {assert_bounds(index);return int_vec_list[index];}
00026     MC_int_vector& MC_int_vector_vector::operator()(const int& index)
00027     {assert_bounds(index);return int_vec_list[index];}
00028     const MC_int_vector& MC_int_vector_vector::operator[](const int& index) const
00029     {assert_bounds(index);return int_vec_list[index];}
00030     MC_int_vector& MC_int_vector_vector::operator[](const int& index)
00031     {assert_bounds(index);return int_vec_list[index];}
00032 
00033     int MC_int_vector_vector::size() const
00034     {return int_vec_list.size();}
00035 
00036 
00037     void MC_int_vector_vector::clear(){int_vec_list.clear();}
00038     MC_int_vector_vector& MC_int_vector_vector::resize(const int& new_size)
00039     {
00040         int N=int_vec_list.size();
00041         if(N==new_size) //same size
00042             return *this;
00043 
00044         if(new_size<0)
00045         {std::cout<<"Error in MC_int_vector_vector::resize("<<new_size<<") new size must be >0"<<std::endl;exit(-1);}
00046 
00047         int_vec_list.resize(new_size);
00048         return *this;
00049     }
00050     MC_int_vector_vector& MC_int_vector_vector::add(const MC_int_vector& val){int_vec_list.push_back(val);return *this;}
00051     MC_int_vector_vector operator<<(const MC_int_vector_vector& vec,const MC_int_vector& value)
00052     {return MC_int_vector_vector(vec).add(value);}
00053     MC_int_vector_vector& MC_int_vector_vector::add(const MC_int_vector_vector& val)
00054     {
00055         int N=val.size();
00056         for(int k=0;k<N;++k)
00057             int_vec_list.push_back(val[k]);
00058         return *this;
00059     }
00060     MC_int_vector_vector operator<<(const MC_int_vector_vector& vec,const MC_int_vector_vector& to_add)
00061     {return MC_int_vector_vector(vec).add(to_add);}
00062     MC_int_vector_vector& MC_int_vector_vector::set(const int& k_index,const MC_int_vector& new_value)
00063     {
00064         if(k_index<0)
00065         {std::cout<<"Error in MC_int_vector_vector::set("<<k_index<<","<<new_value<<"), index must be >0"<<std::endl;exit(-1);}
00066         if(k_index>=size())
00067             int_vec_list.resize(k_index+1);
00068         int_vec_list[k_index]=new_value;
00069         return *this;
00070     }
00071     MC_int_vector_vector& MC_int_vector_vector::set(const MC_int_vector& k_index,const MC_int_vector_vector& new_value)
00072     {
00073         MC_int_vector_vector v_new_value=new_value;
00074         if(new_value.size()!=1 && new_value.size()!=k_index.size())
00075         {std::cout<<"Error in MC_int_vector_vector::set(MC_int_vector,MC_int_vector_vector), size are not correct: "<<k_index.size()<<","<<new_value.size()<<std::endl;exit(-1);}
00076         if(new_value.size()==1)
00077             v_new_value=MC_int_vector_vector::repeat(new_value.first(),k_index.size());
00078         
00079         
00080         int N=v_new_value.size();
00081         for(int k=0;k<N;k++)
00082             set(k_index[k],v_new_value[k]);
00083         return *this;
00084     }
00085     std::pair <MC_int_vector_vector,MC_int_vector> MC_int_vector_vector::delete_index(const int& index_to_delete) const
00086     {
00087         if(index_to_delete<0 || index_to_delete>=size())
00088         {std::cout<<"Error in MC_int_vector_vector::delete("<<index_to_delete<<", when size="<<size()<<std::endl;exit(-1);}
00089         MC_int_vector_vector new_vec;
00090         int N=size();
00091         for(int k=0;k<N;++k)
00092             if(k!=index_to_delete)
00093                 new_vec.add(int_vec_list[k]);
00094         return std::pair <MC_int_vector_vector,MC_int_vector>(new_vec,int_vec_list[index_to_delete]);
00095     }
00096     std::pair <MC_int_vector_vector,MC_int_vector_vector> MC_int_vector_vector::delete_index(const MC_int_vector& index_to_delete) const
00097     {
00098         std::set <int> set_index=index_to_delete.to_set();
00099         MC_int_vector_vector new_vec;
00100         MC_int_vector_vector deleted_vec;
00101         int N=size();
00102         for(int k=0;k<N;k++)
00103         {
00104             if(set_index.find(k)==set_index.end())
00105                 new_vec.add(int_vec_list[k]);
00106             else
00107                 deleted_vec.add(int_vec_list[k]);
00108         }
00109         return std::pair <MC_int_vector_vector,MC_int_vector_vector> (new_vec,deleted_vec);
00110     }
00111 
00112     MC_int_vector_vector MC_int_vector_vector::repeat(const MC_int_vector& input,const int& N_repeat)
00113     {
00114         if(N_repeat<0)
00115         {std::cout<<"Error in MC_int_vector_vector::repeat(MC_int_vector,"<<N_repeat<<"), repeat number must be >0"<<std::endl;exit(-1);}
00116 
00117         MC_int_vector_vector vec(input);
00118         for(int k=1;k<N_repeat;++k)
00119             vec.add(input);
00120         return vec;
00121     }
00122 
00123     const MC_int_vector& MC_int_vector_vector::first() const
00124     {
00125         if(size()>0)
00126             return int_vec_list[0];
00127         else
00128         {
00129             std::cout<<"Error, call MC_int_vector_vector::first() with size=0"<<std::endl;exit(-1);
00130             exit(-1);
00131         }
00132     }
00133     MC_int_vector& MC_int_vector_vector::first()
00134     {
00135         if(size()>0)
00136             return int_vec_list[0];
00137         else
00138         {
00139             std::cout<<"Error, call MC_int_vector_vector::first() with size=0"<<std::endl;exit(-1);
00140             exit(-1);
00141         }
00142     }
00143     const MC_int_vector& MC_int_vector_vector::last() const
00144     {
00145         if(size()>0)
00146             return int_vec_list[size()-1];
00147         else
00148         {std::cout<<"Error, call MC_int_vector::last() with size=0"<<std::endl;exit(-1);}
00149     }
00150     MC_int_vector& MC_int_vector_vector::last()
00151     {
00152         if(size()>0)
00153             return int_vec_list[size()-1];
00154         else
00155         {std::cout<<"Error, call MC_int_vector::last() with size=0"<<std::endl;exit(-1);}
00156     }
00157 
00158     std::ostream& operator<<(std::ostream& stream,const MC_int_vector_vector& input)
00159     {
00160         int N=input.size();
00161         for(int k=0;k<N-1;k++)
00162             stream<<"("<<input[k]<<"); ";
00163         if(N>0)
00164             stream<<"("<<input[N-1]<<")";
00165         return stream;
00166     }
00167     MC_int_vector_vector operator+(const MC_int_vector_vector& vec,const int& to_add)
00168     {
00169 
00170         int N=vec.size();
00171         MC_int_vector_vector res;res.resize(N);
00172         for(int k=0;k<N;++k)
00173             res[k]=vec[k]+to_add;
00174         return res;
00175     }
00176     MC_int_vector_vector operator-(const MC_int_vector_vector& vec,const int& to_add)
00177     {
00178         int N=vec.size();
00179         MC_int_vector_vector res(N);res.resize(N);
00180         for(int k=0;k<N;++k)
00181             res[k]=vec[k]-to_add;
00182         return res;
00183     }
00184 
00185     MC_int_vector_vector::MC_int_vector_vector(const std::list <MC_int_vector>& vec)
00186     {
00187         for(std::list <MC_int_vector> :: const_iterator it=vec.begin();it!=vec.end();++it)
00188             add(*it);
00189     }
00190 
00191     const MC_int_vector* MC_int_vector_vector::pointer() const{return &int_vec_list[0];}
00192     MC_int_vector* MC_int_vector_vector::pointer_unprotected(){return &int_vec_list[0];}
00193 
00194     MC_int_vector_vector MC_int_vector_vector::empty(const int& N)
00195     {MC_int_vector_vector vec;vec.resize(N);return vec;}
00196     MC_int_vector_vector MC_int_vector_vector::operator()(const MC_int_vector& index) const
00197     {
00198         int N=index.size();
00199         MC_int_vector_vector vec=MC_int_vector_vector::empty(N);
00200 
00201         int N_current=size();
00202         for(int k=0;k<N;++k)
00203         {
00204             int u=index[k];
00205             if(u<0 || u>=N_current)
00206             {std::cout<<"Error in MC_int_vector_vector::operator()(MC_int_vector ), at position k="<<k<<"/"<<N<<", index "<<u<<"is not correct for size "<<N_current<<std::endl;exit(-1);}
00207             vec[k]=int_vec_list[u];
00208         }
00209         return vec;
00210     }
00211 
00212 
00213 
00214 
00215 }

Generated on Sun Apr 18 20:24:47 2010 by  doxygen 1.6.1