// =================================================================================================
// ADOBE SYSTEMS INCORPORATED
// Copyright 2002 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.
// =================================================================================================

//	================================================================================================
/// \file TXMPMeta.incl_cpp
/// \brief The implementation of the TXMPMeta template class.

#include "XMP.hpp"

#include "client-glue/WXMP_Common.hpp"

#include "client-glue/WXMPMeta.hpp"


#include "XMPCore/XMPCoreDefines.h"
#if ENABLE_CPP_DOM_MODEL
	#include "XMPCore/Interfaces/IMetadata.h"
	#include "XMPCore/Interfaces/ICoreObjectFactory.h"
#endif


// =================================================================================================
// Implementation Guidelines
// =========================
//
// The implementations of the template functions are very stylized. ...
//
// =================================================================================================
	
#ifndef XMP_TraceCTorDTor
	#define XMP_TraceCTorDTor 0
#endif

#if XMP_TraceCTorDTor
	class XMPeek {	// Hack to peek at the client ref count in the internal object.
	public:
		XMPeek();
		virtual ~XMPeek();
		XMP_Int32 clientRefs;
	};
#endif

// =================================================================================================
// Local utilities
// ===============

class TOPW_Info {
public:
	XMP_TextOutputProc clientProc;
	void *			   clientRefCon;
	TOPW_Info ( XMP_TextOutputProc proc, void * refCon ) : clientProc(proc), clientRefCon(refCon) {};
private:
	TOPW_Info() {}; // ! Hide default constructor.
};

static XMP_Status TextOutputProcWrapper ( void *        refCon,
                                          XMP_StringPtr buffer,
                                          XMP_StringLen bufferSize )
{
	try {	// Don't let client callback exceptions propagate across DLL boundaries.
		TOPW_Info * info = (TOPW_Info*)refCon;
		return info->clientProc ( info->clientRefCon, buffer, bufferSize );
	} catch ( ... ) {
		return -1;
	}
}

// =================================================================================================
// Initialization and termination
// ==============================

