3 * Copyright (c) 2007-2010 SlimDX Group
\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
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\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
27 #include "../stack_array.h"
\r
31 using namespace System;
\r
32 using namespace System::Runtime::InteropServices;
\r
38 bool Macro::operator == ( Macro left, Macro right )
\r
40 return Macro::Equals( left, right );
\r
43 bool Macro::operator != ( Macro left, Macro right )
\r
45 return !Macro::Equals( left, right );
\r
48 int Macro::GetHashCode()
\r
50 return Name->GetHashCode() + Definition->GetHashCode();
\r
53 bool Macro::Equals( Object^ value )
\r
55 if( value == nullptr )
\r
58 if( value->GetType() != GetType() )
\r
61 return Equals( safe_cast<Macro>( value ) );
\r
64 bool Macro::Equals( Macro value )
\r
66 return ( Name == value.Name && Definition == value.Definition );
\r
69 bool Macro::Equals( Macro% value1, Macro% value2 )
\r
71 return ( value1.Name == value2.Name && value1.Definition == value2.Definition );
\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
77 if( macros == nullptr )
\r
80 return stack_array<D3DXMACRO>();
\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
87 for( int i = 0; i < macros->Length; ++i )
\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
92 handles[2 * i] = GCHandle::Alloc( nameBytes, GCHandleType::Pinned );
\r
93 handles[2 * i + 1] = GCHandle::Alloc( defBytes, GCHandleType::Pinned );
\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
99 result[macros->Length].Name = NULL;
\r
100 result[macros->Length].Definition = NULL;
\r
105 void Macro::Unmarshal( array<GCHandle>^ handles )
\r
107 if( handles != nullptr )
\r
109 for( int i = 0; i < handles->Length; ++i )
\r