Perspective3D_api
Documentation Perspective3D
perspective_div2.h
Aller à la documentation de ce fichier.
1 
19 #ifndef PERSPECTIVE_DIV2_H
20 #define PERSPECTIVE_DIV2_H
21 
22 #include <vector> /* std::vector */
23 #include <algorithm> /* std::sort */
24 
28 template<typename T> inline bool CompareSort(const T &v1, const T &v2)
29 {
30  return (v1<v2);
31 }
32 
36 template<typename T> inline bool CompareSortR(const T &v1, const T &v2)
37 {
38  return (v1>v2);
39 }
40 
44 inline bool CompareSortInt(const int &v1, const int &v2)
45 {
46  return (v1<v2);
47 }
48 
52 inline bool CompareSortInt(const long &v1, const long &v2)
53 {
54  return (v1<v2);
55 }
56 
60 inline bool CompareSortIntR(const int &v1, const int &v2)
61 {
62  return (v1>v2);
63 }
64 
68 inline bool CompareSortIntR(const long &v1, const long &v2)
69 {
70  return (v1>v2);
71 }
72 
76 template<typename T> inline void TriStdVect(std::vector<T> &vect, bool (*fct_compare)(const T&, const T&))
77 {
78  std::sort(vect.begin(), vect.end(), fct_compare);
79 }
80 
84 template <class T> inline bool StdVectSupprId(std::vector<T> &v, unsigned int id)
85 {
86 #if 1
87  if (id < v.size())
88  {
89  v.erase(v.begin()+id);
90  return true;
91  }
92 #else
93  const unsigned int n = v.size();
94  if (id < n)
95  {
96  if (n == 1)
97  {
98  v.clear();
99  }
100  else
101  {
102  for(unsigned int i=id+1; i<n; ++i)
103  {
104  v[i-1] = std::move(v[i]);
105  }
106  v.pop_back();
107  }
108  return true;
109  }
110 #endif // 0
111  return false;
112 }
113 
117 template <class T> inline bool StdVectInsert(std::vector<T> &v, const T &t, unsigned int id)
118 {
119  if (id < v.size())
120  {
121  v.insert(v.begin()+id, t);
122  return true;
123  }
124  else if (id == v.size())
125  {
126  v.push_back(t);
127  return true;
128  }
129  return false;
130 }
131 #endif // PERSPECTIVE_DIV2_H
bool StdVectSupprId(std::vector< T > &v, unsigned int id)
StdVectSupprId Supprime un élément du vecteur d&#39;après son id.
Definition: perspective_div2.h:84
bool CompareSortInt(const int &v1, const int &v2)
Comparaison croissante de nombres entiers (pour qsort()).
Definition: perspective_div2.h:44
bool CompareSort(const T &v1, const T &v2)
Comparaison croissante générique (pour qsort()).
Definition: perspective_div2.h:28
bool StdVectInsert(std::vector< T > &v, const T &t, unsigned int id)
StdVectInsert Insert un élément dans un vecteur.
Definition: perspective_div2.h:117
void TriStdVect(std::vector< T > &vect, bool(*fct_compare)(const T &, const T &))
TriStdVect Fonction d&#39;interface pour le tri avec qsort() sur un std::vector.
Definition: perspective_div2.h:76
bool CompareSortR(const T &v1, const T &v2)
Comparaison décroissante générique (pour qsort()).
Definition: perspective_div2.h:36
bool CompareSortIntR(const int &v1, const int &v2)
Comparaison décroissante de nombres entiers (pour qsort()).
Definition: perspective_div2.h:60