MAK Data Logger API Documentation for DIS
collectionFunctions.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
9 #ifndef collectionFunctions_H_
10 #define collectionFunctions_H_
11 
12 #include <algorithm>
13 #include <functional>
14 #include <map>
15 
16 namespace MAKLogger
17 {
18 
21  template< typename TPtr >
23  {
24  bool operator() ( const TPtr left,const TPtr right ) const
25  {
26  return *left < *right;
27  }
28  };
29 
30 
32  template <typename ColT,typename T>
33  void DtCallMemberFunction(ColT& col,void (T::*func)())
34  {
35  std::mem_fun_t<void,T> mf = std::mem_fun(func);
36  std::for_each(col.begin(),col.end(),mf);
37  }
38 
40  template <typename K,typename V>
41  void DtCallMemberFunction(std::map<K,V>& col,void (V::*func)())
42  {
43  std::mem_fun_t<void,V> mf = std::mem_fun(func);
44  typename std::map<K,V>::iterator iter = col.begin();
45  for(;iter != col.end();++iter)
46  {
47  mf(iter->second);
48  }
49  }
50 
52  template <typename K,typename V>
53  void DtCallMemberFunction(std::map<K,V*>& col,void (V::*func)())
54  {
55  std::mem_fun_t<void,V> mf = std::mem_fun(func);
56  typename std::map<K,V*>::iterator iter = col.begin();
57  for(;iter != col.end();++iter)
58  {
59  mf(iter->second);
60  }
61  }
62 
65  template <typename ColT,typename T,typename Arg>
66  void DtCallMemberFunction(ColT& col,void (T::*func)(Arg),Arg arg)
67  {
68  std::mem_fun1_t<void,T,Arg> mf = std::mem_fun(func);
69  typename ColT::iterator iter = col.begin();
70  for(;iter != col.end();++iter)
71  {
72  mf(*iter,arg);
73  }
74  }
75 
76 
79  template <typename K,typename V,typename Arg>
80  void DtCallMemberFunction(std::map<K,V>& col,void (V::*func)(Arg),Arg arg)
81  {
82  std::mem_fun1_t<void,V,Arg> mf = std::mem_fun(func);
83  typename std::map<K,V>::iterator iter = col.begin();
84  for(;iter != col.end();++iter)
85  {
86  mf(iter->second,arg);
87  }
88  }
89 
92  template <typename K,typename V,typename Arg>
93  void DtCallMemberFunction(std::map<K,V*>& col,void (V::*func)(Arg),Arg arg)
94  {
95  std::mem_fun1_t<void,V,Arg> mf = std::mem_fun(func);
96  typename std::map<K,V*>::iterator iter = col.begin();
97  for(;iter != col.end();++iter)
98  {
99  mf(iter->second,arg);
100  }
101  }
102 
103  template <typename T>
105  {
106  typename T::const_iterator iter = col.begin();
107  for(;iter != col.end();++iter)
108  {
109  delete *iter;
110  }
111  col.clear();
112  }
113 
114  template <typename T>
116  {
117  typename T::const_iterator iter = col.begin();
118  for(;iter != col.end();++iter)
119  {
120  delete[] *iter;
121  }
122  col.clear();
123  }
124 
125  template <typename K,typename V>
126  void DtDeletePointerAndClear(std::map<K,V>& col)
127  {
128  typename std::map<K,V>::const_iterator iter = col.begin();
129  for(;iter != col.end();++iter)
130  {
131  delete iter->second;
132  }
133  col.clear();
134  }
135 
136  template <typename K,typename V>
137  void DtDeleteArrayAndClear(std::map<K,V>& col)
138  {
139  typename std::map<K,V>::const_iterator iter = col.begin();
140  for(;iter != col.end();++iter)
141  {
142  delete[] iter->second;
143  }
144  col.clear();
145  }
146 }
147 
148 #endif

Document ID: Generated on Mon Jan 19 08:20:14 EST 2015 from SVN revision 149581
Copyright © 2005-2012 VT MÄK. All Rights Reserved (www.mak.com)