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(nullptr, &dir[0], 1024); \
36
*const_cast<char*>(nlib_strrchr(dir, '\\')) = '\0'; \
37
g_pathmapper.AddMap(dir, "nlibpath:
38
g_pathmapper.AddMap(dir, "nlibpath:
39
SetCurrentDirectoryA(dir); \
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
#define __cpp_exceptions 199711L
47
48
#if 0
49
// Klocwork likes it better than crtdbg.h
50
#include <cassert>
// NOLINT
51
#define NLIB_ASSERT assert
52
#else
53
#define NLIB_ASSERT _ASSERT
54
#endif
55
56
#ifdef _DEBUG
57
#define NLIB_ASSERT_NOERR(e) \
58
(void) (((e) == 0) || \
59
(1 != _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, nullptr, \
60
"%s", nlib_error_string(e))) || \
61
(_CrtDbgBreak(), 0))
62
#else
63
#define NLIB_ASSERT_NOERR(e) ((void)0)
64
#endif
65
66
#define NLIB_ALIGNAS(x) __declspec(align(x))
67
#define NLIB_ALIGNOF(tp) __alignof(tp)
68
#endif
69
70
#ifdef _DEBUG
71
NLIB_NAMESPACE_BEGIN
72
73
class
NlibMemChecker {
74
public
:
75
__declspec(noinline) NlibMemChecker() {
76
_CrtMemCheckpoint(&s1_);
77
}
78
__declspec(noinline)
void
Start() {
79
_CrtMemCheckpoint(&s1_);
80
}
81
__declspec(noinline)
bool
Check() {
82
_CrtMemState s2, s3;
83
_CrtMemCheckpoint(&s2);
84
return
!_CrtMemDifference( &s3, &s1_, &s2);
85
}
86
87
private
:
88
_CrtMemState s1_;
89
};
90
91
#define NLIB_MEMCHECKER ::nlib_ns::NlibMemChecker nlib_memchecker_
92
#define NLIB_MEMCHECKER_START nlib_memchecker_.Start()
93
#define NLIB_MEMCHECKER_CHECK nlib_memchecker_.Check()
94
95
NLIB_NAMESPACE_END
96
#endif
97
98
#define NLIB_NOEMPTYFILE_2(L) namespace { char NoEmptyFileDummy ## L; } // NOLINT
99
#define NLIB_NOEMPTYFILE_1(L) NLIB_NOEMPTYFILE_2(L)
100
#define NLIB_NOEMPTYFILE() NLIB_NOEMPTYFILE_1(__LINE__)
101
102
#define NLIB_HAS_VIRTUALMEMORY
103
104
#define NLIB_THREAD_EXIT_CPP_THROW_NLIB_EXCEPTION
105
#ifdef __cpp_exceptions
106
#undef nlib_thread_cleanup_push
107
#undef nlib_thread_cleanup_pop
108
#define nlib_thread_cleanup_push(fn, arg) switch (0) case 0: default: { \
109
__pragma(warning(push)) \
110
__pragma(warning(disable:4456)) \
111
struct nlib_thread_cleanup_handler_ _thread_cleanup_handler = { fn, arg, nullptr }; \
112
__pragma(warning(pop)) \
113
nlib_thread_cleanup_push_(&_thread_cleanup_handler); try {
114
#define nlib_thread_cleanup_pop(exec) } catch(...) { nlib_thread_cleanup_pop_(1); throw; } \
115
nlib_thread_cleanup_pop_(exec); }
116
#endif
117
118
#endif // INCLUDE_NN_NLIB_CONFIG_WIN32_H_
© 2012-2017 Nintendo Co., Ltd. All rights reserved.