MC_int_vector.hpp

Go to the documentation of this file.
00001 /*
00002 **    Mesh Converter
00003 **    Copyright (C) 2009  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 #ifndef MC_INT_VECTOR_H_
00021 #define MC_INT_VECTOR_H_
00022 
00023 #include <stdlib.h>
00024 #include <vector>
00025 #include <map>
00026 #include <set>
00027 #include <list>
00028 #include <iostream>
00029 
00030 #include <MC_curve.hpp>
00031 #include <MC_v3d.hpp>
00032 
00033 namespace mesh_conv
00034 {
00035 
00036     class MC_int_pair;
00037     class MC_int_pair_less;
00038 
00039     // helper class to compare struct
00040     class comparator_less_int_int
00041     {
00042          public:
00043         bool operator()(const std::pair<int,int> a,const std::pair <int,int> b) const
00044         {return (a.first<b.first);}
00045     };
00046 
00047 
00049 
00051   class MC_int_vector
00052   {
00053 
00054   public:
00055 
00056     //************************************************//
00057     //************************************************//
00058     //CONSTRUCTORS
00059     //************************************************//
00060     //************************************************//
00061     
00063     MC_int_vector();
00065     MC_int_vector(const int& u0);
00067     MC_int_vector(const int& u0,const int& u1);
00069     MC_int_vector(const int& u0,const int& u1,const int& u2);
00071     MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3);
00073     MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3,const int& u4);
00075     MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3,const int& u4,const int& u5);
00080     MC_int_vector(const std::string& in,const std::string& separator=" ");
00081 
00083     MC_int_vector(const std::set <int>& vec);
00085     MC_int_vector(const std::set <unsigned int>& vec);
00086 
00091     MC_int_vector(const std::map <int,int> &vec);
00093     MC_int_vector(const std::list <int> &vec);
00095     MC_int_vector(const std::vector <int> &vec);
00097     MC_int_vector(const MC_int_vector& vec);
00098 
00099     //************************************************//
00100     //************************************************//
00101     //Asserts
00102     //************************************************//
00103     //************************************************//
00104 
00108     void assert_bounds(const int& u) const;
00109 
00110 
00111 
00112     //************************************************//
00113     //************************************************//
00114     //change type
00115     //************************************************//
00116     //************************************************//
00117 
00121     std::vector <int>& get_vector();
00127     const std::vector <int>& to_vector() const;
00128 
00132     std::set <int> to_set() const;
00136     std::map <int,int> to_map() const;
00138     std::list <int> to_list() const;
00139 
00140     MC_v3d to_v3d() const;
00141     
00142 
00143     //************************************************//
00144     //************************************************//
00145     //Initialize value
00146     //************************************************//
00147     //************************************************//
00148 
00150     static MC_int_vector zeros(const int& new_size);
00151 
00157     static MC_int_vector linspace(const int& begin,const int& end,const double& iteration=1);
00158 
00159     //************************************************//
00160     //************************************************//
00161     //manipulate
00162     //************************************************//
00163     //************************************************//
00164 
00166     void clear();
00167 
00171     MC_int_vector& resize(const int& new_size);
00172 
00176     MC_int_vector& add(const int& val);
00180     friend MC_int_vector operator<<(const MC_int_vector& vec,const int& value);
00181 
00182 
00186     MC_int_vector& add(const MC_int_vector& val);
00190     friend MC_int_vector operator<<(const MC_int_vector& vec,const MC_int_vector& to_add);
00191 
00195     MC_int_vector& set(const int& k_index,const int& new_value);
00203     MC_int_vector& set(const MC_int_vector& k_index,const MC_int_vector& new_value);
00204 
00210     std::pair <MC_int_vector,int> delete_index(const int& index_to_delete) const;    
00216     std::pair <MC_int_vector,MC_int_vector> delete_index(const MC_int_vector& index_to_delete) const;
00217     
00222     std::pair <MC_int_vector,MC_int_vector> sort() const;
00223 
00225     MC_int_vector mapping(const std::map<int,int> map_to_apply) const;
00226 
00228     MC_int_vector inverted() const;
00229 
00230 //    /** \brief inverse a mapping <index_0->index_1> from a map (the mapping must be a bijection) */
00231 //    static std::map <int,int> reverse_index_mapping(const std::map<int,int>& input_mapping);
00232 
00233     //************************************************//
00234     //************************************************//
00235     //Build
00236     //************************************************//
00237     //************************************************//
00238 
00240     static std::list <MC_int_vector> connected_component(const std::set<MC_int_pair,MC_int_pair_less>& pair_set);
00241 
00242 
00243     //************************************************//
00244     //************************************************//
00245     //Informations
00246     //************************************************//
00247     //************************************************//
00248 
00250     int size() const;
00251 
00255     int find(const int& to_find) const;
00256 
00257     //************************************************//
00258     //************************************************//
00259     //Math operator
00260     //************************************************//
00261     //************************************************//
00262 
00266     MC_int_vector operator-() const;
00267 
00271     friend MC_int_vector operator+(const MC_int_vector& vec,const int& to_add);
00275     friend MC_int_vector operator-(const MC_int_vector& vec,const int& to_sub);
00279     friend MC_int_vector operator*(const MC_int_vector& vec,const int& to_mult);
00283     friend MC_int_vector operator/(const MC_int_vector& vec,const int& to_subdiv);
00284 
00285 
00286 
00292     friend MC_int_vector operator+(const MC_int_vector& vec,const MC_int_vector& to_add);
00298     friend MC_int_vector operator-(const MC_int_vector& vec,const MC_int_vector& to_sub);
00304     friend MC_int_vector operator*(const MC_int_vector& vec,const MC_int_vector& to_mult);
00310     friend MC_int_vector operator/(const MC_int_vector& vec,const MC_int_vector& to_subdiv);
00311 
00312 
00313 
00315     MC_int_vector& operator+=(const int& to_add);
00317     MC_int_vector& operator-=(const int& to_sub);
00319     MC_int_vector& operator*=(const int& to_mult);
00321     MC_int_vector& operator/=(const int& to_subdiv);
00322 
00327     MC_int_vector& operator+=(const MC_int_vector& to_add);
00332     MC_int_vector& operator-=(const MC_int_vector& to_sub);
00337     MC_int_vector& operator*=(const MC_int_vector& to_mult);
00342     MC_int_vector& operator/=(const MC_int_vector& to_subdiv);
00343 
00344 
00348     friend MC_int_vector operator<(const MC_int_vector& vec,const int& val);
00352     friend MC_int_vector operator<=(const MC_int_vector& vec,const int& val);
00356     friend MC_int_vector operator>(const MC_int_vector& vec,const int& val);
00360     friend MC_int_vector operator>=(const MC_int_vector& vec,const int& val);
00364     friend MC_int_vector operator==(const MC_int_vector& vec,const int& val);
00365 
00366 
00367 
00371     friend MC_int_vector operator<(const int& val,const MC_int_vector& vec);
00375     friend MC_int_vector operator<=(const int& val,const MC_int_vector& vec);
00379     friend MC_int_vector operator>(const int& val,const MC_int_vector& vec);
00383     friend MC_int_vector operator>=(const int& val,const MC_int_vector& vec);
00387     friend MC_int_vector operator==(const int& val,const MC_int_vector& vec);
00388 
00389 
00390 
00391     //************************************************//
00392     //************************************************//
00393     //Get value
00394     //************************************************//
00395     //************************************************//
00396 
00398     const int& operator()(const int& index) const ;
00400     int& operator()(const int& index) ;
00402     const int& operator[](const int& index) const ;
00404     int& operator[](const int& index) ;
00405 
00407     MC_int_vector operator()(const MC_int_vector& index) const;
00409     MC_int_vector operator[](const MC_int_vector& index) const;
00410 
00411 
00413     const int& first() const;
00415     int& first();
00417     const int& last() const;
00419     int& last();
00420 
00422     MC_int_vector& erase_last();
00423 
00424 
00426     const int* pointer() const;
00427 
00428     //************************************************//
00429     //************************************************//
00430     //OUTPUT
00431     //************************************************//
00432     //************************************************//
00433     
00435     friend std::ostream& operator<<(std::ostream& output,const mesh_conv::MC_int_vector& in);
00436 
00441     friend mesh_conv::MC_int_vector& operator>>(std::istream& input,mesh_conv::MC_int_vector& vec);
00442 
00443 
00444   private:
00445     
00447     std::vector <int> int_list;
00448 
00449   };
00450 
00451 
00452 
00453 
00454 }
00455 
00456 #endif

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