Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

util.h

00001 /*
00002   Copyright (c) 2007-2008 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 #ifndef UTIL_H__
00014 #define UTIL_H__
00015 
00016 #include "gloox.h"
00017 
00018 #include <string>
00019 #include <list>
00020 #include <map>
00021 
00022 namespace gloox
00023 {
00024 
00028   namespace util
00029   {
00030 
00031     #define lookup( a, b ) _lookup( a, b, sizeof(b)/sizeof(char*) )
00032     #define lookup2( a, b ) _lookup2( a, b, sizeof(b)/sizeof(char*) )
00033     #define deflookup( a, b, c ) _lookup( a, b, sizeof(b)/sizeof(char*), c )
00034     #define deflookup2( a, b, c ) _lookup2( a, b, sizeof(b)/sizeof(char*), c )
00035 
00043     unsigned _lookup( const std::string& str, const char* values[],
00044                       unsigned size, int def = -1 );
00045 
00053     const std::string _lookup( unsigned code, const char* values[],
00054                                unsigned size, const std::string& def = EmptyString );
00055 
00063     unsigned _lookup2( const std::string& str, const char* values[],
00064                               unsigned size, int def = -1 );
00065 
00073     const std::string _lookup2( unsigned code, const char* values[],
00074                                 unsigned size, const std::string& def = EmptyString );
00075 
00081     template< typename T, typename F >
00082     inline void ForEach( T& t, F f )
00083     {
00084       for( typename T::iterator it = t.begin(); it != t.end(); ++it )
00085         ( (*it)->*f )();
00086     }
00087 
00095     template< typename T, typename F, typename D >
00096     inline void ForEach( T& t, F f, D& d )
00097     {
00098       for( typename T::iterator it = t.begin(); it != t.end(); ++it )
00099         ( (*it)->*f )( d );
00100     }
00101 
00110     template< typename T, typename F, typename D1, typename D2 >
00111     inline void ForEach( T& t, F f, D1& d1, D2& d2 )
00112     {
00113       for( typename T::iterator it = t.begin(); it != t.end(); ++it )
00114         ( (*it)->*f )( d1, d2 );
00115     }
00116 
00126     template< typename T, typename F, typename D1, typename D2, typename D3 >
00127     inline void ForEach( T& t, F f, D1& d1, D2& d2, D3& d3 )
00128     {
00129       for( typename T::iterator it = t.begin(); it != t.end(); ++it )
00130         ( (*it)->*f )( d1, d2, d3 );
00131     }
00132 
00137 //     template< typename T >
00138 //     inline void clearList( std::list< T* >& L )
00139 //     {
00140 //       typename std::list< T* >::iterator it = L.begin();
00141 //       typename std::list< T* >::iterator it2;
00142 //       while( it != L.end() )
00143 //       {
00144 //         it2 = it++;
00145 //         delete (*it2);
00146 //         L.erase( it2 );
00147 //       }
00148 //     }
00149 
00154 //     template< typename Key, typename T >
00155 //     inline void clearMap( std::map< Key, T* >& M )
00156 //     {
00157 //       typename std::map< Key, T* >::iterator it = M.begin();
00158 //       typename std::map< Key, T* >::iterator it2;
00159 //       while( it != M.end() )
00160 //       {
00161 //         it2 = it++;
00162 //         delete (*it2).second;
00163 //         M.erase( it2 );
00164 //       }
00165 //     }
00166 
00172 //     template< typename Key, typename T >
00173 //     inline void clearMap( std::map< const Key, T* >& M )
00174 //     {
00175 //       typename std::map< const Key, T* >::iterator it = M.begin();
00176 //       typename std::map< Key, T* >::iterator it2;
00177 //       while( it != M.end() )
00178 //       {
00179 //         it2 = it++;
00180 //         delete (*it2).second;
00181 //         M.erase( it2 );
00182 //       }
00183 //     }
00184 
00190     const std::string escape( std::string what );
00191 
00197     bool checkValidXMLChars( const std::string& data );
00198 
00204     int log2( unsigned int n );
00205   }
00206 
00207 }
00208 
00209 #endif // UTIL_H__

Generated on Mon Jun 23 10:50:20 2008 for gloox by  doxygen 1.4.1