00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
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__