1 #if ! __WXMP_Common_hpp__
2 #define __WXMP_Common_hpp__ 1
3 
4 // =================================================================================================
5 // Copyright 2002 Adobe Systems Incorporated
6 // All Rights Reserved.
7 //
8 // NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
9 // of the Adobe license agreement accompanying it.
10 // =================================================================================================
11 
12 #include <stdlib.h>
13 #include <string.h>
14 
15 #ifndef XMP_Inline
16 	#if TXMP_EXPAND_INLINE
17 		#define XMP_Inline inline
18 	#else
19 		#define XMP_Inline /* not inline */
20 	#endif
21 #endif
22 
23 #define XMP_CTorDTorIntro(Class) template <class tStringObj> XMP_Inline Class<tStringObj>
24 #define XMP_MethodIntro(Class,ResultType) template <class tStringObj> XMP_Inline ResultType Class<tStringObj>
25 
26 typedef void (* SetClientStringProc) ( void * clientPtr, XMP_StringPtr valuePtr, XMP_StringLen valueLen );
27 typedef void (* SetClientStringVectorProc) ( void * clientPtr, XMP_StringPtr * arrayPtr, XMP_Uns32 stringCount );
28 
29 struct WXMP_Result {
30 private:
31     char*         errMessage;
32 public:
33     void *        ptrResult;
34     double        floatResult;
35     XMP_Uns64     int64Result;
36     XMP_Uns32     int32Result;
WXMP_ResultWXMP_Result37 	WXMP_Result() : errMessage(NULL),ptrResult(NULL),floatResult(0),int64Result(0),int32Result(0){};
~WXMP_ResultWXMP_Result38 	~WXMP_Result()
39 	{
40 		if (errMessage) {
41 			free(errMessage);
42 		}
43 	}
SetErrMessageWXMP_Result44 	void SetErrMessage(const char* msg)
45 		{
46 			if (errMessage) {
47 				free(errMessage);
48 				errMessage = NULL;
49 			}
50 			if (msg) {
51 				errMessage = strdup(msg);
52 			}
53 		}
GetErrMessageWXMP_Result54 	const char* GetErrMessage() const
55 		{
56 			return errMessage;
57 		}
58 private:
59 	// We should avoid automatic copy.
60 	WXMP_Result(const WXMP_Result&);
61 	WXMP_Result& operator=(const WXMP_Result&);
62 };
63 
64 #if __cplusplus
65 extern "C" {
66 #endif
67 
68 #define PropagateException(res)	\
69 	if ( res.GetErrMessage() != 0 ) throw XMP_Error ( res.int32Result, res.GetErrMessage() );
70 
71 #ifndef XMP_TraceClientCalls
72 	#define XMP_TraceClientCalls		0
73 	#define XMP_TraceClientCallsToFile	0
74 #endif
75 
76 #if ! XMP_TraceClientCalls
77 	#define InvokeCheck(WCallProto) \
78     	WXMP_Result wResult;        \
79 		WCallProto;                 \
80 		PropagateException ( wResult )
81 #else
82 	extern FILE * xmpClientLog;
83 	#define InvokeCheck(WCallProto)                                                                          \
84     	WXMP_Result wResult;                                                                                 \
85     	fprintf ( xmpClientLog, "WXMP calling: %s\n", #WCallProto ); fflush ( xmpClientLog );                \
86     	WCallProto;                                                                                          \
87 	if ( wResult.GetErrMessage() == 0 ) {				\
88 			fprintf ( xmpClientLog, "WXMP back, no error\n" ); fflush ( xmpClientLog );                      \
89     	} else {                                                                                             \
90 			fprintf ( xmpClientLog, "WXMP back, error: %s\n", wResult.GetErrMessage() ); fflush ( xmpClientLog ); \
91     	}                                                                                                    \
92 		PropagateException ( wResult )
93 #endif
94 
95 // =================================================================================================
96 
97 #define WrapNoCheckVoid(WCallProto) \
98 	WCallProto;
99 
100 #define WrapCheckVoid(WCallProto) \
101     InvokeCheck(WCallProto);
102 
103 #define WrapCheckMetaRef(result,WCallProto) \
104     InvokeCheck(WCallProto);                \
105     XMPMetaRef result = XMPMetaRef(wResult.ptrResult)
106 
107 #define WrapCheckIterRef(result,WCallProto) \
108     InvokeCheck(WCallProto);                \
109     XMPIteratorRef result = XMPIteratorRef(wResult.ptrResult)
110 
111 #define WrapCheckDocOpsRef(result,WCallProto) \
112     InvokeCheck(WCallProto);                  \
113     XMPDocOpsRef result = XMPDocOpsRef(wResult.ptrResult)
114 
115 #define  WrapCheckNewMetadata(result,WCallProto) \
116     InvokeCheck(WCallProto);                  \
117     void * result = wResult.ptrResult
118 
119 #define WrapCheckBool(result,WCallProto) \
120     InvokeCheck(WCallProto);             \
121     bool result = bool(wResult.int32Result)
122 
123 #define WrapCheckTriState(result,WCallProto) \
124     InvokeCheck(WCallProto);                 \
125     XMP_TriState result = XMP_TriState(wResult.int32Result)
126 
127 #define WrapCheckOptions(result,WCallProto) \
128     InvokeCheck(WCallProto);                \
129     XMP_OptionBits result = XMP_OptionBits(wResult.int32Result)
130 
131 #define WrapCheckStatus(result,WCallProto) \
132     InvokeCheck(WCallProto);               \
133     XMP_Status result = XMP_Status(wResult.int32Result)
134 
135 #define WrapCheckIndex(result,WCallProto) \
136     InvokeCheck(WCallProto);              \
137     XMP_Index result = XMP_Index(wResult.int32Result)
138 
139 #define WrapCheckInt32(result,WCallProto) \
140     InvokeCheck(WCallProto);              \
141     XMP_Int32 result = wResult.int32Result
142 
143 #define WrapCheckInt64(result,WCallProto) \
144     InvokeCheck(WCallProto);              \
145     XMP_Int64 result = wResult.int64Result
146 
147 #define WrapCheckFloat(result,WCallProto) \
148     InvokeCheck(WCallProto);              \
149     double result = wResult.floatResult
150 
151 #define WrapCheckFormat(result,WCallProto) \
152     InvokeCheck(WCallProto);               \
153     XMP_FileFormat result = wResult.int32Result
154 
155 // =================================================================================================
156 
157 #if __cplusplus
158 }	// extern "C"
159 #endif
160 
161 #endif  // __WXMP_Common_hpp__
162