Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
244 chris 1
#ifndef __SEXYAPPFRAMEWORK_COMMON_H__
2
#define __SEXYAPPFRAMEWORK_COMMON_H__
3
 
4
#pragma warning(disable:4786)
5
#pragma warning(disable:4503)
6
 
7
#undef _WIN32_WINNT
8
#undef WIN32_LEAN_AND_MEAN
9
 
10
#define WIN32_LEAN_AND_MEAN
11
#define _WIN32_WINNT 0x0500
12
#undef _UNICODE
13
#undef UNICODE
14
 
15
#include <string>
16
#include <vector>
17
#include <set>
18
#include <map>
19
#include <list>
20
#include <algorithm>
21
#include <cstdlib>
22
 
23
#include <windows.h>
24
#include <shellapi.h> 
25
#include <mmsystem.h>
26
#include "ModVal.h"
27
 
28
#ifdef _USE_WIDE_STRING
29
 
30
typedef std::wstring            SexyString;
31
#define _S(x)                           L ##x
32
 
33
 
34
#define sexystrncmp                     wcsncmp
35
#define sexystrcmp                      wcscmp
36
#define sexystricmp                     wcsicmp
37
#define sexysscanf                      swscanf
38
#define sexyatoi                        _wtoi
39
#define sexystrcpy                      wcscpy
40
 
41
#define SexyStringToStringFast(x)       WStringToString(x)
42
#define SexyStringToWStringFast(x)      (x)
43
#define StringToSexyStringFast(x)       StringToWString(x)
44
#define WStringToSexyStringFast(x)      (x)
45
 
46
#ifndef SEXYFRAMEWORK_NO_REDEFINE_WIN_API
47
// Redefine the functions and structs we need to be wide-string
48
#undef CreateWindowEx
49
#undef RegisterClass
50
#undef MessageBox
51
#undef ShellExecute
52
#undef GetTextExtentPoint32
53
#undef RegisterWindowMessage
54
#undef CreateMutex
55
#undef DrawTextEx
56
#undef TextOut
57
 
58
#define CreateWindowEx                          CreateWindowExW
59
#define RegisterClass                           RegisterClassW
60
#define WNDCLASS                                        WNDCLASSW
61
#define MessageBox                                      MessageBoxW
62
#define ShellExecute                            ShellExecuteW
63
#define GetTextExtentPoint32            GetTextExtentPoint32W
64
#define RegisterWindowMessage           RegisterWindowMessageW
65
#define CreateMutex                                     CreateMutexW
66
#define DrawTextEx                                      DrawTextExW
67
#define TextOut                                         TextOutW
68
#endif
69
 
70
#else
71
 
72
typedef std::string                     SexyString;
73
#define _S(x)                           x
74
 
75
 
76
#define sexystrncmp                     strncmp
77
#define sexystrcmp                      strcmp
78
#define sexystricmp                     stricmp
79
#define sexysscanf                      sscanf
80
#define sexyatoi                        atoi
81
#define sexystrcpy                      strcpy
82
 
83
#define SexyStringToStringFast(x)       (x)
84
#define SexyStringToWStringFast(x)      StringToWString(x)
85
#define StringToSexyStringFast(x)       (x)
86
#define WStringToSexyStringFast(x)      WStringToString(x)
87
 
88
#endif
89
 
90
#define LONG_BIGE_TO_NATIVE(l) (((l >> 24) & 0xFF) | ((l >> 8) & 0xFF00) | ((l << 8) & 0xFF0000) | ((l << 24) & 0xFF000000))
91
#define WORD_BIGE_TO_NATIVE(w) (((w >> 8) & 0xFF) | ((w << 8) & 0xFF00))
92
#define LONG_LITTLEE_TO_NATIVE(l) (l)
93
#define WORD_LITTLEE_TO_NATIVE(w) (w)
94
 
95
#define LENGTH(anyarray) (sizeof(anyarray) / sizeof(anyarray[0]))
96
 
97
typedef unsigned char uchar;
98
typedef unsigned short ushort;
99
typedef unsigned int uint;
100
typedef unsigned long ulong;
101
typedef __int64 int64;
102
 
103
typedef std::map<std::string, std::string>              DefinesMap;
104
typedef std::map<std::wstring, std::wstring>    WStringWStringMap;
105
typedef SexyString::value_type                                  SexyChar;
106
#define HAS_SEXYCHAR
107
 
