OSDN Git Service

DTXMania089リリースに際してのtag付け。
[dtxmania/dtxmania.git] / 110401(DTXMania089) / SlimDXc_Jun2010(VC++2008) / source / direct3d9 / Macro.cpp
1 #include "stdafx.h"\r
2 /*\r
3 * Copyright (c) 2007-2010 SlimDX Group\r
4\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy\r
6 * of this software and associated documentation files (the "Software"), to deal\r
7 * in the Software without restriction, including without limitation the rights\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
9 * copies of the Software, and to permit persons to whom the Software is\r
10 * furnished to do so, subject to the following conditions:\r
11\r
12 * The above copyright notice and this permission notice shall be included in\r
13 * all copies or substantial portions of the Software.\r
14\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
21 * THE SOFTWARE.\r
22 */\r
23 #include <d3d9.h>\r
24 #include <d3dx9.h>\r
25 #include <vcclr.h>\r
26 \r
27 #include "../stack_array.h"\r
28 \r
29 #include "Macro.h"\r
30 \r
31 using namespace System;\r
32 using namespace System::Runtime::InteropServices;\r
33 \r
34 namespace SlimDX\r
35 {\r
36 namespace Direct3D9\r
37 {\r
38         bool Macro::operator == ( Macro left, Macro right )\r
39         {\r
40                 return Macro::Equals( left, right );\r
41         }\r
42 \r
43         bool Macro::operator != ( Macro left, Macro right )\r
44         {\r
45                 return !Macro::Equals( left, right );\r
46         }\r
47 \r
48         int Macro::GetHashCode()\r
49         {\r
50                 return Name->GetHashCode() + Definition->GetHashCode();\r
51         }\r
52 \r
53         bool Macro::Equals( Object^ value )\r
54         {\r
55                 if( value == nullptr )\r
56                         return false;\r
57 \r
58                 if( value->GetType() != GetType() )\r
59                         return false;\r
60 \r
61                 return Equals( safe_cast<Macro>( value ) );\r
62         }\r
63 \r
64         bool Macro::Equals( Macro value )\r
65         {\r
66                 return ( Name == value.Name && Definition == value.Definition );\r
67         }\r
68 \r
69         bool Macro::Equals( Macro% value1, Macro% value2 )\r
70         {\r
71                 return ( value1.Name == value2.Name && value1.Definition == value2.Definition );\r
72         }\r
73 \r
74         // helper function to resolve array<Macro>^ to D3DXMACRO*\r
75         stack_array<D3DXMACRO> Macro::Marshal( array<Macro>^ macros, [Out] array<GCHandle>^% handles )\r
76         {\r
77                 if( macros == nullptr )\r
78                 {\r
79                         handles = nullptr;\r
80                         return stack_array<D3DXMACRO>();\r
81                 }\r
82 \r
83                 //this array is null terminated, so we need to patch in an extra value\r
84                 stack_array<D3DXMACRO> result( macros->Length + 1 );\r
85                 handles = gcnew array<GCHandle>( macros->Length * 2 );\r
86 \r
87                 for( int i = 0; i < macros->Length; ++i )\r
88                 {\r
89                         array<Byte>^ nameBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( macros[i].Name );\r
90                         array<Byte>^ defBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( macros[i].Definition );\r
91 \r
92                         handles[2 * i] = GCHandle::Alloc( nameBytes, GCHandleType::Pinned );\r
93                         handles[2 * i + 1] = GCHandle::Alloc( defBytes, GCHandleType::Pinned );\r
94 \r
95                         result[i].Name = reinterpret_cast<LPCSTR>( handles[2 * i].AddrOfPinnedObject().ToPointer() );\r
96                         result[i].Definition = reinterpret_cast<LPCSTR>( handles[2 * i + 1].AddrOfPinnedObject().ToPointer() );\r
97                 }\r
98 \r
99                 result[macros->Length].Name = NULL;\r
100                 result[macros->Length].Definition = NULL;\r
101 \r
102                 return result;\r
103         }\r
104 \r
105         void Macro::Unmarshal( array<GCHandle>^ handles )\r
106         {\r
107                 if( handles != nullptr )\r
108                 {\r
109                         for( int i = 0; i < handles->Length; ++i )\r
110                                 handles[i].Free();\r
111                 }\r
112         }\r
113 }\r
114 }