OSDN Git Service

リセット
[momiji/momiji_main.git] / Core / Momiji.Util.h
1 /*
2 [momiji music component library]
3 ---------------------------------------------------------------------
4 Momiji.Sequencer.Midi.Smf.h
5         stream component of standard midi file.
6 ---------------------------------------------------------------------
7 Copyright (C) 2011 tyiki badwell {miria@users.sourceforge.jp}.
8
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program.  If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
21 ---------------------------------------------------------------------
22 */
23 #pragma once
24
25 #using <mscorlib.dll>
26
27 using namespace System::Runtime;
28
29 namespace Momiji{
30         /**
31         <remarks>
32         ユーティリティクラス(未整理ロジック)
33         </remarks>
34         */
35         value class Util
36         {
37         public:
38                 /**
39                 <summary>
40                 ntohs
41                 </summary>
42                 <param name="data">ビッグエンディアンの2バイトデータ</param>
43                 <returns>システムがリトルエンディアンであれば、変換して返す。</returns>
44                 */
45                 static System::UInt16 ToHostOrder(System::UInt16 data)
46                 {
47                         if (System::BitConverter::IsLittleEndian)
48                         {
49                                 return safe_cast<System::UInt16>(
50                                         ((data >> 8) & 0x00FF) | 
51                                         ((data << 8) & 0xFF00)
52                                         );
53                         }
54                         return data;
55                 };
56
57                 /**
58                 <summary>
59                 ntohl
60                 </summary>
61                 <param name="data">ビッグエンディアンの4バイトデータ</param>
62                 <returns>システムがリトルエンディアンであれば、変換して返す。</returns>
63                 */
64                 static System::UInt32 ToHostOrder(System::UInt32 data)
65                 {
66                         if (System::BitConverter::IsLittleEndian)
67                         {
68                                 return (
69                                         ((data >> 24) & 0x000000FFL) |
70                                         ((data >> 8 ) & 0x0000FF00L) |
71                                         ((data << 8 ) & 0x00FF0000L) |
72                                         ((data << 24) & 0xFF000000L)
73                                         );
74                         }
75                         return data;
76                 };
77         };
78
79 }