YSTest: ycommon.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
ycommon.cpp
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2009 - 2013.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "YCLib/Debug.h"
29 #include <cstring>
30 #include <cerrno>
31 #include "YCLib/NativeAPI.h"
32
33 namespace platform
34 {
35
36 void
37 terminate() ynothrow
38 {
39 #if YCL_DS
40 for(;;)
41 ::swiWaitForVBlank();
42 #else
43 std::terminate();
44 #endif
45 }
46
47
48 #ifdef YB_USE_YASSERT
49
50 void
51 yassert(bool exp, const char* expstr, const char* message,
52 int line, const char* file)
53 {
54 if(YB_UNLIKELY(!exp))
55 {
56 yprintf("Assertion failed: \n"
57 "%s\nMessage: \n%s\nAt line %i in file \"%s\".\n",
58 expstr, message, line, file);
59 std::abort();
60 }
61 }
62
63 #endif
64
65 }
66
67 namespace platform_ex
68 {
69
70 #if YCL_DS
71 bool
72 AllowSleep(bool b)
73 {
74 static bool bSleepEnabled(true); //与 libnds 默认的 ARM7 电源管理同步。
75 const bool b_old(bSleepEnabled);
76
77 if(b != bSleepEnabled)
78 {
79 bSleepEnabled = b;
80 ::fifoSendValue32(FIFO_PM,
81 b ? PM_REQ_SLEEP_ENABLE : PM_REQ_SLEEP_DISABLE);
82 }
83 return b_old;
84 }
85 #elif YCL_MINGW32
86 std::string
87 UTF8ToMBCS(const char* str, std::size_t len, int cp)
88 {
89 if(cp == CP_UTF8)
90 return str;
91
92 const int w_len(::MultiByteToWideChar(CP_UTF8, 0, str, len, nullptr, 0));
93 std::wstring wstr(w_len, wchar_t());
94 wchar_t* w_str = &wstr[0];
95
96 ::MultiByteToWideChar(CP_UTF8, 0, str, len, w_str, w_len);
97
98 return WCSToMBCS(w_str, w_len, cp);
99 }
100
101 std::string
102 WCSToMBCS(const wchar_t* str, std::size_t len, int cp)
103 {
104 const int r_len(::WideCharToMultiByte(cp, 0, str, len,
105 nullptr, 0, nullptr, nullptr));
106 std::string mbcs(r_len, char());
107
108 ::WideCharToMultiByte(cp, 0, str, len, &mbcs[0], r_len, nullptr, nullptr);
109 return mbcs;
110 }
111 #endif
112
113 }
114