+++ /dev/null
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-\r
-#include <windows.h>\r
-#include <dxerr.h>\r
-\r
-#include "Configuration.h"\r
-#include "Result.h"\r
-#include "SlimDXException.h"\r
-\r
-using namespace System;\r
-using namespace System::Globalization;\r
-using namespace System::Collections;\r
-\r
-namespace SlimDX\r
-{\r
- Result::Result( int hr )\r
- : m_Code( hr )\r
- {\r
- }\r
- \r
- int Result::Code::get()\r
- {\r
- return m_Code;\r
- }\r
- \r
- String^ Result::Name::get()\r
- {\r
- if( m_Info == nullptr )\r
- {\r
- m_Info = gcnew ResultInfo();\r
- }\r
-\r
- if( m_Info->Name == nullptr )\r
- {\r
- m_Info->Name = gcnew String( DXGetErrorString( m_Code ) );\r
- }\r
-\r
- return m_Info->Name;\r
- }\r
-\r
- String^ Result::Description::get()\r
- {\r
- if( m_Info == nullptr )\r
- {\r
- m_Info = gcnew ResultInfo();\r
- }\r
-\r
- if( m_Info->Description == nullptr )\r
- {\r
- m_Info->Description = gcnew String( DXGetErrorDescription( m_Code ) );\r
- }\r
- \r
- return m_Info->Description;\r
- }\r
- \r
- SortedList^ Result::Data::get()\r
- {\r
- if( m_Info == nullptr )\r
- {\r
- m_Info = gcnew ResultInfo();\r
- }\r
-\r
- return m_Info->Data;\r
- }\r
-\r
- void Result::Data::set( SortedList^ value )\r
- {\r
- if( m_Info == nullptr )\r
- {\r
- m_Info = gcnew ResultInfo();\r
- }\r
-\r
- m_Info->Data = value;\r
- }\r
-\r
- bool Result::IsSuccess::get()\r
- {\r
- return SUCCEEDED( m_Code );\r
- }\r
- \r
- bool Result::IsFailure::get()\r
- {\r
- return FAILED( m_Code );\r
- }\r
- \r
- void Result::BreakIfDebugging()\r
- {\r
- System::Diagnostics::Debugger::Break();\r
- }\r
-\r
- generic< typename T >\r
- void Result::Throw( Object^ dataKey, Object^ dataValue )\r
- {\r
- SlimDXException^ ex = safe_cast<SlimDXException^>( Activator::CreateInstance( T::typeid, m_Last ) );\r
- if( dataKey != nullptr )\r
- ex->Data->Add(dataKey, dataValue);\r
-\r
- throw ex;\r
- }\r
-\r
- generic< typename T >\r
- Result Result::Record( int hr, bool failed, Object^ dataKey, Object^ dataValue )\r
- {\r
- m_LastCode = hr;\r
- if(!failed)\r
- return Result( hr );\r
-\r
- m_Last = Result( hr );\r
- if( dataKey != nullptr )\r
- {\r
- m_Last.Data = gcnew SortedList();\r
- m_Last.Data->Add( dataKey, dataValue );\r
- }\r
-\r
- ResultWatchFlags flags;\r
- if( Configuration::TryGetResultWatch( m_Last, flags ) )\r
- {\r
- if( flags == ResultWatchFlags::AlwaysIgnore )\r
- return m_Last;\r
-\r
- if( static_cast<int>( flags & ResultWatchFlags::Break ) != 0 )\r
- BreakIfDebugging();\r
-\r
- if( static_cast<int>( flags & ResultWatchFlags::Throw ) != 0 )\r
- Throw<T>(dataKey, dataValue);\r
- }\r
-\r
- if( Configuration::ThrowOnError )\r
- Throw<T>(dataKey, dataValue);\r
-\r
- return m_Last;\r
- }\r
-\r
- generic< typename T >\r
- Result Result::Fail( int hr, Object^ dataKey, Object^ dataValue )\r
- {\r
- return Record<T>( hr, true, dataKey, dataValue );\r
- }\r
-\r
- generic< typename T >\r
- Result Result::Record( int hr, Object^ dataKey, Object^ dataValue )\r
- {\r
- return Record<T>( hr, hr < 0, dataKey, dataValue );\r
- }\r
- \r
- Result Result::Last::get()\r
- {\r
- if( SUCCEEDED(m_LastCode) )\r
- return Result( m_LastCode );\r
- else\r
- return m_Last;\r
- }\r
- \r
- bool Result::operator == ( Result left, Result right )\r
- {\r
- return Result::Equals( left, right );\r
- }\r
- \r
- bool Result::operator != ( Result left, Result right )\r
- {\r
- return !Result::Equals( left, right );\r
- }\r
-\r
- String^ Result::ToString()\r
- {\r
- return String::Format( CultureInfo::CurrentCulture, "{0}: {1} ({2})", Name, Description, Code );\r
- }\r
-\r
- int Result::GetHashCode()\r
- {\r
- return m_Code.GetHashCode();\r
- }\r
-\r
- bool Result::Equals( Object^ value )\r
- {\r
- if( value == nullptr )\r
- return false;\r
-\r
- if( value->GetType() != GetType() )\r
- return false;\r
-\r
- return Equals( safe_cast<Result>( value ) );\r
- }\r
-\r
- bool Result::Equals( Result value )\r
- {\r
- return ( Code == value.Code );\r
- }\r
-\r
- bool Result::Equals( Result% value1, Result% value2 )\r
- {\r
- return ( value1.Code == value2.Code );\r
- }\r
-}
\ No newline at end of file