108
namespace Sexy
109
{
110
 
111
const ulong SEXY_RAND_MAX = 0x7FFFFFFF;
112
 
113
extern bool                     gDebug;
114
extern HINSTANCE        gHInstance;
115
 
116
int                                     Rand();
117
int                                     Rand(int range);
118
float                           Rand(float range);
119
void                            SRand(ulong theSeed);
120
extern std::string      vformat(const char* fmt, va_list argPtr);
121
extern std::wstring     vformat(const wchar_t* fmt, va_list argPtr);
122
extern std::string      StrFormat(const char* fmt ...);
123
extern std::wstring     StrFormat(const wchar_t* fmt ...);
124
bool                            CheckFor98Mill();
125
bool                            CheckForVista();
126
std::string                     GetAppDataFolder();
127
void                            SetAppDataFolder(const std::string& thePath);
128
std::string                     URLEncode(const std::string& theString);
129
std::string                     StringToUpper(const std::string& theString);
130
std::wstring            StringToUpper(const std::wstring& theString);
131
std::string                     StringToLower(const std::string& theString);
132
std::wstring            StringToLower(const std::wstring& theString);
133
std::wstring            StringToWString(const std::string &theString);
134
std::string                     WStringToString(const std::wstring &theString);
135
SexyString                      StringToSexyString(const std::string& theString);
136
SexyString                      WStringToSexyString(const std::wstring& theString);
137
std::string                     SexyStringToString(const SexyString& theString);
138
std::wstring            SexyStringToWString(const SexyString& theString);
139
std::string                     Upper(const std::string& theData);
140
std::wstring            Upper(const std::wstring& theData);
141
std::string                     Lower(const std::string& theData);
142
std::wstring            Lower(const std::wstring& theData);
143
std::string                     Trim(const std::string& theString);
144
std::wstring            Trim(const std::wstring& theString);
145
bool                            StringToInt(const std::string theString, int* theIntVal);
146
bool                            StringToDouble(const std::string theString, double* theDoubleVal);
147
bool                            StringToInt(const std::wstring theString, int* theIntVal);
148
bool                            StringToDouble(const std::wstring theString, double* theDoubleVal);
149
int                                     StrFindNoCase(const char *theStr, const char *theFind);
150
bool                            StrPrefixNoCase(const char *theStr, const char *thePrefix, int maxLength = 10000000);
151
SexyString                      CommaSeperate(int theValue);
152
std::string                     Evaluate(const std::string& theString, const DefinesMap& theDefinesMap);
153
std::string                     XMLDecodeString(const std::string& theString);
154
std::string                     XMLEncodeString(const std::string& theString);
155
std::wstring            XMLDecodeString(const std::wstring& theString);
156
std::wstring            XMLEncodeString(const std::wstring& theString);
157
 
158
bool                            Deltree(const std::string& thePath);
159
bool                            FileExists(const std::string& theFileName);
160
void                            MkDir(const std::string& theDir);
161
std::string                     GetFileName(const std::string& thePath, bool noExtension = false);
162
std::string                     GetFileDir(const std::string& thePath, bool withSlash = false);
163
std::string                     RemoveTrailingSlash(const std::string& theDirectory);
164
std::string                     AddTrailingSlash(const std::string& theDirectory, bool backSlash = false);
165
time_t                          GetFileDate(const std::string& theFileName);
166
std::string                     GetCurDir();
167
std::string                     GetFullPath(const std::string& theRelPath);
168
std::string                     GetPathFrom(const std::string& theRelPath, const std::string& theDir);
169
bool                            AllowAllAccess(const std::string& theFileName);
170
 
171
 
172
inline void                     inlineUpper(std::string &theData)
173
{
174
    //std::transform(theData.begin(), theData.end(), theData.begin(), toupper);
175
 
176
        int aStrLen = (int) theData.length();
177
        for (int i = 0; i < aStrLen; i++)
178
        {
179
                theData[i] = toupper(theData[i]);
180
        }
181
}
182
 
183
inline void                     inlineUpper(std::wstring &theData)
184
{
185
    //std::transform(theData.begin(), theData.end(), theData.begin(), toupper);
186
 
187
        int aStrLen = (int) theData.length();
188
        for (int i = 0; i < aStrLen; i++)
189
        {
190
                theData[i] = towupper(theData[i]);
191
        }
192
}
193
 
194
inline void                     inlineLower(std::string &theData)
195
{
196
    std::transform(theData.begin(), theData.end(), theData.begin(), tolower);
197
}
198
 
199
inline void                     inlineLower(std::wstring &theData)
200
{
201
    std::transform(theData.begin(), theData.end(), theData.begin(), tolower);
202
}
203
 
204
inline void                     inlineLTrim(std::string &theData, const std::string& theChars = " \t\r\n")
205
{
206
    theData.erase(0, theData.find_first_not_of(theChars));
207
}
208
 
209
inline void                     inlineLTrim(std::wstring &theData, const std::wstring& theChars = L" \t\r\n")
210
{
211
    theData.erase(0, theData.find_first_not_of(theChars));
212
}
213
 
214
 
215
inline void                     inlineRTrim(std::string &theData, const std::string& theChars = " \t\r\n")
216
{
217
    theData.resize(theData.find_last_not_of(theChars) + 1);
218
}
219
 
220
inline void                     inlineTrim(std::string &theData, const std::string& theChars = " \t\r\n")
221
{
222
        inlineRTrim(theData, theChars);
223
        inlineLTrim(theData, theChars);
224
}
225
 
226
struct StringLessNoCase { bool operator()(const std::string &s1, const std::string &s2) const { return _stricmp(s1.c_str(),s2.c_str())<0; } };
227
 
228
}
229
 
230
#endif //__SEXYAPPFRAMEWORK_COMMON_H__