You.i Engine
YiPredefAndroid.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_PREDEF_ANDROID_H_
3 #define _YI_PREDEF_ANDROID_H_
4 
5 #include <algorithm>
6 #include <cfloat>
7 #include <cstdio>
8 #include <cstdlib>
9 #include <cstring>
10 #include <ctime>
11 #include <cctype>
12 #include <fstream>
13 #include <iostream>
14 #include <iterator>
15 #include <list>
16 #include <map>
17 #include <queue>
18 #include <sstream>
19 #include <stack>
20 #include <unistd.h>
21 #include <vector>
22 #include <wchar.h>
23 
24 
30 // platform-dependant functions
31 // memory
32 #define YI_SYSTEM_FREE(a) free(a)
33 #define YI_SYSTEM_MALLOC(a) malloc(a)
34 #define YI_SYSTEM_REALLOC(a, b) realloc(a, b)
35 #define YI_MEMCMP(a, b, c) memcmp(a, b, c)
36 #define YI_MEMMOVE(a, b, c) memmove(a, b, c)
37 #define YI_MEMCOPY(a, b, c) memcpy(a, b, c)
38 #define YI_MEMSET(a, b, c) memset(a, b, c)
39 
40 // multi-byte string
41 // NOTE: To be used only when absolutely required.
42 // Wide strings are preferred
43 #define YI_STRCAT(a, b) strcat(a, b)
44 #define YI_STRCHR(a, b) strchr(a, b)
45 #define YI_STRCMP(a, b) strcmp(a, b)
46 #define YI_STRCPY(a, b) strcpy(a, b)
47 #define YI_STRUP(a) strdup(a)
48 #define YI_STRLEN(a) strlen(a)
49 #define YI_STRREV(a) STRREV(a)
50 #define YI_STRNCMP(a, b, c) strncmp(a, b, c)
51 #define YI_STRNICMP(a, b, c) strncmp(a, b, c)
52 #define YI_STRNCAT(a, b, c) strncat(a, b, c)
53 #define YI_STRNCPY(a, b, c) strncpy(a, b, c)
54 #define YI_STRRCHR(a, b) strrchr(a, b)
55 #define YI_STRTOUL(a, b, c) strtoul(a, b, c)
56 #define YI_VSNPRINTF(a, b, c, d) vsnprintf(a, b, c, d)
57 #define YI_STRICMP(a, b) strcmp(a, b)
58 #define YI_SPRINTF sprintf
59 #define YI_SNPRINTF snprintf
60 #define YI_ATOI(a) atoi(a)
61 #define YI_ATOF(a) atof(a)
62 
63 // wide string
64 
65 #define YI_WCSCPY(a, b) wcscpy( a, b)
66 #define YI_WCSNCPY(a, b, c) wcsncpy( a, b, (size_t)c)
67 #define YI_WCSCAT(a, b) wcscat( a, b)
68 #define YI_WCSLEN(a) (int32_t) wcslen(a)
69 #define YI_WCSREV(a) WCSREV( a)
70 #define YI_WCSCMP(a, b) wcscmp( a, b)
71 #define YI_WCSNCMP(a, b, c) wcsncmp( a, b, (size_t)c)
72 #define YI_WCSICMP(a, b) WCSICMP( a, b)
73 #define YI_WCSNICMP(a, b, c) WCSNICMP(a, b, (size_t)c)
74 #define YI_WCSNCAT(a, b, c) wcsncat(a, b, (size_t)c)
75 
76 #if _POSIX_C_SOURCE >= 199309L
77 inline void YI_SLEEP(long timeMs)
78 {
79  struct timespec ts;
80  ts.tv_sec = int(timeMs / 1000);
81  ts.tv_nsec = (timeMs % 1000) * 1000000;
82  nanosleep(&ts, NULL);
83 }
84 
85 inline void YI_USLEEP(long timeUs)
86 {
87  struct timespec ts;
88  ts.tv_sec = int(timeUs / 1000000);
89  ts.tv_nsec = (timeUs % 1000000) * 1000;
90  nanosleep(&ts, NULL);
91 }
92 #else
93 // usleep: This C routine is considered obsolete (as opposed to the shell
94 // command by the same name). The interaction of this function with SIGALRM and
95 // other timer functions such as sleep(), alarm(), setitimer(), and nanosleep()
96 // is unspecified (CWE-676). Use nanosleep(2) or setitimer(2) instead.
97 #define YI_SLEEP(x) usleep((x)*1000)
98 #define YI_USLEEP(x) usleep(x)
99 #endif
100 
101 //File handling
102 #define YI_FILE FILE
103 #define YI_FREAD (int32_t) fread
104 #define YI_FWRITE fwrite
105 #define YI_FGETC fgetc
106 #define YI_FPUTC fputc
107 
108 typedef void *HANDLE;
109 
110 // Android specific key codes
111 #define YI_KEYCODE_HOME_BUTTON 0x00000003
112 #define YI_KEYCODE_BACK_BUTTON 0x00000004
113 #define YI_HAS_VIRTUAL_KEYBOARD
114 
118 #endif // _YI_PREDEF_ANDROID_H_
#define YI_SLEEP(x)
Definition: YiPredefAndroid.h:97
void * HANDLE
Definition: YiPredefAndroid.h:108
#define YI_USLEEP(x)
Definition: YiPredefAndroid.h:98