collectionFunctions.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 1992-2010 VT MAK
00003 ** All rights reserved.
00004 ******************************************************************************/
00005 
00008 
00009 #ifndef collectionFunctions_H_
00010 #define collectionFunctions_H_
00011 
00012 #include <algorithm>
00013 #include <functional>
00014 #include <map>
00015 
00016 namespace MAKLogger
00017 {
00018 
00021    template< typename TPtr >
00022    struct DtSortByPtrObject
00023    {      
00024       bool operator() ( const TPtr left,const TPtr right ) const
00025       {
00026          return *left < *right;
00027       }
00028    };
00029 
00030 
00032    template <typename ColT,typename T>
00033    void DtCallMemberFunction(ColT& col,void (T::*func)())
00034    {
00035       std::mem_fun_t<void,T> mf = std::mem_fun(func);
00036       std::for_each(col.begin(),col.end(),mf);
00037    }
00038 
00040    template <typename K,typename V>
00041    void DtCallMemberFunction(std::map<K,V>& col,void (V::*func)())
00042    {
00043       std::mem_fun_t<void,V> mf = std::mem_fun(func);
00044       typename std::map<K,V>::iterator iter = col.begin();
00045       for(;iter != col.end();++iter)
00046       {
00047          mf(iter->second);
00048       }
00049    }
00050 
00052    template <typename K,typename V>
00053    void DtCallMemberFunction(std::map<K,V*>& col,void (V::*func)())
00054    {
00055       std::mem_fun_t<void,V> mf = std::mem_fun(func);
00056       typename std::map<K,V*>::iterator iter = col.begin();
00057       for(;iter != col.end();++iter)
00058       {
00059          mf(iter->second);
00060       }
00061    }
00062 
00065    template <typename ColT,typename T,typename Arg>
00066    void DtCallMemberFunction(ColT& col,void (T::*func)(Arg),Arg arg)
00067    {
00068       std::mem_fun1_t<void,T,Arg> mf = std::mem_fun(func);
00069       typename ColT::iterator iter = col.begin();
00070       for(;iter != col.end();++iter)
00071       {
00072          mf(*iter,arg);
00073       }
00074    }
00075 
00076 
00079    template <typename K,typename V,typename Arg>
00080    void DtCallMemberFunction(std::map<K,V>& col,void (V::*func)(Arg),Arg arg)
00081    {
00082       std::mem_fun1_t<void,V,Arg> mf = std::mem_fun(func);
00083       typename std::map<K,V>::iterator iter = col.begin();
00084       for(;iter != col.end();++iter)
00085       {
00086          mf(iter->second,arg);
00087       }
00088    }
00089 
00092    template <typename K,typename V,typename Arg>
00093       void DtCallMemberFunction(std::map<K,V*>& col,void (V::*func)(Arg),Arg arg)
00094    {
00095       std::mem_fun1_t<void,V,Arg> mf = std::mem_fun(func);
00096       typename std::map<K,V*>::iterator iter = col.begin();
00097       for(;iter != col.end();++iter)
00098       {
00099          mf(iter->second,arg);
00100       }
00101    }
00102 
00103    template <typename T>
00104    void DtDeletePointerAndClear(T& col)
00105    {
00106       typename T::const_iterator iter = col.begin();
00107       for(;iter != col.end();++iter)
00108       {
00109          delete *iter;
00110       }
00111       col.clear();
00112    }
00113 
00114    template <typename T>
00115       void DtDeleteArrayAndClear(T& col)
00116    {
00117       typename T::const_iterator iter = col.begin();
00118       for(;iter != col.end();++iter)
00119       {
00120          delete[] *iter;
00121       }
00122       col.clear();
00123    }
00124 
00125    template <typename K,typename V>
00126    void DtDeletePointerAndClear(std::map<K,V>& col)
00127    {
00128       typename std::map<K,V>::const_iterator iter = col.begin();
00129       for(;iter != col.end();++iter)
00130       {
00131          delete iter->second;
00132       }
00133       col.clear();
00134    }
00135 
00136    template <typename K,typename V>
00137    void DtDeleteArrayAndClear(std::map<K,V>& col)
00138    {
00139       typename std::map<K,V>::const_iterator iter = col.begin();
00140       for(;iter != col.end();++iter)
00141       {
00142          delete[] iter->second;
00143       }
00144       col.clear();
00145    }
00146 }
00147 
00148 #endif

Document ID: Generated on Tue Oct 11 19:41:03 EDT 2011 from SVN revision 107422
Copyright © 2005-2011 VT MÄK Inc. All Rights Reserved (www.mak.com)