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 \
43  int main(int argc, char** argv) { \
44  bool result = SampleMain(argc, argv); \
45  nlib_printf(result ? "OK\n" : "NG\n"); \
46  return result ? 0 : 1; \
47  }
48 #ifndef __cpp_exceptions
49 #define __cpp_exceptions 199711L
50 #endif
51 
52 #if 0
53 // Klocwork likes it better than crtdbg.h
54 #include <cassert>
55 #define NLIB_ASSERT assert
56 #else
57 #define NLIB_ASSERT _ASSERT
58 #endif
59 
60 #ifdef _DEBUG
61 #define NLIB_ASSERT_NOERR(e) \
62  (void)(((e) == 0) || \
63  (1 != _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, nullptr, "%s", \
64  nlib_error_string(e))) || \
65  (_CrtDbgBreak(), 0))
66 #else
67 #define NLIB_ASSERT_NOERR(e) ((void)0)
68 #endif
69 
70 #define NLIB_ALIGNAS(x) __declspec(align(x))
71 #define NLIB_ALIGNOF(tp) __alignof(tp)
72 #endif
73 
74 #ifdef _DEBUG
75 NLIB_NAMESPACE_BEGIN
76 
77 class NlibMemChecker {
78  public:
79  __declspec(noinline) NlibMemChecker() { _CrtMemCheckpoint(&s1_); }
80  __declspec(noinline) void Start() { _CrtMemCheckpoint(&s1_); }
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) \
99  namespace { \
100  char NoEmptyFileDummy##L; \
101  }
102 #define NLIB_NOEMPTYFILE_1(L) NLIB_NOEMPTYFILE_2(L)
103 #define NLIB_NOEMPTYFILE() NLIB_NOEMPTYFILE_1(__LINE__)
104 
105 #define NLIB_HAS_VIRTUALMEMORY
106 
107 #ifdef __cpp_exceptions
108 #define NLIB_THREAD_EXIT_CPP_THROW_NLIB_EXCEPTION
109 #undef nlib_thread_cleanup_push
110 #undef nlib_thread_cleanup_pop
111 #define nlib_thread_cleanup_push(fn, arg) \
112  switch (0) \
113  case 0: \
114  default: { \
115  __pragma(warning(push)) __pragma(warning( \
116  disable : 4456)) struct nlib_thread_cleanup_handler_ _thread_cleanup_handler = { \
117  fn, arg, nullptr}; \
118  __pragma(warning(pop)) nlib_thread_cleanup_push_(&_thread_cleanup_handler); \
119  try {
120 #define nlib_thread_cleanup_pop(exec) \
121  } \
122  catch (...) { \
123  nlib_thread_cleanup_pop_(1); \
124  throw; \
125  } \
126  nlib_thread_cleanup_pop_(exec); \
127  }
128 #endif
129 
130 #endif // INCLUDE_NN_NLIB_CONFIG_WIN32_H_