00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _terimber_algorithm_hpp_
00029 #define _terimber_algorithm_hpp_
00030
00031 #include "alg/algorith.h"
00032
00033 BEGIN_TERIMBER_NAMESPACE
00034 #pragma pack(4)
00035
00036
00037 namespace algorithm
00038 {
00039 template< class Cont, class Pred >
00040 inline void find_if(Cont& cont, Pred& pr, const mutex& mtx)
00041 {
00042 mutex_keeper keeper(mtx);
00043 TYPENAME Cont::iterator first = cont.begin(), last = cont.end();
00044 for (; first != last; ++first)
00045 if (pr(*first))
00046 break;
00047 }
00048
00049 template< class Cont, class Pred >
00050 inline void for_each(Cont& cont, Pred& pr, const mutex& mtx)
00051 {
00052 mutex_keeper keeper(mtx);
00053 TYPENAME Cont::iterator first = cont.begin(), last = cont.end();
00054
00055 for (; first != last; ++first)
00056 pr(*first);
00057 }
00058
00059 template< class Cont, class Pred >
00060 inline void remove_if(Cont& cont, Pred& pr, const mutex& mtx)
00061 {
00062 mutex_keeper keeper(mtx);
00063 TYPENAME Cont::iterator first = cont.begin(), last = cont.end();
00064
00065 for (; first != last; ++first)
00066 if (pr(*first))
00067 {
00068 cont.erase(first);
00069 break;
00070 }
00071 }
00072
00073 template< class Al, class Obj, class Cont >
00074 inline void push_back(Al& al, Cont& cont, Obj& obj, const mutex& mtx)
00075 {
00076 mutex_keeper keeper(mtx);
00077 cont.push_back(al, obj);
00078 }
00079
00080 template< class Al, class Cont, class Pred, class Obj >
00081 inline bool push_back_if(Al& al, Cont& cont, Pred& pr, Obj& obj, const mutex& mtx)
00082 {
00083 mutex_keeper keeper(mtx);
00084 TYPENAME Cont::iterator first = cont.begin(), last = cont.end();
00085
00086 for (; first != last; ++first)
00087 if (pr(*first))
00088 return false;
00089
00090 cont.push_back(al, obj);
00091 return true;
00092 }
00093
00094 template< class Obj, class Cont >
00095 inline void push_back(Cont& cont, Obj& obj, const mutex& mtx)
00096 {
00097 mutex_keeper keeper(mtx);
00098 cont.push_back(obj);
00099 }
00100
00101 template< class Cont, class Pred, class Obj >
00102 inline bool push_back_if(Cont& cont, Pred& pr, Obj& obj, const mutex& mtx)
00103 {
00104 mutex_keeper keeper(mtx);
00105 TYPENAME Cont::iterator first = cont.begin(), last = cont.end();
00106
00107 for (; first != last; ++first)
00108 if (pr(*first))
00109 return false;
00110
00111 cont.push_back(obj);
00112 return true;
00113 }
00114
00115 template< class Obj, class Cont >
00116 inline void remove(Cont& cont, Obj& obj, const mutex& mtx)
00117 {
00118 mutex_keeper keeper(mtx);
00119 cont.remove(obj);
00120 }
00121
00122 template< class Obj >
00123 inline void swap(Obj& first, Obj& second)
00124 {
00125 Obj temp(first);
00126 first = second;
00127 second = temp;
00128 }
00129 }
00130
00131 #pragma pack()
00132 END_TERIMBER_NAMESPACE
00133
00134 #endif // _terimber_algorithm_hpp_
00135