12 #include <vlutil/vlExceptions.h>
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);\
178 template <
typename K,
typename V,
typename Pr,
typename Alloc>
181 typename std::map<K,V,Pr,Alloc>::const_iterator iter = map.find(key);
182 if(iter == map.end())
188 return const_cast<V*
>(&iter->second);
197 template <
typename M>
200 typename M::mapped_type ptr;
201 typename M::iterator curIter = map.begin();
202 typename M::const_iterator endIter = map.end();
203 for ( ; curIter != endIter; ++curIter )
205 ptr = curIter->second;
217 template <
typename V>
220 typename V::value_type ptr;
221 typename V::iterator curIter = vec.begin();
222 typename V::iterator endIter = vec.end();
223 for ( ; curIter != endIter; ++curIter )
232 template <
typename Iter>
235 for(Iter cur = begin;cur !=
end;++cur)
241 template <
typename Key,
typename Value>
244 inline bool operator()(
const std::pair<Key,Value>&
a,
const std::pair<Key,Value>&
b)
const
246 return a.first < b.first;
251 template <
typename T,
typename R,
typename A,
typename Col>
254 typename Col::iterator curIter = col.begin();
255 typename Col::iterator endIter = col.end();
256 for(;curIter != endIter;++curIter)
258 (_this->*memfun)(*curIter);
262 template <
typename Ret,
typename AT,
typename Class>
264 const Ret (Class::* memberPtr)(AT)
const,
267 return const_cast<Ret
>(_this->*(memberPtr)(param));
272 template <
typename T,
void(T::*MF)()>
278 template <
class InputIterator1,
class InputIterator2,
class OutputIterator1,
class OutputIterator2>
280 InputIterator2 first2, InputIterator2 last2,
281 OutputIterator1 result1,
282 OutputIterator2 result2 )
284 while (first1!=last1 && first2!=last2)
288 *result1++ = *first1++;
290 else if (*first2<*first1)
292 *result2++ = *first2++;
301 copy(first1,last1,result1);
302 copy(first2,last2,result2);
330 template <
typename iter,
typename T>
337 template <
typename iter,
typename F>
344 template <
typename T,
typename Ax >
347 size_t size = list.size();
354 typename std::vector<T,Ax>::iterator i =
fasterFind(size,list.begin(),list.end(),
value);
363 if(&(*i) != &list.back())
367 list.resize(size - 1);
373 template <
typename T,
typename Ax >
376 size_t size = list.size();
387 typename std::vector<T*,Ax>::iterator i =
fasterFind(size,list.begin(),list.end(),
value);
390 if(&(*i) != &list.back())
394 list.resize(size - 1);
399 template <
typename T,
typename Ax,
typename Function >
402 size_t size = list.size();
413 typename std::vector<T,Ax>::iterator i =
fastFindPred(size,list.begin(),list.end(),
f);
416 if(&(*i) != &list.back())
420 list.resize(size - 1);
425 template <
typename T,
typename Ax,
typename Function>
428 size_t size = list.size();
439 typename std::vector<T*,Ax>::iterator i =
fastFindPred(size,list.begin(),list.end(),
f );
442 if(&(*i) != &list.back())
446 list.resize(size - 1);
451 template <
typename Ret,
typename T>
473 template <
typename Ret,
typename T>
479 template <
typename Ret,
typename T>
504 template <
typename Ret,
typename T>
511 template <
typename K,
typename V>
512 const V&
findOrThrow(
const std::map<K,V,std::less<K>, std::allocator<std::pair<const K, V> > >& map, K
key)
514 typename std::map<K,V>::const_iterator iter = map.find(key);
515 if(iter == map.end())
517 DtTHROW_NEW(DtInvalidInput,
"Unable to find key");
523 template <
typename K,
typename V>
526 if(index >= (
int)map.size())
528 DtTHROW_NEW(DtInvalidInput,
"Index out of range.");
530 typename std::map<K,V>::const_iterator i = map.begin();
531 std::advance(i,index);
536 template <
typename V>
539 if(index >= (
int)vec.size())
541 DtTHROW_NEW(DtInvalidInput,
"Index out of range.");
543 typename std::vector<V>::const_iterator i = vec.begin();
544 std::advance(i,index);