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
00029 #ifndef __SEAL_UTILS_H__
00030 #define __SEAL_UTILS_H__
00031
00032 #include "functor.h"
00033 #include "collection.h"
00034
00035 namespace seal
00036 {
00037
00042 class Utils
00043 {
00044
00045 public:
00046
00054 template <typename T>
00055 static inline void swap(T &a, T &b)
00056 {
00057 T temp = a;
00058 a = b;
00059 b = temp;
00060 }
00061
00076 template <typename T>
00077 static inline void foreach(const Collection<T> &c, UnaryFunction<T, void> &fobj)
00078 {
00079 AbstractIterator<T> *iterPtr = c.iteratorPtr();
00080 iterPtr->reset();
00081
00082 while (iterPtr->hasNext())
00083 {
00084 fobj(iterPtr->next());
00085 }
00086 }
00087
00103 template <typename T>
00104 static inline void foreach(const Collection<T> &c, void (*fptr)(const T &t))
00105 {
00106 AbstractIterator<T> *iterPtr = c.iteratorPtr();
00107 iterPtr->reset();
00108
00109 while (iterPtr->hasNext())
00110 {
00111 fptr(iterPtr->next());
00112 }
00113 }
00114
00130 template <typename T>
00131 static inline void foreach(const Collection<T> &c, void (*fptr)(T &t))
00132 {
00133 AbstractIterator<T> *iterPtr = c.iteratorPtr();
00134 iterPtr->reset();
00135
00136 while (iterPtr->hasNext())
00137 {
00138 fptr(iterPtr->next());
00139 }
00140 }
00141
00157 template <typename T>
00158 static inline void foreach(const Collection<T> &c, void (*fptr)(T t))
00159 {
00160 AbstractIterator<T> *iterPtr = c.iteratorPtr();
00161 iterPtr->reset();
00162
00163 while (iterPtr->hasNext())
00164 {
00165 fptr(iterPtr->next());
00166 }
00167 }
00168
00169 };
00170
00171 #define swap(a, b) Utils::swap(a, b)
00172 #define foreach(a, b) Utils::foreach(a, b)
00173
00174 }
00175
00176 #endif // __SEAL_UTILS_H_
00177