Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

StdAfx.h

Go to the documentation of this file.
00001 //
00002 // StdAfx.h
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #pragma once
00023 
00024 //
00025 // Configuration
00026 //
00027 
00028 #define WINVER                  0x0500          // Windows Version
00029 #define _WIN32_WINDOWS  0x0500          // Windows Version
00030 #define _WIN32_WINNT    0x0500          // NT Version
00031 #define _WIN32_IE               0x0500          // IE Version
00032 #define _WIN32_DCOM                                     // DCOM
00033 #define _AFX_NO_RICHEDIT_SUPPORT        // No RichEdit
00034 
00035 //
00036 // MFC
00037 //
00038 
00039 #include <afxwin.h>         // MFC core and standard components
00040 #include <afxext.h>         // MFC extensions
00041 #include <afxcmn.h>                     // MFC support for Windows Common Controls
00042 #include <afxtempl.h>           // MFC templates
00043 #include <afxmt.h>                      // MFC threads
00044 #include <afxole.h>                     // MFC OLE
00045 #include <afxocc.h>                     // MDC OCC
00046 #include <afxhtml.h>            // MFC HTML
00047 
00048 //
00049 // WIN32
00050 //
00051 
00052 #include <winsock2.h>           // Windows sockets V2
00053 #include <objbase.h>            // OLE
00054 #include <shlobj.h>                     // Shell objects
00055 #include <wininet.h>            // Internet
00056 #include <ddeml.h>                      // DDE
00057 #include <math.h>                       // Math
00058 
00059 #undef IDC_HAND
00060 
00061 //
00062 // Missing constants
00063 //
00064 
00065 #define BIF_NEWDIALOGSTYLE      0x0040
00066 #define OFN_ENABLESIZING        0x00800000
00067 
00068 #undef NULL
00069 #undef min
00070 #undef max
00071 
00072 //
00073 // Standard headers
00074 //
00075 
00076 #include <algorithm>
00077 #undef NULL
00078 
00079 const int NULL = 0;
00080 using std::min;
00081 using std::max;
00082 
00083 //
00084 // 64-bit type
00085 //
00086 
00087 typedef unsigned __int64 QWORD;
00088 
00089 //
00090 // Tristate type
00091 //
00092 
00093 typedef int TRISTATE;
00094 
00095 #define TS_UNKNOWN      0
00096 #define TS_FALSE        1
00097 #define TS_TRUE         2
00098 
00099 //
00100 // GUID
00101 //
00102 
00103 typedef union
00104 {
00105         BYTE    n[16];
00106         BYTE    b[16];
00107         DWORD   w[4];
00108 } GGUID;
00109 
00110 inline bool operator==(const GGUID& guidOne, const GGUID& guidTwo)
00111 {
00112    return (
00113       ((PLONG)&guidOne)[0] == ((PLONG)&guidTwo)[0] &&
00114       ((PLONG)&guidOne)[1] == ((PLONG)&guidTwo)[1] &&
00115       ((PLONG)&guidOne)[2] == ((PLONG)&guidTwo)[2] &&
00116       ((PLONG)&guidOne)[3] == ((PLONG)&guidTwo)[3] );
00117 }
00118 
00119 inline bool operator!=(const GGUID& guidOne, const GGUID& guidTwo)
00120 {
00121    return (
00122       ( (PLONG)&guidOne)[0] != ((PLONG)&guidTwo)[0] ||
00123       ( (PLONG)&guidOne)[1] != ((PLONG)&guidTwo)[1] ||
00124       ( (PLONG)&guidOne)[2] != ((PLONG)&guidTwo)[2] ||
00125       ( (PLONG)&guidOne)[3] != ((PLONG)&guidTwo)[3] );
00126 }
00127 
00128 #define SIZE_UNKNOWN    0xFFFFFFFFFFFFFFFF
00129 
00130 //
00131 // Hash values
00132 //
00133 
00134 typedef union
00135 {
00136         BYTE    n[20];
00137         BYTE    b[20];
00138 } SHA1;
00139 
00140 typedef union
00141 {
00142         BYTE    n[24];
00143         BYTE    b[24];
00144         QWORD   w[3];
00145 } TIGEROOT;
00146 
00147 typedef union
00148 {
00149         BYTE    n[16];
00150         BYTE    b[16];
00151         DWORD   w[4];
00152 } MD4, MD5;
00153 
00154 #define HASH_NULL               0
00155 #define HASH_SHA1               1
00156 #define HASH_MD5                2
00157 #define HASH_TIGERTREE  3
00158 #define HASH_ED2K               4
00159 #define HASH_TORRENT    5
00160 
00161 //
00162 // Protocol IDs
00163 //
00164 
00165 typedef int PROTOCOLID;
00166 
00167 #define PROTOCOL_NULL   0
00168 #define PROTOCOL_G1             1
00169 #define PROTOCOL_G2             2
00170 #define PROTOCOL_ED2K   3
00171 
00172 #define PROTOCOL_HTTP   4
00173 #define PROTOCOL_FTP    5
00174 #define PROTOCOL_BT             6
00175 
00176 class CQuickLock
00177 {
00178 public:
00179         explicit CQuickLock(CSyncObject& oMutex) : m_oMutex( oMutex ) { oMutex.Lock(); }
00180         ~CQuickLock() { m_oMutex.Unlock(); }
00181 private:
00182         CSyncObject& m_oMutex;
00183         CQuickLock(const CQuickLock&);
00184         CQuickLock& operator=(const CQuickLock&);
00185         static void* operator new(std::size_t);
00186         static void* operator new[](std::size_t);
00187         static void operator delete(void*);
00188         static void operator delete[](void*);
00189         CQuickLock* operator&();
00190 };
00191 
00192 template< class T >
00193 class CGuarded
00194 {
00195 public:
00196         explicit CGuarded() : m_oSection(), m_oValue() { }
00197         explicit CGuarded(const CGuarded& other) : m_oSection(), m_oValue( other ) { }
00198         CGuarded(const T& oValue) : m_oSection(), m_oValue( oValue ) { }
00199         CGuarded& operator=(const T& oValue)
00200         {
00201                 CQuickLock oLock( m_oSection );
00202                 m_oValue = oValue;
00203                 return *this;
00204         }
00205         operator T() const
00206         {
00207                 CQuickLock oLock( m_oSection );
00208                 return m_oValue;
00209         }
00210 private:
00211         mutable CCriticalSection m_oSection;
00212         T m_oValue;
00213         CGuarded* operator&(); // too unsafe
00214 };
00215 
00216 class CLowerCaseTable
00217 {
00218 public:
00219         explicit CLowerCaseTable()
00220         {
00221                 for ( size_t i = 0 ; i < 65536 ; ++i ) cTable[ i ] = i;
00222                 cTable[ 65536 ] = 0;
00223                 CharLower( &cTable[ 1 ] );
00224                 cTable[ 304 ] = 105; // turkish capital I with dot is converted to "i"
00225                 // convert fullwidth characters to halfwidth
00226                 for ( size_t i = 65281 ; i < 65313 ; ++i ) cTable[ i ] = i - 65248;
00227                 for ( size_t i = 65313 ; i < 65339 ; ++i ) cTable[ i ] = i - 65216;
00228                 for ( size_t i = 65339 ; i < 65375 ; ++i ) cTable[ i ] = i - 65248;
00229         };
00230         const TCHAR& operator()(const TCHAR cLookup) const { return cTable[ cLookup ]; }
00231         const TCHAR& operator[](const TCHAR cLookup) const { return ( *this )( cLookup ); }
00232 private:
00233         TCHAR CLowerCaseTable::cTable[ 65537 ];
00234 };
00235 
00236 const CLowerCaseTable ToLowerCase;

Generated on Thu Dec 15 10:39:50 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2