12 #include <vlutil/vlExceptions.h>
19 #define DO_PP(MACRO) MACRO
26 #define MAKE_STREAM_1(word) word##1
27 #define MAKE_STREAM_2(word) MAKE_STREAM_1(word)<<word##2
28 #define MAKE_STREAM_3(word) MAKE_STREAM_2(word)<<word##3
29 #define MAKE_STREAM_4(word) MAKE_STREAM_3(word)<<word##4
30 #define MAKE_STREAM_5(word) MAKE_STREAM_4(word)<<word##5
31 #define MAKE_STREAM_6(word) MAKE_STREAM_5(word)<<word##6
32 #define MAKE_STREAM_7(word) MAKE_STREAM_6(word)<<word##7
33 #define MAKE_STREAM_8(word) MAKE_STREAM_7(word)<<word##8
34 #define MAKE_STREAM_9(word) MAKE_STREAM_8(word)<<word##9
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
52 #define MAKE_STREAMOUT(word,count) DO_PP(MAKE_STREAMOUT_##count(word))
59 #define MAKE_LIST_1(word) word##1
60 #define MAKE_LIST_2(word) MAKE_LIST_1(word),word##2
61 #define MAKE_LIST_3(word) MAKE_LIST_2(word),word##3
62 #define MAKE_LIST_4(word) MAKE_LIST_3(word),word##4
63 #define MAKE_LIST_5(word) MAKE_LIST_4(word),word##5
64 #define MAKE_LIST_6(word) MAKE_LIST_5(word),word##6
65 #define MAKE_LIST_7(word) MAKE_LIST_6(word),word##7
66 #define MAKE_LIST_8(word) MAKE_LIST_7(word),word##8
67 #define MAKE_LIST_9(word) MAKE_LIST_8(word),word##9
69 #define MAKE_LIST(word,count) DO_PP(MAKE_LIST_##count(word))
75 #define MAKE_MULTILIST_1(first,second) first##1 second##1
76 #define MAKE_MULTILIST_2(first,second) MAKE_MULTILIST_1(first,second),first##2 second##2
77 #define MAKE_MULTILIST_3(first,second) MAKE_MULTILIST_2(first,second),first##3 second##3
78 #define MAKE_MULTILIST_4(first,second) MAKE_MULTILIST_3(first,second),first##4 second##4
79 #define MAKE_MULTILIST_5(first,second) MAKE_MULTILIST_4(first,second),first##5 second##5
80 #define MAKE_MULTILIST_6(first,second) MAKE_MULTILIST_5(first,second),first##6 second##6
81 #define MAKE_MULTILIST_7(first,second) MAKE_MULTILIST_6(first,second),first##7 second##7
82 #define MAKE_MULTILIST_8(first,second) MAKE_MULTILIST_7(first,second),first##8 second##8
83 #define MAKE_MULTILIST_9(first,second) MAKE_MULTILIST_8(first,second),first##9 second##9
85 #define MAKE_MULTILIST(first,second,count) DO_PP(MAKE_MULTILIST_##count(first,second))
92 #define MAKE_CAST_CALL_1(first,second,third,forth) first##1 second(third,forth##1)
93 #define MAKE_CAST_CALL_2(first,second,third,forth) MAKE_CAST_CALL_1(first,second,third,forth),first##2 second(third,forth##2)
94 #define MAKE_CAST_CALL_3(first,second,third,forth) MAKE_CAST_CALL_2(first,second,third,forth),first##3 second(third,forth##3)
95 #define MAKE_CAST_CALL_4(first,second,third,forth) MAKE_CAST_CALL_3(first,second,third,forth),first##4 second(third,forth##4)
96 #define MAKE_CAST_CALL_5(first,second,third,forth) MAKE_CAST_CALL_4(first,second,third,forth),first##5 second(third,forth##5)
97 #define MAKE_CAST_CALL_6(first,second,third,forth) MAKE_CAST_CALL_5(first,second,third,forth),first##6 second(third,forth##6)
98 #define MAKE_CAST_CALL_7(first,second,third,forth) MAKE_CAST_CALL_6(first,second,third,forth),first##7 second(third,forth##7)
99 #define MAKE_CAST_CALL_8(first,second,third,forth) MAKE_CAST_CALL_7(first,second,third,forth),first##8 second(third,forth##8)
100 #define MAKE_CAST_CALL_9(first,second,third,forth) MAKE_CAST_CALL_8(first,second,third,forth),first##9 second(third,forth##9)
102 #define MAKE_CAST_CALL(first,second,third,forth,count) DO_PP(MAKE_CAST_CALL_##count(first,second,third,forth))
108 #define MAKE_DECL_LIST_1(word) word##1
109 #define MAKE_DECL_LIST_2(word) MAKE_DECL_LIST_1(word);word##2
110 #define MAKE_DECL_LIST_3(word) MAKE_DECL_LIST_2(word);word##3
111 #define MAKE_DECL_LIST_4(word) MAKE_DECL_LIST_3(word);word##4
112 #define MAKE_DECL_LIST_5(word) MAKE_DECL_LIST_4(word);word##5
113 #define MAKE_DECL_LIST_6(word) MAKE_DECL_LIST_5(word);word##6
114 #define MAKE_DECL_LIST_7(word) MAKE_DECL_LIST_6(word);word##7
115 #define MAKE_DECL_LIST_8(word) MAKE_DECL_LIST_7(word);word##8
116 #define MAKE_DECL_LIST_9(word) MAKE_DECL_LIST_8(word);word##9
118 #define MAKE_DECL_LIST(word,count) DO_PP(MAKE_DECL_LIST_##count(word))
123 #define MAKE_DECL_MULTILIST_1(first,second) first##1 second##1
124 #define MAKE_DECL_MULTILIST_2(first,second) MAKE_DECL_MULTILIST_1(first,second);first##2 second##2
125 #define MAKE_DECL_MULTILIST_3(first,second) MAKE_DECL_MULTILIST_2(first,second);first##3 second##3
126 #define MAKE_DECL_MULTILIST_4(first,second) MAKE_DECL_MULTILIST_3(first,second);first##4 second##4
127 #define MAKE_DECL_MULTILIST_5(first,second) MAKE_DECL_MULTILIST_4(first,second);first##5 second##5
128 #define MAKE_DECL_MULTILIST_6(first,second) MAKE_DECL_MULTILIST_5(first,second);first##6 second##6
129 #define MAKE_DECL_MULTILIST_7(first,second) MAKE_DECL_MULTILIST_6(first,second);first##7 second##7
130 #define MAKE_DECL_MULTILIST_8(first,second) MAKE_DECL_MULTILIST_7(first,second);first##8 second##8
131 #define MAKE_DECL_MULTILIST_9(first,second) MAKE_DECL_MULTILIST_8(first,second);first##9 second##9
133 #define MAKE_DECL_MULTILIST(first,second,count) DO_PP(MAKE_DECL_MULTILIST_##count(first,second))
136 #define EXPORT_TEMPLATE_TYPEDEF(C,TD)\
139 #define EXPORT_TEMPLATE_TYPEDEF(C,TD)\
146 #define FAST_REPEATED_CALL(count,x) \
150 size_t __FAST_ITERATE_count = count;\
151 size_t __FAST_ITERATE_n = (__FAST_ITERATE_count + 7) >> 3; \
152 switch (__FAST_ITERATE_count & 7) \
162 } while (--__FAST_ITERATE_n > 0);\
172 template <
typename K,
typename V,
typename Pr,
typename Alloc>
175 typename std::map<K,V,Pr,Alloc>::const_iterator iter = map.find(key);
176 if(iter == map.end())
182 return const_cast<V*
>(&iter->second);
191 template <
typename M>
194 typename M::mapped_type ptr;
195 typename M::iterator curIter = map.begin();
196 typename M::const_iterator endIter = map.end();
197 for ( ; curIter != endIter; ++curIter )
199 ptr = curIter->second;
211 template <
typename V>
214 typename V::value_type ptr;
215 typename V::iterator curIter = vec.begin();
216 typename V::const_iterator endIter = vec.end();
217 for ( ; curIter != endIter; ++curIter )
226 template <
typename Iter>
229 for(Iter cur = begin;cur != end;++cur)
235 template <
typename Key,
typename Value>
238 inline bool operator()(
const std::pair<Key,Value>& a,
const std::pair<Key,Value>& b)
const
240 return a.first < b.first;
254 template <
typename T,
typename R,
typename A>
257 return std::bind1st(std::mem_fun(memfun),ptr);
260 template <
typename T,
typename R,
typename A>
263 return std::bind1st(std::mem_fun(memfun),ptr);
266 template <
typename T,
typename R,
typename A>
269 return std::bind1st(std::mem_fun(memfun),ptr);
272 template <
typename T,
typename R,
typename A,
typename Col>
275 typename Col::iterator curIter = col.begin();
276 typename Col::iterator endIter = col.end();
277 for(;curIter != endIter;++curIter)
279 (_this->*memfun)(*curIter);
283 template <
typename Ret,
typename AT,
typename Class>
285 const Ret (Class::* memberPtr)(AT)
const,
288 return const_cast<Ret
>(_this->*(memberPtr)(param));
293 template <
typename T,
void(T::*MF)()>
299 template <
class InputIterator1,
class InputIterator2,
class OutputIterator1,
class OutputIterator2>
301 InputIterator2 first2, InputIterator2 last2,
302 OutputIterator1 result1,
303 OutputIterator2 result2 )
305 while (first1!=last1 && first2!=last2)
309 *result1++ = *first1++;
311 else if (*first2<*first1)
313 *result2++ = *first2++;
322 copy(first1,last1,result1);
323 copy(first2,last2,result2);
351 template <
typename iter,
typename T>
352 iter
fasterFind(
size_t size, iter begin, iter end,
const T& value)
358 template <
typename iter,
typename F>
365 template <
typename T,
typename Ax >
368 size_t size = list.size();
375 typename std::vector<T,Ax>::iterator i =
fasterFind(size,list.begin(),list.end(),value);
384 if(&(*i) != &list.back())
388 list.resize(size - 1);
394 template <
typename T,
typename Ax >
397 size_t size = list.size();
408 typename std::vector<T*,Ax>::iterator i =
fasterFind(size,list.begin(),list.end(),value);
411 if(&(*i) != &list.back())
415 list.resize(size - 1);
420 template <
typename T,
typename Ax,
typename Function >
423 size_t size = list.size();
434 typename std::vector<T,Ax>::iterator i =
fastFindPred(size,list.begin(),list.end(),f);
437 if(&(*i) != &list.back())
441 list.resize(size - 1);
446 template <
typename T,
typename Ax,
typename Function>
449 size_t size = list.size();
460 typename std::vector<T*,Ax>::iterator i =
fastFindPred(size,list.begin(),list.end(), f );
463 if(&(*i) != &list.back())
467 list.resize(size - 1);
472 template <
typename Ret,
typename T>
494 template <
typename Ret,
typename T>
500 template <
typename Ret,
typename T>
525 template <
typename Ret,
typename T>
532 template <
typename K,
typename V>
533 const V&
findOrThrow(
const std::map<K,V,std::less<K>, std::allocator<std::pair<const K, V> > >& map, K key)
535 typename std::map<K,V>::const_iterator iter = map.find(key);
536 if(iter == map.end())
538 DtTHROW_NEW(DtInvalidInput,
"Unable to find key");
544 template <
typename K,
typename V>
545 const V&
findByIndexOrThrow(
const std::map<K,V,std::less<K>, std::allocator<std::pair<const K, V> > >& map,
int index)
547 if(index >= (
int)map.size())
549 DtTHROW_NEW(DtInvalidInput,
"Index out of range.");
551 typename std::map<K,V>::const_iterator i = map.begin();
552 std::advance(i,index);
557 template <
typename V>
560 if(index >= (
int)vec.size())
562 DtTHROW_NEW(DtInvalidInput,
"Index out of range.");
564 typename std::vector<V>::const_iterator i = vec.begin();
565 std::advance(i,index);