summaryrefslogtreecommitdiff
path: root/public/include/XMPCommon/source/IError.cpp
blob: 8f763d385e0193586828035340c537d12e076151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// =================================================================================================
// ADOBE SYSTEMS INCORPORATED
// Copyright 2015 Adobe Systems Incorporated
// All Rights Reserved
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it.
// =================================================================================================

#define FRIEND_CLASS_DECLARATION() friend class IErrorProxy;

#include "XMPCommon/Interfaces/IError.h"

#if !BUILDING_XMPCOMMON_LIB && !SOURCE_COMPILING_XMP_ALL

#include "XMPCommon/Utilities/TWrapperFunctions.h"
#include "XMPCommon/Interfaces/IUTF8String.h"
#include "XMPCommon/Interfaces/IObjectFactory.h"

#include <assert.h>

namespace AdobeXMPCommon {
	class IErrorProxy
		: public virtual IError
	{
	private:
		pIError mRawPtr;

	public:
		IErrorProxy( pIError ptr )
			: mRawPtr( ptr )
		{
			mRawPtr->Acquire();
		}

		~IErrorProxy() __NOTHROW__ { mRawPtr->Release(); }

		pIError APICALL GetActualIError() __NOTHROW__ { return mRawPtr; }

		void APICALL Acquire() const __NOTHROW__ { assert( false ); }

		void APICALL Release() const __NOTHROW__ { assert( false ); }

		pvoid APICALL GetInterfacePointer( uint64 interfaceID, uint32 interfaceVersion ) {
			return CallSafeFunction<
				IVersionable, pvoid, pvoid, uint64, uint32
			>( mRawPtr, &IVersionable::getInterfacePointer, interfaceID, interfaceVersion );
		}

		pvoid APICALL getInterfacePointer( uint64 interfaceID, uint32 interfaceVersion, pcIError_base & error ) __NOTHROW__ {
			assert( false );
			return mRawPtr->getInterfacePointer( interfaceID, interfaceVersion, error );
		}

		eErrorCode APICALL GetCode() const {
			return CallConstSafeFunction< IError, eErrorCode, uint32 >(
				mRawPtr, &IError::getCode );
		}

		uint32 APICALL getCode( pcIError_base & error ) const __NOTHROW__ {
			assert( false );
			return mRawPtr->getCode( error );
		}

		eErrorDomain APICALL GetDomain() const {
			return CallConstSafeFunction< IError, eErrorDomain, uint32 >(
				mRawPtr, &IError::getDomain );
		}

		uint32 APICALL getDomain( pcIError_base & error ) const __NOTHROW__ {
			assert( false );
			return mRawPtr->getDomain( error );
		}

		eErrorSeverity APICALL GetSeverity() const {
			return CallConstSafeFunction< IError, eErrorSeverity, uint32 >(
				mRawPtr, &IError::getSeverity );
		}

		uint32 APICALL getSeverity( pcIError_base & error ) const __NOTHROW__ {
			assert( false );
			return mRawPtr->getSeverity( error );
		}

		spcIUTF8String APICALL GetMessage() const {
			return CallConstSafeFunctionReturningPointer< IError, pcIUTF8String_base, const IUTF8String >(
				mRawPtr, &IError::getMessage );
		}

		pcIUTF8String_base APICALL getMessage( pcIError_base & error ) const __NOTHROW__ {
			assert( false );
			return mRawPtr->getMessage( error );
		}

		spcIUTF8String APICALL GetLocation() const {
			return CallConstSafeFunctionReturningPointer< IError, pcIUTF8String_base, const IUTF8String >(
				mRawPtr, &IError::getLocation );
		}

		pcIUTF8String_base APICALL getLocation( pcIError_base & error ) const __NOTHROW__ {
			assert( false );
			return mRawPtr->getLocation( error );
		}

		spcIUTF8String APICALL GetParameter( sizet index ) const {
			return CallConstSafeFunctionReturningPointer< IError, pcIUTF8String_base, const IUTF8String, sizet >(
				mRawPtr, &IError::getParameter, index );
		}

		pcIUTF8String_base APICALL getParameter( sizet index, pcIError_base & error ) const __NOTHROW__ {
			assert( false );
			return mRawPtr->getParameter( index, error );
		}

		sizet APICALL GetParametersCount() const __NOTHROW__ {
			return mRawPtr->GetParametersCount();
		}

		spIError APICALL GetNextError() {
			pcIError_base error( NULL );
			pIError_base ptr = mRawPtr->getNextError( error );
			if ( error ) throw MakeShared( error );
			return MakeShared( ptr );
		}

		pIError_base APICALL getNextError( pcIError_base & error ) __NOTHROW__ {
			assert( false );
			return mRawPtr->getNextError( error );
		}

		spIError APICALL SetNextError( const spIError & nextError ) {
			pcIError_base error( NULL );
			pIError_base ptr = mRawPtr->setNextError( nextError ? nextError->GetActualIError() : NULL, error );
			if ( error ) throw MakeShared( error );
			return MakeShared( ptr );
		}

		pIError_base APICALL setNextError( pIError_base nextError, pcIError_base & error ) __NOTHROW__ {
			assert( false );
			return mRawPtr->setNextError( nextError, error );
		}

		void APICALL SetMessage( const char * message, sizet len ) __NOTHROW__ {
			mRawPtr->SetMessage( message, len );
		}

		void APICALL SetLocation( const char * fileName, sizet lineNumber ) __NOTHROW__ {
			mRawPtr->SetLocation( fileName, lineNumber );
		}

		void APICALL AppendParameter( const char * parameter, sizet len ) __NOTHROW__ {
			mRawPtr->AppendParameter( parameter, len );
		}

		void APICALL AppendParameter( void * addressParameter ) __NOTHROW__ {
			return mRawPtr->AppendParameter( addressParameter );
		}

		void APICALL AppendParameter( const uint32 & integerValue ) __NOTHROW__ {
			return mRawPtr->AppendParameter( integerValue );
		}

		void APICALL AppendParameter( const uint64 & integerValue ) __NOTHROW__ {
			return mRawPtr->AppendParameter( integerValue );
		}

		void APICALL AppendParameter( const int32 & integerValue ) __NOTHROW__ {
			return mRawPtr->AppendParameter( integerValue );
		}

		void APICALL AppendParameter( const int64 & integerValue ) __NOTHROW__ {
			return mRawPtr->AppendParameter( integerValue );
		}

		void APICALL AppendParameter( const float & floatValue ) __NOTHROW__ {
			return mRawPtr->AppendParameter( floatValue );
		}

		void APICALL AppendParameter( const double & doubleValue ) __NOTHROW__ {
			return mRawPtr->AppendParameter( doubleValue );
		}

		void APICALL AppendParameter( bool booleanValue ) __NOTHROW__ {
			return mRawPtr->AppendParameter( booleanValue );
		}

		AdobeXMPCommon_Int::pISharedObject_I APICALL GetISharedObject_I() __NOTHROW__ {
			return mRawPtr->GetISharedObject_I();
		}

	};

	spIError IError_v1::CreateError( pIObjectFactory objFactory, eErrorDomain errDomain, eErrorCode errCode, eErrorSeverity errSeverity ) {
		pIError_base temp = CallSafeFunction< IObjectFactory_base, pIError_base, pIError_base, uint32, uint32, uint32 >(
			objFactory, &IObjectFactory_base::CreateError, static_cast< uint32 >( errDomain ),
			static_cast< uint32 >( errCode ), static_cast< uint32 >( errSeverity ) );
		return MakeShared( temp );
	}

	spIError IError_v1::MakeShared( pIError_base ptr ) {
		if ( !ptr ) return spIError();
		pIError p = IError::GetInterfaceVersion() > 1 ? ptr->GetInterfacePointer<IError>() : ptr;
		return shared_ptr< IError >( new IErrorProxy( p ) );
	}
}

#endif  // !BUILDING_XMPCOMMON_LIB && !SOURCE_COMPILING_XMP_ALL