nlib
Config_win32.h
1
2
/*--------------------------------------------------------------------------------*
3
Project: CrossRoad
4
Copyright (C)Nintendo All rights reserved.
5
6
These coded instructions, statements, and computer programs contain proprietary
7
information of Nintendo and/or its licensed developers and are protected by
8
national and international copyright laws. They may not be disclosed to third
9
parties or copied or duplicated in any form, in whole or in part, without the
10
prior written consent of Nintendo.
11
12
The content herein is highly confidential and should be handled accordingly.
13
*--------------------------------------------------------------------------------*/
14
15
#pragma once
16
#ifndef INCLUDE_NN_NLIB_CONFIG_WIN32_H_
17
#define INCLUDE_NN_NLIB_CONFIG_WIN32_H_
18
#ifndef INCLUDE_NN_NLIB_CONFIG_H_
19
# error do not include directly
20
#endif
21
22
#if defined(_MSC_VER)
23
24
#include <Windows.h>
25
#include <crtdbg.h>
26
#if _WIN32_WINNT < 0x601
27
# pragma message("Windows SDK is old. Please install Windows SDK 7.1 or higher.")
28
#endif
29
30
#define NLIB_PATHMAPPER_FORSAMPLE \
31
nlib_ns::NativePathMapper g_pathmapper; \
32
nlib_ns::NativePathMapper& g_PathMapper = g_pathmapper; \
33
inline void InitPathMapperForSample() { \
34
char dir[1024]; \
35
::GetModuleFileNameA(NULL, &dir[0], 1024); \
36
*const_cast<char*>(nlib_strrchr(dir, '\\')) = '\0'; \
37
*const_cast<char*>(nlib_strrchr(dir, '\\')) = '\0'; \
38
g_pathmapper.AddMap(dir, "nlibpath:
39
g_pathmapper.AddMap(dir, "nlibpath:
40
}
41
42
#define NLIB_MAINFUNC int main(int argc, char** argv) { \
43
bool result = SampleMain(argc, argv); nlib_printf(result ? "OK\n" : "NG\n"); \
44
return result ? 0 : 1; }
45
#define NLIB_EXCEPTION_ENABLED
46
47
#if 0
48
// Klocwork likes it better than crtdbg.h
49
#include <cassert>
// NOLINT
50
#define NLIB_ASSERT assert
51
#else
52
#define NLIB_ASSERT _ASSERT
53
#endif
54
55
#ifdef _DEBUG
56
#define NLIB_ASSERT_NOERR(e) \
57
(void) (((e) == 0) || \
58
(1 != _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, \
59
"%s", nlib_error_string(e))) || \
60
(_CrtDbgBreak(), 0))
61
#else
62
#define NLIB_ASSERT_NOERR(e) ((void)0)
63
#endif
64
65
#define NLIB_ALIGNAS(x) __declspec(align(x))
66
#define NLIB_ALIGNOF(tp) __alignof(tp)
67
#endif
68
69
#ifdef _DEBUG
70
NLIB_NAMESPACE_BEGIN
71
72
class
NlibMemChecker {
73
public
:
74
__declspec(noinline) NlibMemChecker() {
75
_CrtMemCheckpoint(&s1_);
76
}
77
__declspec(noinline)
void
Start() {
78
_CrtMemCheckpoint(&s1_);
79
}
80
__declspec(noinline)
bool
Check() {
81
_CrtMemState s2, s3;
82
_CrtMemCheckpoint(&s2);
83
return
!_CrtMemDifference( &s3, &s1_, &s2);
84
}
85
86
private
:
87
_CrtMemState s1_;
88
};
89
90
#define NLIB_MEMCHECKER ::nlib_ns::NlibMemChecker nlib_memchecker_
91
#define NLIB_MEMCHECKER_START nlib_memchecker_.Start()
92
#define NLIB_MEMCHECKER_CHECK nlib_memchecker_.Check()
93
94
NLIB_NAMESPACE_END
95
#endif
96
97
#define NLIB_NOEMPTYFILE_2(L) namespace { char NoEmptyFileDummy ## L; } // NOLINT
98
#define NLIB_NOEMPTYFILE_1(L) NLIB_NOEMPTYFILE_2(L)
99
#define NLIB_NOEMPTYFILE() NLIB_NOEMPTYFILE_1(__LINE__)
100
101
#define NLIB_HAS_VIRTUALMEMORY
102
103
#define NLIB_THREAD_EXIT_CPP_THROW_NLIB_EXCEPTION
104
#ifdef NLIB_EXCEPTION_ENABLED
105
#undef nlib_thread_cleanup_push
106
#undef nlib_thread_cleanup_pop
107
#define nlib_thread_cleanup_push(fn, arg) switch (0) case 0: default: { \
108
__pragma(warning(push)) \
109
__pragma(warning(disable:4456)) \
110
struct nlib_thread_cleanup_handler_ _thread_cleanup_handler = { fn, arg, NULL }; \
111
__pragma(warning(pop)) \
112
nlib_thread_cleanup_push_(&_thread_cleanup_handler); try {
113
#define nlib_thread_cleanup_pop(exec) } catch(...) { nlib_thread_cleanup_pop_(1); throw; } \
114
nlib_thread_cleanup_pop_(exec); }
115
#endif
116
117
#endif // INCLUDE_NN_NLIB_CONFIG_WIN32_H_
© 2012-2017 Nintendo Co., Ltd. All rights reserved.