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 
00031 namespace mesh_conv
00032 {
00033 
00034 
00035     // helper class to compare struct
00036     class comparator_less_int_int
00037     {
00038          public:
00039         bool operator()(const std::pair<int,int> a,const std::pair <int,int> b) const
00040         {return (a.first<b.first);}
00041     };
00042 
00043 
00045 
00047   class MC_int_vector
00048   {
00049 
00050   public:
00051 
00052     //************************************************//
00053     //************************************************//
00054     //CONSTRUCTORS
00055     //************************************************//
00056     //************************************************//
00057     
00059     MC_int_vector();
00061     MC_int_vector(const int& u0);
00063     MC_int_vector(const int& u0,const int& u1);
00065     MC_int_vector(const int& u0,const int& u1,const int& u2);
00067     MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3);
00069     MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3,const int& u4);
00071     MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3,const int& u4,const int& u5);
00076     MC_int_vector(const std::string& in,const std::string& separator=" ");
00077 
00079     MC_int_vector(const std::set <int>& vec);
00084     MC_int_vector(const std::map <int,int> &vec);
00086     MC_int_vector(const std::list <int> &vec);
00088     MC_int_vector(const std::vector <int> &vec);
00090     MC_int_vector(const MC_int_vector& vec);
00091 
00092     //************************************************//
00093     //************************************************//
00094     //Asserts
00095     //************************************************//
00096     //************************************************//
00097 
00101     void assert_bounds(const int& u) const;
00102 
00103 
00104 
00105     //************************************************//
00106     //************************************************//
00107     //change type
00108     //************************************************//
00109     //************************************************//
00110 
00114     std::vector <int>& get_vector();
00120     const std::vector <int>& to_vector() const;
00121 
00125     std::set <int> to_set() const;
00129     std::map <int,int> to_map() const;
00131     std::list <int> to_list() const;
00132 
00133     
00134 
00135     //************************************************//
00136     //************************************************//
00137     //Initialize value
00138     //************************************************//
00139     //************************************************//
00140 
00142     static MC_int_vector zeros(const int& new_size);
00143 
00149     static MC_int_vector linspace(const int& begin,const int& end,const double& iteration=1);
00150 
00151     //************************************************//
00152     //************************************************//
00153     //manipulate
00154     //************************************************//
00155     //************************************************//
00156 
00158     void clear();
00159 
00163     MC_int_vector& resize(const int& new_size);
00164 
00168     MC_int_vector& add(const int& val);
00172     friend MC_int_vector operator<<(const MC_int_vector& vec,const int& value);
00173 
00174 
00178     MC_int_vector& add(const MC_int_vector& val);
00182     friend MC_int_vector operator<<(const MC_int_vector& vec,const MC_int_vector& to_add);
00183 
00187     MC_int_vector& set(const int& k_index,const int& new_value);
00195     MC_int_vector& set(const MC_int_vector& k_index,const MC_int_vector& new_value);
00196 
00202     std::pair <MC_int_vector,int> delete_index(const int& index_to_delete) const;    
00208     std::pair <MC_int_vector,MC_int_vector> delete_index(const MC_int_vector& index_to_delete) const;
00209     
00214     std::pair <MC_int_vector,MC_int_vector> sort() const;
00215 
00217     MC_int_vector mapping(const std::map<int,int> map_to_apply) const;
00218 
00219 //    /** \brief inverse a mapping <index_0->index_1> from a map (the mapping must be a bijection) */
00220 //    static std::map <int,int> reverse_index_mapping(const std::map<int,int>& input_mapping);
00221 
00222     //************************************************//
00223     //************************************************//
00224     //Build
00225     //************************************************//
00226     //************************************************//
00227 
00228 
00229 
00230     //************************************************//
00231     //************************************************//
00232     //Informations
00233     //************************************************//
00234     //************************************************//
00235 
00237     int size() const;
00238 
00242     int find(const int& to_find) const;
00243 
00244     //************************************************//
00245     //************************************************//
00246     //Math operator
00247     //************************************************//
00248     //************************************************//
00249 
00253     MC_int_vector operator-() const;
00254 
00258     friend MC_int_vector operator+(const MC_int_vector& vec,const int& to_add);
00262     friend MC_int_vector operator-(const MC_int_vector& vec,const int& to_sub);
00266     friend MC_int_vector operator*(const MC_int_vector& vec,const int& to_mult);
00270     friend MC_int_vector operator/(const MC_int_vector& vec,const int& to_subdiv);
00271 
00272 
00273 
00279     friend MC_int_vector operator+(const MC_int_vector& vec,const MC_int_vector& to_add);
00285     friend MC_int_vector operator-(const MC_int_vector& vec,const MC_int_vector& to_sub);
00291     friend MC_int_vector operator*(const MC_int_vector& vec,const MC_int_vector& to_mult);
00297     friend MC_int_vector operator/(const MC_int_vector& vec,const MC_int_vector& to_subdiv);
00298 
00299 
00300 
00302     MC_int_vector& operator+=(const int& to_add);
00304     MC_int_vector& operator-=(const int& to_sub);
00306     MC_int_vector& operator*=(const int& to_mult);
00308     MC_int_vector& operator/=(const int& to_subdiv);
00309 
00314     MC_int_vector& operator+=(const MC_int_vector& to_add);
00319     MC_int_vector& operator-=(const MC_int_vector& to_sub);
00324     MC_int_vector& operator*=(const MC_int_vector& to_mult);
00329     MC_int_vector& operator/=(const MC_int_vector& to_subdiv);
00330 
00331 
00335     friend MC_int_vector operator<(const MC_int_vector& vec,const int& val);
00339     friend MC_int_vector operator<=(const MC_int_vector& vec,const int& val);
00343     friend MC_int_vector operator>(const MC_int_vector& vec,const int& val);
00347     friend MC_int_vector operator>=(const MC_int_vector& vec,const int& val);
00351     friend MC_int_vector operator==(const MC_int_vector& vec,const int& val);
00352 
00353 
00354 
00358     friend MC_int_vector operator<(const int& val,const MC_int_vector& vec);
00362     friend MC_int_vector operator<=(const int& val,const MC_int_vector& vec);
00366     friend MC_int_vector operator>(const int& val,const MC_int_vector& vec);
00370     friend MC_int_vector operator>=(const int& val,const MC_int_vector& vec);
00374     friend MC_int_vector operator==(const int& val,const MC_int_vector& vec);
00375 
00376 
00377 
00378     //************************************************//
00379     //************************************************//
00380     //Get value
00381     //************************************************//
00382     //************************************************//
00383 
00385     const int& operator()(const int& index) const ;
00387     int& operator()(const int& index) ;
00389     const int& operator[](const int& index) const ;
00391     int& operator[](const int& index) ;
00392 
00394     MC_int_vector operator()(const MC_int_vector& index) const;
00396     MC_int_vector operator[](const MC_int_vector& index) const;
00397 
00398 
00400     const int& first() const;
00402     int& first();
00404     const int& last() const;
00406     int& last();
00407 
00409     MC_int_vector& erase_last();
00410 
00411 
00413     const int* pointer() const;
00414 
00415     //************************************************//
00416     //************************************************//
00417     //OUTPUT
00418     //************************************************//
00419     //************************************************//
00420     
00422     friend std::ostream& operator<<(std::ostream& output,const mesh_conv::MC_int_vector& in);
00423 
00428     friend mesh_conv::MC_int_vector& operator>>(std::istream& input,mesh_conv::MC_int_vector& vec);
00429 
00430 
00431   private:
00432     
00434     std::vector <int> int_list;
00435 
00436   };
00437 
00438 
00439 
00440 
00441 }
00442 
00443 #endif

Generated on Fri Sep 25 13:31:35 2009 by  doxygen 1.5.8