XMP_MethodIntro(TXMPMeta,void)::
SetClientString ( void * clientPtr, XMP_StringPtr valuePtr, XMP_StringLen valueLen )
{
	tStringObj * clientStr = (tStringObj*) clientPtr;
	clientStr->assign ( valuePtr, valueLen );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
GetVersionInfo ( XMP_VersionInfo * info )
{
	WrapNoCheckVoid ( zXMPMeta_GetVersionInfo_1 ( info ) );
}

// -------------------------------------------------------------------------------------------------

#if XMP_TraceClientCalls
	FILE * xmpClientLog = stderr;
#endif

#ifndef XMP_TypeCheck
	#if ! XMP_DebugBuild
		#define XMP_TypeCheck(e,msg) /* nothing */
	#else
		#define XMP_TypeCheck(e,msg) if ( ! (e) ) throw XMP_Error ( kXMPErr_AssertFailure, msg );
	#endif
#endif

XMP_MethodIntro(TXMPMeta,bool)::
Initialize()
{
	// Verify critical type sizes.
	XMP_TypeCheck ( (sizeof(XMP_Int8)  == 1), "Size wrong for critical type XMP_Int8" );
	XMP_TypeCheck ( (sizeof(XMP_Int16) == 2), "Size wrong for critical type XMP_Int16" );
	XMP_TypeCheck ( (sizeof(XMP_Int32) == 4), "Size wrong for critical type XMP_Int32" );
	XMP_TypeCheck ( (sizeof(XMP_Int64) == 8), "Size wrong for critical type XMP_Int64" );
	XMP_TypeCheck ( (sizeof(XMP_Uns8)  == 1), "Size wrong for critical type XMP_Uns8" );
	XMP_TypeCheck ( (sizeof(XMP_Uns16) == 2), "Size wrong for critical type XMP_Uns16" );
	XMP_TypeCheck ( (sizeof(XMP_Uns32) == 4), "Size wrong for critical type XMP_Uns32" );
	XMP_TypeCheck ( (sizeof(XMP_Uns64) == 8), "Size wrong for critical type XMP_Uns64" );
	XMP_TypeCheck ( (sizeof(XMP_Bool)  == 1), "Size wrong for critical type XMP_Bool" );

	#if XMP_TraceClientCallsToFile
		xmpClientLog = fopen ( "XMPClientLog.txt", "w" );
		if ( xmpClientLog == 0 ) xmpClientLog = stderr;
	#endif

	WrapCheckBool ( ok, zXMPMeta_Initialize_1() );

	#if ENABLE_CPP_DOM_MODEL
			AdobeXMPCore::ICoreObjectFactory::SetupCoreObjectFactory();
	#endif

	return ok;

}
// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
Terminate()
{
	
	#if ENABLE_CPP_DOM_MODEL
		AdobeXMPCore::ICoreObjectFactory::DestroyCoreObjectFactory();
	#endif

	WrapNoCheckVoid ( zXMPMeta_Terminate_1() );

	#if XMP_TraceClientCallsToFile
		if ( xmpClientLog != stderr ) fclose ( xmpClientLog );
		xmpClientLog = stderr;
	#endif
}

// =================================================================================================
// Constuctors, destructor, operators
// ==================================

static XMPMetaRef DefaultCTor()
{
	WrapCheckMetaRef ( newRef, zXMPMeta_CTor_1() );
	return newRef;
}

// -------------------------------------------------------------------------------------------------

XMP_CTorDTorIntro(TXMPMeta)::
TXMPMeta() : xmpRef(DefaultCTor())
{
	#if XMP_TraceCTorDTor
		XMPeek* xmPtr = (XMPeek*)this->xmpRef;
		printf ( "Default construct TXMPMeta @ %.8X, ref = %.8X, count = %d\n", this, xmPtr, xmPtr->clientRefs );
	#endif
}

// -------------------------------------------------------------------------------------------------

XMP_CTorDTorIntro(TXMPMeta)::
TXMPMeta ( const TXMPMeta<tStringObj> & original ) : xmpRef(original.xmpRef)
{
	WXMPMeta_IncrementRefCount_1 ( this->xmpRef );
	#if XMP_TraceCTorDTor
		XMPeek* xmPtr = (XMPeek*)this->xmpRef;
		printf ( "Copy construct TXMPMeta @ %.8X, ref = %.8X, count = %d\n", this, xmPtr, xmPtr->clientRefs );
	#endif
}

// -------------------------------------------------------------------------------------------------
XMP_MethodIntro(TXMPMeta,void)::
operator= ( const TXMPMeta<tStringObj> & rhs )
{
	#if XMP_TraceCTorDTor
		XMPeek* xmLHS = (XMPeek*)this->xmpRef;
		XMPeek* xmRHS = (XMPeek*)rhs.xmpRef;
		printf ( "Assign TXMPMeta, lhs @ %.8X, rhs @ %.8X\n", this, &rhs );
		printf ( "   original lhs ref = %.8X, count = %d\n", xmLHS, xmLHS->clientRefs );
		printf ( "   original rhs ref = %.8X, count = %d\n", xmRHS, xmRHS->clientRefs );
	#endif
	XMPMetaRef oldRef = this->xmpRef;	// ! Decrement last so errors leave client object OK.
	this->xmpRef = rhs.xmpRef;
	WXMPMeta_IncrementRefCount_1 ( this->xmpRef );	// Increment the count on the new ref.
	WXMPMeta_DecrementRefCount_1 ( oldRef );		// Decrement the count on the old ref.
	#if XMP_TraceCTorDTor
		printf ( "   result   lhs ref = %.8X, count = %d\n", xmLHS, xmLHS->clientRefs );
	#endif
}

// -------------------------------------------------------------------------------------------------

XMP_CTorDTorIntro(TXMPMeta)::
TXMPMeta ( XMPMetaRef _xmpRef ) : xmpRef(_xmpRef)
{
	WXMPMeta_IncrementRefCount_1 ( this->xmpRef );
	#if XMP_TraceCTorDTor
		XMPeek* xmPtr = (XMPeek*)this->xmpRef;
		printf ( "Ref construct TXMPMeta @ %.8X, ref = %.8X, count = %d\n", this, xmPtr, xmPtr->clientRefs );
	#endif
}

// -------------------------------------------------------------------------------------------------

XMP_CTorDTorIntro(TXMPMeta)::
TXMPMeta ( XMP_StringPtr buffer,
           XMP_StringLen xmpSize ) : xmpRef(DefaultCTor())
{
	#if XMP_TraceCTorDTor
		XMPeek* xmPtr = (XMPeek*)this->xmpRef;
		printf ( "Parse construct TXMPMeta @ %.8X, ref = %.8X, count = %d\n", this, xmPtr, xmPtr->clientRefs );
	#endif
	try {
		this->ParseFromBuffer ( buffer, xmpSize );
	} catch ( ... ) {
		WXMPMeta_DecrementRefCount_1 ( this->xmpRef );
		this->xmpRef = 0;
		throw;
	}
}

// -------------------------------------------------------------------------------------------------

XMP_CTorDTorIntro(TXMPMeta)::
~TXMPMeta() throw()
{
	#if XMP_TraceCTorDTor
		XMPeek* xmPtr = (XMPeek*)this->xmpRef;
		printf ( "Destruct TXMPMeta @ %.8X, ref = %.8X, count = %d\n", this, xmPtr, xmPtr->clientRefs );
	#endif
	WXMPMeta_DecrementRefCount_1 ( this->xmpRef );
	this->xmpRef = 0;

}	// ~TXMPMeta ()

// =================================================================================================
// Global state functions
// ======================

XMP_MethodIntro(TXMPMeta,XMP_OptionBits)::
GetGlobalOptions()
{
	WrapCheckOptions ( options, zXMPMeta_GetGlobalOptions_1() );
	return options;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetGlobalOptions ( XMP_OptionBits options )
{
	WrapCheckVoid ( zXMPMeta_SetGlobalOptions_1 ( options ) );
}

// -------------------------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,XMP_Status)::
DumpNamespaces ( XMP_TextOutputProc outProc,
                 void *             refCon )
{
	TOPW_Info info ( outProc, refCon );
	WrapCheckStatus ( status, zXMPMeta_DumpNamespaces_1 ( TextOutputProcWrapper, &info ) );
	return status;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
RegisterNamespace ( XMP_StringPtr namespaceURI,
                    XMP_StringPtr suggestedPrefix,
                    tStringObj *  registeredPrefix )
{
	WrapCheckBool ( prefixMatch, zXMPMeta_RegisterNamespace_1 ( namespaceURI, suggestedPrefix, registeredPrefix, SetClientString ) );
	return prefixMatch;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetNamespacePrefix ( XMP_StringPtr namespaceURI,
                     tStringObj *  namespacePrefix )
{
	WrapCheckBool ( found, zXMPMeta_GetNamespacePrefix_1 ( namespaceURI, namespacePrefix, SetClientString ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetNamespaceURI ( XMP_StringPtr namespacePrefix,
                  tStringObj *  namespaceURI )
{
	WrapCheckBool ( found, zXMPMeta_GetNamespaceURI_1 ( namespacePrefix, namespaceURI, SetClientString ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
DeleteNamespace ( XMP_StringPtr namespaceURI )
{
	WrapCheckVoid ( zXMPMeta_DeleteNamespace_1 ( namespaceURI ) );
}

// =================================================================================================
// Basic property manipulation functions
// =====================================

XMP_MethodIntro(TXMPMeta,bool)::
GetProperty ( XMP_StringPtr    schemaNS,
              XMP_StringPtr    propName,
			  tStringObj *     propValue,
			  XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetProperty_1 ( schemaNS, propName, propValue, options, SetClientString ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetArrayItem ( XMP_StringPtr    schemaNS,
               XMP_StringPtr    arrayName,
               XMP_Index        itemIndex,
			   tStringObj *     itemValue,
			   XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetArrayItem_1 ( schemaNS, arrayName, itemIndex, itemValue, options, SetClientString ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetStructField ( XMP_StringPtr    schemaNS,
                 XMP_StringPtr    structName,
				 XMP_StringPtr    fieldNS,
				 XMP_StringPtr    fieldName,
				 tStringObj *     fieldValue,
				 XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetStructField_1 ( schemaNS, structName, fieldNS, fieldName, fieldValue, options, SetClientString ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetQualifier ( XMP_StringPtr    schemaNS,
               XMP_StringPtr    propName,
			   XMP_StringPtr    qualNS,
			   XMP_StringPtr    qualName,
			   tStringObj *     qualValue,
			   XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetQualifier_1 ( schemaNS, propName, qualNS, qualName, qualValue, options, SetClientString ) );
	return found;
}	//GetQualifier ()

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetProperty ( XMP_StringPtr  schemaNS,
              XMP_StringPtr  propName,
			  XMP_StringPtr  propValue,
			  XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetProperty_1 ( schemaNS, propName, propValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetProperty ( XMP_StringPtr      schemaNS,
              XMP_StringPtr      propName,
			  const tStringObj & propValue,
			  XMP_OptionBits     options /* = 0 */ )
{
	this->SetProperty ( schemaNS, propName, propValue.c_str(), options );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetArrayItem ( XMP_StringPtr  schemaNS,
               XMP_StringPtr  arrayName,
               XMP_Index      itemIndex,
			   XMP_StringPtr  itemValue,
			   XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetArrayItem_1 ( schemaNS, arrayName, itemIndex, itemValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetArrayItem ( XMP_StringPtr      schemaNS,
               XMP_StringPtr      arrayName,
               XMP_Index          itemIndex,
			   const tStringObj & itemValue,
			   XMP_OptionBits     options /* = 0 */ )
{
	this->SetArrayItem ( schemaNS, arrayName, itemIndex, itemValue.c_str(), options );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
AppendArrayItem ( XMP_StringPtr  schemaNS,
                  XMP_StringPtr  arrayName,
                  XMP_OptionBits arrayOptions,
				  XMP_StringPtr  itemValue,
				  XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_AppendArrayItem_1 ( schemaNS, arrayName, arrayOptions, itemValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
AppendArrayItem ( XMP_StringPtr      schemaNS,
                  XMP_StringPtr      arrayName,
                  XMP_OptionBits     arrayOptions,
				  const tStringObj & itemValue,
				  XMP_OptionBits     options /* = 0 */ )
{
	this->AppendArrayItem ( schemaNS, arrayName, arrayOptions, itemValue.c_str(), options );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetStructField ( XMP_StringPtr  schemaNS,
                 XMP_StringPtr  structName,
				 XMP_StringPtr  fieldNS,
				 XMP_StringPtr  fieldName,
				 XMP_StringPtr  fieldValue,
				 XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetStructField_1 ( schemaNS, structName, fieldNS, fieldName, fieldValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetStructField ( XMP_StringPtr      schemaNS,
                 XMP_StringPtr      structName,
				 XMP_StringPtr      fieldNS,
				 XMP_StringPtr      fieldName,
				 const tStringObj & fieldValue,
				 XMP_OptionBits     options /* = 0 */ )
{
	this->SetStructField ( schemaNS, structName, fieldNS, fieldName, fieldValue.c_str(), options );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetQualifier ( XMP_StringPtr  schemaNS,
               XMP_StringPtr  propName,
			   XMP_StringPtr  qualNS,
			   XMP_StringPtr  qualName,
			   XMP_StringPtr  qualValue,
			   XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetQualifier_1 ( schemaNS, propName, qualNS, qualName, qualValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetQualifier ( XMP_StringPtr      schemaNS,
               XMP_StringPtr      propName,
			   XMP_StringPtr      qualNS,
			   XMP_StringPtr      qualName,
			   const tStringObj & qualValue,
			   XMP_OptionBits     options /* = 0 */ )
{
	this->SetQualifier ( schemaNS, propName, qualNS, qualName, qualValue.c_str(), options );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
DeleteProperty ( XMP_StringPtr schemaNS,
                 XMP_StringPtr propName )
{
	WrapCheckVoid ( zXMPMeta_DeleteProperty_1 ( schemaNS, propName ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
DeleteArrayItem ( XMP_StringPtr schemaNS,
                  XMP_StringPtr arrayName,
                  XMP_Index     itemIndex )
{
	WrapCheckVoid ( zXMPMeta_DeleteArrayItem_1 ( schemaNS, arrayName, itemIndex ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
DeleteStructField ( XMP_StringPtr schemaNS,
                    XMP_StringPtr structName,
					XMP_StringPtr fieldNS,
					XMP_StringPtr fieldName )
{
	WrapCheckVoid ( zXMPMeta_DeleteStructField_1 ( schemaNS, structName, fieldNS, fieldName ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
DeleteQualifier ( XMP_StringPtr schemaNS,
                  XMP_StringPtr propName,
				  XMP_StringPtr qualNS,
				  XMP_StringPtr qualName )
{
	WrapCheckVoid ( zXMPMeta_DeleteQualifier_1 ( schemaNS, propName, qualNS, qualName ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
DoesPropertyExist ( XMP_StringPtr schemaNS,
                    XMP_StringPtr propName ) const
{
	WrapCheckBool ( exists, zXMPMeta_DoesPropertyExist_1 ( schemaNS, propName ) );
	return exists;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
DoesArrayItemExist ( XMP_StringPtr schemaNS,
                     XMP_StringPtr arrayName,
                     XMP_Index itemIndex ) const
{
	WrapCheckBool ( exists, zXMPMeta_DoesArrayItemExist_1 ( schemaNS, arrayName, itemIndex ) );
	return exists;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
DoesStructFieldExist ( XMP_StringPtr schemaNS,
                       XMP_StringPtr structName,
					   XMP_StringPtr fieldNS,
					   XMP_StringPtr fieldName ) const
{
	WrapCheckBool ( exists, zXMPMeta_DoesStructFieldExist_1 ( schemaNS, structName, fieldNS, fieldName ) );
	return exists;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
DoesQualifierExist ( XMP_StringPtr schemaNS,
                     XMP_StringPtr propName,
					 XMP_StringPtr qualNS,
					 XMP_StringPtr qualName ) const
{
	WrapCheckBool ( exists, zXMPMeta_DoesQualifierExist_1 ( schemaNS, propName, qualNS, qualName ) );
	return exists;
}

// =================================================================================================
// Specialized Get and Set functions
// =================================

XMP_MethodIntro(TXMPMeta,bool)::
GetLocalizedText ( XMP_StringPtr    schemaNS,
                   XMP_StringPtr    altTextName,
				   XMP_StringPtr    genericLang,
				   XMP_StringPtr    specificLang,
				   tStringObj *     actualLang,
				   tStringObj *     itemValue,
				   XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetLocalizedText_1 ( schemaNS, altTextName, genericLang, specificLang,
														 actualLang, itemValue, options, SetClientString ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetLocalizedText ( XMP_StringPtr  schemaNS,
                   XMP_StringPtr  altTextName,
				   XMP_StringPtr  genericLang,
				   XMP_StringPtr  specificLang,
				   XMP_StringPtr  itemValue,
				   XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetLocalizedText_1 ( schemaNS, altTextName, genericLang, specificLang, itemValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetLocalizedText ( XMP_StringPtr      schemaNS,
                   XMP_StringPtr      altTextName,
				   XMP_StringPtr      genericLang,
				   XMP_StringPtr      specificLang,
				   const tStringObj & itemValue,
				   XMP_OptionBits     options /* = 0 */ )
{
	this->SetLocalizedText ( schemaNS, altTextName, genericLang, specificLang, itemValue.c_str(), options );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
DeleteLocalizedText ( XMP_StringPtr    schemaNS,
		XMP_StringPtr    altTextName,
		XMP_StringPtr    genericLang,
		XMP_StringPtr    specificLang )
{
	WrapCheckVoid ( zXMPMeta_DeleteLocalizedText_1 ( schemaNS, altTextName, genericLang, specificLang ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetProperty_Bool ( XMP_StringPtr    schemaNS,
                   XMP_StringPtr    propName,
				   bool *           propValue,
				   XMP_OptionBits * options ) const
{
	XMP_Bool binValue;
	WrapCheckBool ( found, zXMPMeta_GetProperty_Bool_1 ( schemaNS, propName, &binValue, options ) );
	if ( found && (propValue != 0) ) *propValue = binValue;
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetProperty_Int ( XMP_StringPtr    schemaNS,
                  XMP_StringPtr    propName,
				  XMP_Int32 *      propValue,
				  XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetProperty_Int_1 ( schemaNS, propName, propValue, options ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetProperty_Int64 ( XMP_StringPtr    schemaNS,
                    XMP_StringPtr    propName,
				    XMP_Int64 *      propValue,
				    XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetProperty_Int64_1 ( schemaNS, propName, propValue, options ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetProperty_Float ( XMP_StringPtr    schemaNS,
                    XMP_StringPtr    propName,
					double *         propValue,
					XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetProperty_Float_1 ( schemaNS, propName, propValue, options ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,bool)::
GetProperty_Date ( XMP_StringPtr    schemaNS,
                   XMP_StringPtr    propName,
				   XMP_DateTime *   propValue,
				   XMP_OptionBits * options ) const
{
	WrapCheckBool ( found, zXMPMeta_GetProperty_Date_1 ( schemaNS, propName, propValue, options ) );
	return found;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetProperty_Bool ( XMP_StringPtr  schemaNS,
                   XMP_StringPtr  propName,
				   bool           propValue,
				   XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetProperty_Bool_1 ( schemaNS, propName, propValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetProperty_Int ( XMP_StringPtr  schemaNS,
                  XMP_StringPtr  propName,
				  XMP_Int32      propValue,
				  XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetProperty_Int_1 ( schemaNS, propName, propValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetProperty_Int64 ( XMP_StringPtr  schemaNS,
                    XMP_StringPtr  propName,
				    XMP_Int64      propValue,
				    XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetProperty_Int64_1 ( schemaNS, propName, propValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetProperty_Float ( XMP_StringPtr  schemaNS,
                    XMP_StringPtr  propName,
					double         propValue,
					XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetProperty_Float_1 ( schemaNS, propName, propValue, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetProperty_Date ( XMP_StringPtr        schemaNS,
                   XMP_StringPtr        propName,
				   const XMP_DateTime &	propValue,
				   XMP_OptionBits       options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_SetProperty_Date_1 ( schemaNS, propName, propValue, options ) );
}

// =================================================================================================
// Miscellaneous Member Functions
// ==============================

XMP_MethodIntro(TXMPMeta,XMPMetaRef)::
GetInternalRef() const
{
	return this->xmpRef;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
GetObjectName ( tStringObj * nameStr ) const
{
	WrapCheckVoid ( zXMPMeta_GetObjectName_1 ( nameStr, SetClientString ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetObjectName ( XMP_StringPtr name )
{
	WrapCheckVoid ( zXMPMeta_SetObjectName_1 ( name ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetObjectName ( tStringObj name )
{
	this->SetObjectName ( name.c_str() );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,XMP_OptionBits)::
GetObjectOptions() const
{
	WrapCheckOptions ( options, zXMPMeta_GetObjectOptions_1() );
	return options;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetObjectOptions ( XMP_OptionBits options )
{
	WrapCheckVoid ( zXMPMeta_SetObjectOptions_1 ( options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
Sort()
{
	WrapCheckVoid ( zXMPMeta_Sort_1() );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
Erase()
{
	WrapCheckVoid ( zXMPMeta_Erase_1() );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,TXMPMeta<tStringObj>)::
Clone ( XMP_OptionBits options ) const
{
	WrapCheckMetaRef ( cloneRef, zXMPMeta_Clone_1 ( options ) );
	return TXMPMeta<tStringObj> ( cloneRef );	// Ref construct will increment the clientRefs.
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,XMP_Index)::
CountArrayItems ( XMP_StringPtr schemaNS,
                  XMP_StringPtr arrayName ) const
{
	WrapCheckIndex ( count, zXMPMeta_CountArrayItems_1 ( schemaNS, arrayName ) );
	return count;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,XMP_Status)::
DumpObject ( XMP_TextOutputProc outProc,
             void *             refCon ) const
{
	TOPW_Info info ( outProc, refCon );
	WrapCheckStatus ( status, zXMPMeta_DumpObject_1 ( TextOutputProcWrapper, &info ) );
	return status;
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
ParseFromBuffer ( XMP_StringPtr  buffer,
                  XMP_StringLen  bufferSize,
                  XMP_OptionBits options /* = 0 */ )
{
	WrapCheckVoid ( zXMPMeta_ParseFromBuffer_1 ( buffer, bufferSize, options ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SerializeToBuffer ( tStringObj *   pktString,
                    XMP_OptionBits options,
                    XMP_StringLen  padding,
					XMP_StringPtr  newline,
					XMP_StringPtr  indent,
					XMP_Index      baseIndent /* = 0 */ ) const
{
	WrapCheckVoid ( zXMPMeta_SerializeToBuffer_1 ( pktString, options, padding, newline, indent, baseIndent, SetClientString ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SerializeToBuffer ( tStringObj *   pktString,
					XMP_OptionBits options /* = 0 */,
					XMP_StringLen  padding /* = 0 */ ) const
{
	this->SerializeToBuffer ( pktString, options, padding, "", "", 0 );
}

// -------------------------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetDefaultErrorCallback ( XMPMeta_ErrorCallbackProc proc,
						  void *    context /* = 0 */,
						  XMP_Uns32 limit /* = 1 */ )
{
	WrapCheckVoid ( zXMPMeta_SetDefaultErrorCallback_1 ( proc, context, limit ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
SetErrorCallback ( XMPMeta_ErrorCallbackProc proc,
				   void *    context /* = 0 */,
				   XMP_Uns32 limit /* = 1 */ )
{
	WrapCheckVoid ( zXMPMeta_SetErrorCallback_1 ( proc, context, limit ) );
}

// -------------------------------------------------------------------------------------------------

XMP_MethodIntro(TXMPMeta,void)::
ResetErrorCallbackLimit ( XMP_Uns32 limit /* = 1 */ )
{
	WrapCheckVoid ( zXMPMeta_ResetErrorCallbackLimit_1 ( limit ) );
}

// =================================================================================================
