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
26 #include "EffectHandle.h"
\r
28 using namespace System;
\r
29 using namespace System::Runtime::InteropServices;
\r
35 EffectHandle::EffectHandle( D3DXHANDLE handle )
\r
38 m_StringData = IntPtr::Zero;
\r
40 GC::SuppressFinalize(this);
\r
43 EffectHandle::EffectHandle( String^ name )
\r
45 m_StringData = Marshal::StringToHGlobalAnsi( name );
\r
47 m_StringDataSize = name->Length;
\r
48 GC::AddMemoryPressure( m_StringDataSize );
\r
50 m_Handle = reinterpret_cast<D3DXHANDLE>( m_StringData.ToPointer() );
\r
53 void EffectHandle::Destruct()
\r
57 Marshal::FreeHGlobal( m_StringData );
\r
58 GC::RemoveMemoryPressure( m_StringDataSize );
\r
62 EffectHandle::operator EffectHandle^( String^ name )
\r
64 return gcnew EffectHandle( name );
\r
67 bool EffectHandle::operator == ( EffectHandle^ left, EffectHandle^ right )
\r
69 //preferred to ReferenceEquals
\r
70 Object^ leftObj = left;
\r
71 Object^ rightObj = right;
\r
72 if(leftObj == nullptr)
\r
73 return rightObj == nullptr;
\r
75 return EffectHandle::Equals( left, right );
\r
78 bool EffectHandle::operator != ( EffectHandle^ left, EffectHandle^ right )
\r
80 return !( left == right );
\r
83 int EffectHandle::GetHashCode()
\r
85 IntPtr ptr( const_cast<void*>( reinterpret_cast<const void*>( m_Handle ) ) );
\r
86 return ptr.GetHashCode();
\r
89 bool EffectHandle::Equals( Object^ value )
\r
91 if( ((Object^) value) == nullptr )
\r
94 if( value->GetType() != GetType() )
\r
97 return Equals( safe_cast<EffectHandle^>( value ) );
\r
100 bool EffectHandle::Equals( EffectHandle^ value )
\r
102 if( ((Object^) value) == nullptr )
\r
105 if( ReferenceEquals( this, value ) )
\r
108 return ( m_Handle == value->InternalHandle );
\r
111 bool EffectHandle::Equals( EffectHandle^ value1, EffectHandle^ value2 )
\r
113 return value1->Equals( value2 );
\r