12 #include <vlutil/vlExceptions.h>
13 #include <boost/bind/bind.hpp>
18 #define DO_PP(MACRO) MACRO
25 #define MAKE_STREAM_1(word) word##1
26 #define MAKE_STREAM_2(word) MAKE_STREAM_1(word)<<word##2
27 #define MAKE_STREAM_3(word) MAKE_STREAM_2(word)<<word##3
28 #define MAKE_STREAM_4(word) MAKE_STREAM_3(word)<<word##4
29 #define MAKE_STREAM_5(word) MAKE_STREAM_4(word)<<word##5
30 #define MAKE_STREAM_6(word) MAKE_STREAM_5(word)<<word##6
31 #define MAKE_STREAM_7(word) MAKE_STREAM_6(word)<<word##7
32 #define MAKE_STREAM_8(word) MAKE_STREAM_7(word)<<word##8
33 #define MAKE_STREAM_9(word) MAKE_STREAM_8(word)<<word##9
34 #define MAKE_STREAM_10(word) MAKE_STREAM_9(word)<<word##10
36 #define MAKE_STREAM(word,count) DO_PP(MAKE_STREAM_##count(word))
42 #define MAKE_STREAMOUT_1(word) word##1
43 #define MAKE_STREAMOUT_2(word) MAKE_STREAMOUT_1(word)>>word##2
44 #define MAKE_STREAMOUT_3(word) MAKE_STREAMOUT_2(word)>>word##3
45 #define MAKE_STREAMOUT_4(word) MAKE_STREAMOUT_3(word)>>word##4
46 #define MAKE_STREAMOUT_5(word) MAKE_STREAMOUT_4(word)>>word##5
47 #define MAKE_STREAMOUT_6(word) MAKE_STREAMOUT_5(word)>>word##6
48 #define MAKE_STREAMOUT_7(word) MAKE_STREAMOUT_6(word)>>word##7
49 #define MAKE_STREAMOUT_8(word) MAKE_STREAMOUT_7(word)>>word##8
50 #define MAKE_STREAMOUT_9(word) MAKE_STREAMOUT_8(word)>>word##9
51 #define MAKE_STREAMOUT_10(word) MAKE_STREAMOUT_9(word)>>word##10
53 #define MAKE_STREAMOUT(word,count) DO_PP(MAKE_STREAMOUT_##count(word))
60 #define MAKE_LIST_1(word) word##1
61 #define MAKE_LIST_2(word) MAKE_LIST_1(word),word##2
62 #define MAKE_LIST_3(word) MAKE_LIST_2(word),word##3
63 #define MAKE_LIST_4(word) MAKE_LIST_3(word),word##4
64 #define MAKE_LIST_5(word) MAKE_LIST_4(word),word##5
65 #define MAKE_LIST_6(word) MAKE_LIST_5(word),word##6
66 #define MAKE_LIST_7(word) MAKE_LIST_6(word),word##7
67 #define MAKE_LIST_8(word) MAKE_LIST_7(word),word##8
68 #define MAKE_LIST_9(word) MAKE_LIST_8(word),word##9
69 #define MAKE_LIST_10(word) MAKE_LIST_9(word),word##10
71 #define MAKE_LIST(word,count) DO_PP(MAKE_LIST_##count(word))
77 #define MAKE_MULTILIST_1(first,second) first##1 second##1
78 #define MAKE_MULTILIST_2(first,second) MAKE_MULTILIST_1(first,second),first##2 second##2
79 #define MAKE_MULTILIST_3(first,second) MAKE_MULTILIST_2(first,second),first##3 second##3
80 #define MAKE_MULTILIST_4(first,second) MAKE_MULTILIST_3(first,second),first##4 second##4
81 #define MAKE_MULTILIST_5(first,second) MAKE_MULTILIST_4(first,second),first##5 second##5
82 #define MAKE_MULTILIST_6(first,second) MAKE_MULTILIST_5(first,second),first##6 second##6
83 #define MAKE_MULTILIST_7(first,second) MAKE_MULTILIST_6(first,second),first##7 second##7
84 #define MAKE_MULTILIST_8(first,second) MAKE_MULTILIST_7(first,second),first##8 second##8
85 #define MAKE_MULTILIST_9(first,second) MAKE_MULTILIST_8(first,second),first##9 second##9
86 #define MAKE_MULTILIST_10(first,second) MAKE_MULTILIST_9(first,second),first##10 second##10
88 #define MAKE_MULTILIST(first,second,count) DO_PP(MAKE_MULTILIST_##count(first,second))
95 #define MAKE_CAST_CALL_1(first,second,third,forth) first##1 second(third,forth##1)
96 #define MAKE_CAST_CALL_2(first,second,third,forth) MAKE_CAST_CALL_1(first,second,third,forth),first##2 second(third,forth##2)
97 #define MAKE_CAST_CALL_3(first,second,third,forth) MAKE_CAST_CALL_2(first,second,third,forth),first##3 second(third,forth##3)
98 #define MAKE_CAST_CALL_4(first,second,third,forth) MAKE_CAST_CALL_3(first,second,third,forth),first##4 second(third,forth##4)
99 #define MAKE_CAST_CALL_5(first,second,third,forth) MAKE_CAST_CALL_4(first,second,third,forth),first##5 second(third,forth##5)
100 #define MAKE_CAST_CALL_6(first,second,third,forth) MAKE_CAST_CALL_5(first,second,third,forth),first##6 second(third,forth##6)
101 #define MAKE_CAST_CALL_7(first,second,third,forth) MAKE_CAST_CALL_6(first,second,third,forth),first##7 second(third,forth##7)
102 #define MAKE_CAST_CALL_8(first,second,third,forth) MAKE_CAST_CALL_7(first,second,third,forth),first##8 second(third,forth##8)
103 #define MAKE_CAST_CALL_9(first,second,third,forth) MAKE_CAST_CALL_8(first,second,third,forth),first##9 second(third,forth##9)
104 #define MAKE_CAST_CALL_10(first,second,third,forth) MAKE_CAST_CALL_9(first,second,third,forth),first##10 second(third,forth##10)
106 #define MAKE_CAST_CALL(first,second,third,forth,count) DO_PP(MAKE_CAST_CALL_##count(first,second,third,forth))
112 #define MAKE_DECL_LIST_1(word) word##1
113 #define MAKE_DECL_LIST_2(word) MAKE_DECL_LIST_1(word);word##2
114 #define MAKE_DECL_LIST_3(word) MAKE_DECL_LIST_2(word);word##3
115 #define MAKE_DECL_LIST_4(word) MAKE_DECL_LIST_3(word);word##4
116 #define MAKE_DECL_LIST_5(word) MAKE_DECL_LIST_4(word);word##5
117 #define MAKE_DECL_LIST_6(word) MAKE_DECL_LIST_5(word);word##6
118 #define MAKE_DECL_LIST_7(word) MAKE_DECL_LIST_6(word);word##7
119 #define MAKE_DECL_LIST_8(word) MAKE_DECL_LIST_7(word);word##8
120 #define MAKE_DECL_LIST_9(word) MAKE_DECL_LIST_8(word);word##9
121 #define MAKE_DECL_LIST_10(word) MAKE_DECL_LIST_9(word);word##10
123 #define MAKE_DECL_LIST(word,count) DO_PP(MAKE_DECL_LIST_##count(word))
128 #define MAKE_DECL_MULTILIST_1(first,second) first##1 second##1
129 #define MAKE_DECL_MULTILIST_2(first,second) MAKE_DECL_MULTILIST_1(first,second);first##2 second##2
130 #define MAKE_DECL_MULTILIST_3(first,second) MAKE_DECL_MULTILIST_2(first,second);first##3 second##3
131 #define MAKE_DECL_MULTILIST_4(first,second) MAKE_DECL_MULTILIST_3(first,second);first##4 second##4
132 #define MAKE_DECL_MULTILIST_5(first,second) MAKE_DECL_MULTILIST_4(first,second);first##5 second##5
133 #define MAKE_DECL_MULTILIST_6(first,second) MAKE_DECL_MULTILIST_5(first,second);first##6 second##6
134 #define MAKE_DECL_MULTILIST_7(first,second) MAKE_DECL_MULTILIST_6(first,second);first##7 second##7
135 #define MAKE_DECL_MULTILIST_8(first,second) MAKE_DECL_MULTILIST_7(first,second);first##8 second##8
136 #define MAKE_DECL_MULTILIST_9(first,second) MAKE_DECL_MULTILIST_8(first,second);first##9 second##9
137 #define MAKE_DECL_MULTILIST_10(first,second) MAKE_DECL_MULTILIST_9(first,second);first##10 second##10
139 #define MAKE_DECL_MULTILIST(first,second,count) DO_PP(MAKE_DECL_MULTILIST_##count(first,second))
142 #define EXPORT_TEMPLATE_TYPEDEF(C,TD)\
145 #define EXPORT_TEMPLATE_TYPEDEF(C,TD)\
152 #define FAST_REPEATED_CALL(count,x) \
156 size_t __FAST_ITERATE_count = count;\
157 size_t __FAST_ITERATE_n = (__FAST_ITERATE_count + 7) >> 3; \
158 switch (__FAST_ITERATE_count & 7) \
168 } while (--__FAST_ITERATE_n > 0);\
183 template <
typename M>
186 for (
auto& keyVal : map)
188 auto ptr = keyVal.second;
200 template <
typename V>
203 typename V::value_type ptr;
204 typename V::iterator curIter = vec.begin();
205 typename V::iterator endIter = vec.end();
206 for ( ; curIter != endIter; ++curIter )
215 template <
typename Iter>
218 for(Iter cur = begin;cur != end;++cur)
224 template <
typename Key,
typename Value>
227 inline bool operator()(
const std::pair<Key,Value>& a,
const std::pair<Key,Value>& b)
const
229 return a.first < b.first;
234 template <
typename T,
typename R,
typename A,
typename Col>
237 typename Col::iterator curIter = col.begin();
238 typename Col::iterator endIter = col.end();
239 for(;curIter != endIter;++curIter)
241 (_this->*memfun)(*curIter);
245 template <
typename Ret,
typename AT,
typename Class>
247 const Ret (Class::* memberPtr)(AT)
const,
250 return const_cast<Ret
>(_this->*(memberPtr)(param));
255 template <
typename T,
void(T::*MF)()>
261 template <
class InputIterator1,
class InputIterator2,
class OutputIterator1,
class OutputIterator2>
263 InputIterator2 first2, InputIterator2 last2,
264 OutputIterator1 result1,
265 OutputIterator2 result2 )
267 while (first1!=last1 && first2!=last2)
271 *result1++ = *first1++;
273 else if (*first2<*first1)
275 *result2++ = *first2++;
284 copy(first1,last1,result1);
285 copy(first2,last2,result2);
313 template <
typename iter,
typename T>
320 template <
typename iter,
typename F>
327 template <
typename T,
typename Ax >
330 size_t size = list.size();
337 typename std::vector<T,Ax>::iterator i =
fasterFind(size,list.begin(),list.end(),
value);
346 if(&(*i) != &list.back())
350 list.resize(size - 1);
356 template <
typename T,
typename Ax >
359 size_t size = list.size();
370 typename std::vector<T*,Ax>::iterator i =
fasterFind(size,list.begin(),list.end(),
value);
373 if(&(*i) != &list.back())
377 list.resize(size - 1);
382 template <
typename T,
typename Ax,
typename Function >
385 size_t size = list.size();
392 typename std::vector<T,Ax>::iterator i =
fastFindPred(size,list.begin(),list.end(),f);
395 if(&(*i) != &list.back())
399 list.resize(size - 1);
404 template <
typename T,
typename Ax,
typename Function>
407 size_t size = list.size();
414 typename std::vector<T*,Ax>::iterator i =
fastFindPred(size,list.begin(),list.end(), f );
417 if(&(*i) != &list.back())
421 list.resize(size - 1);
426 template <
typename Ret,
typename T>
448 template <
typename Ret,
typename T>
454 template <
typename Ret,
typename T>
479 template <
typename Ret,
typename T>
486 template <
typename K,
typename V>
487 const V&
findOrThrow(
const std::map<K,V,std::less<K>, std::allocator<std::pair<const K, V> > >& map, K key)
489 typename std::map<K,V>::const_iterator iter = map.find(key);
490 if(iter == map.end())
492 DtTHROW_NEW(DtInvalidInput,
"Unable to find key");
498 template <
typename K,
typename V>
499 const V&
findByIndexOrThrow(
const std::map<K,V,std::less<K>, std::allocator<std::pair<const K, V> > >& map,
int index)
501 if(index >= (
int)map.size())
503 DtTHROW_NEW(DtInvalidInput,
"Index out of range.");
505 typename std::map<K,V>::const_iterator i = map.begin();
506 std::advance(i,index);
511 template <
typename V>
514 if(index >= (
int)vec.size())
516 DtTHROW_NEW(DtInvalidInput,
"Index out of range.");
518 typename std::vector<V>::const_iterator i = vec.begin();
519 std::advance(i,index);