1// ================================================================================================= 2// ADOBE SYSTEMS INCORPORATED 3// Copyright 2002-2008 Adobe Systems Incorporated 4// All Rights Reserved 5// 6// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms 7// of the Adobe license agreement accompanying it. 8// ================================================================================================= 9 10// ================================================================================================ 11/// \file TXMPUtils.incl_cpp 12/// \brief The implementation of the TXMPUtils template class. 13 14#include "XMPSDK.hpp" 15#include "client-glue/WXMP_Common.hpp" 16#include "client-glue/WXMPUtils.hpp" 17 18// ================================================================================================= 19// Implementation Guidelines 20// ========================= 21// 22// The implementations of the template functions are very stylized. ... 23// 24// ================================================================================================= 25 26XMP_MethodIntro(TXMPUtils,void):: 27ComposeArrayItemPath ( XMP_StringPtr schemaNS, 28 XMP_StringPtr arrayName, 29 XMP_Index itemIndex, 30 tStringObj * fullPath ) 31{ 32 XMP_StringPtr pathPtr = 0; 33 XMP_StringLen pathLen = 0; 34 WrapCheckVoid ( zXMPUtils_ComposeArrayItemPath_1 ( schemaNS, arrayName, itemIndex, &pathPtr, &pathLen ) ); 35 if ( fullPath != 0 ) fullPath->assign ( pathPtr, pathLen ); 36 WXMPUtils_Unlock_1 ( 0 ); 37} 38 39// ------------------------------------------------------------------------------------------------- 40 41XMP_MethodIntro(TXMPUtils,void):: 42ComposeStructFieldPath ( XMP_StringPtr schemaNS, 43 XMP_StringPtr structName, 44 XMP_StringPtr fieldNS, 45 XMP_StringPtr fieldName, 46 tStringObj * fullPath ) 47{ 48 XMP_StringPtr pathPtr = 0; 49 XMP_StringLen pathLen = 0; 50 WrapCheckVoid ( zXMPUtils_ComposeStructFieldPath_1 ( schemaNS, structName, fieldNS, fieldName, &pathPtr, &pathLen ) ); 51 if ( fullPath != 0 ) fullPath->assign ( pathPtr, pathLen ); 52 WXMPUtils_Unlock_1 ( 0 ); 53} 54 55// ------------------------------------------------------------------------------------------------- 56 57XMP_MethodIntro(TXMPUtils,void):: 58ComposeQualifierPath ( XMP_StringPtr schemaNS, 59 XMP_StringPtr propName, 60 XMP_StringPtr qualNS, 61 XMP_StringPtr qualName, 62 tStringObj * fullPath ) 63{ 64 XMP_StringPtr pathPtr = 0; 65 XMP_StringLen pathLen = 0; 66 WrapCheckVoid ( zXMPUtils_ComposeQualifierPath_1 ( schemaNS, propName, qualNS, qualName, &pathPtr, &pathLen ) ); 67 if ( fullPath != 0 ) fullPath->assign ( pathPtr, pathLen ); 68 WXMPUtils_Unlock_1 ( 0 ); 69} 70 71// ------------------------------------------------------------------------------------------------- 72 73XMP_MethodIntro(TXMPUtils,void):: 74ComposeLangSelector ( XMP_StringPtr schemaNS, 75 XMP_StringPtr arrayName, 76 XMP_StringPtr langName, 77 tStringObj * fullPath ) 78{ 79 XMP_StringPtr pathPtr = 0; 80 XMP_StringLen pathLen = 0; 81 WrapCheckVoid ( zXMPUtils_ComposeLangSelector_1 ( schemaNS, arrayName, langName, &pathPtr, &pathLen ) ); 82 if ( fullPath != 0 ) fullPath->assign ( pathPtr, pathLen ); 83 WXMPUtils_Unlock_1 ( 0 ); 84} 85 86// ------------------------------------------------------------------------------------------------- 87 88XMP_MethodIntro(TXMPUtils,void):: 89ComposeLangSelector ( XMP_StringPtr schemaNS, 90 XMP_StringPtr arrayName, 91 const tStringObj & langName, 92 tStringObj * fullPath ) 93{ 94 TXMPUtils::ComposeLangSelector ( schemaNS, arrayName, langName.c_str(), fullPath ); 95} 96 97// ------------------------------------------------------------------------------------------------- 98 99XMP_MethodIntro(TXMPUtils,void):: 100ComposeFieldSelector ( XMP_StringPtr schemaNS, 101 XMP_StringPtr arrayName, 102 XMP_StringPtr fieldNS, 103 XMP_StringPtr fieldName, 104 XMP_StringPtr fieldValue, 105 tStringObj * fullPath ) 106{ 107 XMP_StringPtr pathPtr = 0; 108 XMP_StringLen pathLen = 0; 109 WrapCheckVoid ( zXMPUtils_ComposeFieldSelector_1 ( schemaNS, arrayName, fieldNS, fieldName, fieldValue, 110 &pathPtr, &pathLen ) ); 111 if ( fullPath != 0 ) fullPath->assign ( pathPtr, pathLen ); 112 WXMPUtils_Unlock_1 ( 0 ); 113} 114 115// ------------------------------------------------------------------------------------------------- 116 117XMP_MethodIntro(TXMPUtils,void):: 118ComposeFieldSelector ( XMP_StringPtr schemaNS, 119 XMP_StringPtr arrayName, 120 XMP_StringPtr fieldNS, 121 XMP_StringPtr fieldName, 122 const tStringObj & fieldValue, 123 tStringObj * fullPath ) 124{ 125 TXMPUtils::ComposeFieldSelector ( schemaNS, arrayName, fieldNS, fieldName, fieldValue.c_str(), fullPath ); 126} 127 128// ------------------------------------------------------------------------------------------------- 129// ------------------------------------------------------------------------------------------------- 130 131XMP_MethodIntro(TXMPUtils,void):: 132ConvertFromBool ( bool binValue, 133 tStringObj * strValue ) 134{ 135 XMP_StringPtr strPtr = 0; 136 XMP_StringLen strLen = 0; 137 WrapCheckVoid ( zXMPUtils_ConvertFromBool_1 ( binValue, &strPtr, &strLen ) ); 138 if ( strValue != 0 ) strValue->assign ( strPtr, strLen ); 139 WXMPUtils_Unlock_1 ( 0 ); 140} 141 142// ------------------------------------------------------------------------------------------------- 143 144XMP_MethodIntro(TXMPUtils,void):: 145ConvertFromInt ( long binValue, 146 XMP_StringPtr format, 147 tStringObj * strValue ) 148{ 149 XMP_StringPtr strPtr = 0; 150 XMP_StringLen strLen = 0; 151 WrapCheckVoid ( zXMPUtils_ConvertFromInt_1 ( binValue, format, &strPtr, &strLen ) ); 152 if ( strValue != 0 ) strValue->assign ( strPtr, strLen ); 153 WXMPUtils_Unlock_1 ( 0 ); 154} 155 156// ------------------------------------------------------------------------------------------------- 157 158XMP_MethodIntro(TXMPUtils,void):: 159ConvertFromInt64 ( long long binValue, 160 XMP_StringPtr format, 161 tStringObj * strValue ) 162{ 163 XMP_StringPtr strPtr = 0; 164 XMP_StringLen strLen = 0; 165 WrapCheckVoid ( zXMPUtils_ConvertFromInt64_1 ( binValue, format, &strPtr, &strLen ) ); 166 if ( strValue != 0 ) strValue->assign ( strPtr, strLen ); 167 WXMPUtils_Unlock_1 ( 0 ); 168} 169 170// ------------------------------------------------------------------------------------------------- 171 172XMP_MethodIntro(TXMPUtils,void):: 173ConvertFromFloat ( double binValue, 174 XMP_StringPtr format, 175 tStringObj * strValue ) 176{ 177 XMP_StringPtr strPtr = 0; 178 XMP_StringLen strLen = 0; 179 WrapCheckVoid ( zXMPUtils_ConvertFromFloat_1 ( binValue, format, &strPtr, &strLen ) ); 180 if ( strValue != 0 ) strValue->assign ( strPtr, strLen ); 181 WXMPUtils_Unlock_1 ( 0 ); 182} 183 184// ------------------------------------------------------------------------------------------------- 185 186XMP_MethodIntro(TXMPUtils,void):: 187ConvertFromDate ( const XMP_DateTime & binValue, 188 tStringObj * strValue ) 189{ 190 XMP_StringPtr strPtr = 0; 191 XMP_StringLen strLen = 0; 192 WrapCheckVoid ( zXMPUtils_ConvertFromDate_1 ( binValue, &strPtr, &strLen ) ); 193 if ( strValue != 0 ) strValue->assign ( strPtr, strLen ); 194 WXMPUtils_Unlock_1 ( 0 ); 195} 196 197// ------------------------------------------------------------------------------------------------- 198 199XMP_MethodIntro(TXMPUtils,bool):: 200ConvertToBool ( XMP_StringPtr strValue ) 201{ 202 WrapCheckBool ( value, zXMPUtils_ConvertToBool_1 ( strValue ) ); 203 return value; 204} 205 206// ------------------------------------------------------------------------------------------------- 207 208XMP_MethodIntro(TXMPUtils,bool):: 209ConvertToBool ( const tStringObj & strValue ) 210{ 211 return TXMPUtils::ConvertToBool ( strValue.c_str() ); 212} 213 214// ------------------------------------------------------------------------------------------------- 215 216XMP_MethodIntro(TXMPUtils,long):: 217ConvertToInt ( XMP_StringPtr strValue ) 218{ 219 WrapCheckInt32 ( value, zXMPUtils_ConvertToInt_1 ( strValue ) ); 220 return value; 221} 222 223// ------------------------------------------------------------------------------------------------- 224 225XMP_MethodIntro(TXMPUtils,long):: 226ConvertToInt ( const tStringObj & strValue ) 227{ 228 return TXMPUtils::ConvertToInt ( strValue.c_str() ); 229} 230 231// ------------------------------------------------------------------------------------------------- 232 233XMP_MethodIntro(TXMPUtils,long long):: 234ConvertToInt64 ( XMP_StringPtr strValue ) 235{ 236 WrapCheckInt64 ( value, zXMPUtils_ConvertToInt64_1 ( strValue ) ); 237 return value; 238} 239 240// ------------------------------------------------------------------------------------------------- 241 242XMP_MethodIntro(TXMPUtils,long long):: 243ConvertToInt64 ( const tStringObj & strValue ) 244{ 245 return TXMPUtils::ConvertToInt64 ( strValue.c_str() ); 246} 247 248// ------------------------------------------------------------------------------------------------- 249 250XMP_MethodIntro(TXMPUtils,double):: 251ConvertToFloat ( XMP_StringPtr strValue ) 252{ 253 WrapCheckFloat ( value, zXMPUtils_ConvertToFloat_1 ( strValue ) ); 254 return value; 255} 256 257// ------------------------------------------------------------------------------------------------- 258 259XMP_MethodIntro(TXMPUtils,double):: 260ConvertToFloat ( const tStringObj & strValue ) 261{ 262 return TXMPUtils::ConvertToFloat ( strValue.c_str() ); 263} 264 265// ------------------------------------------------------------------------------------------------- 266 267XMP_MethodIntro(TXMPUtils,void):: 268ConvertToDate ( XMP_StringPtr strValue, 269 XMP_DateTime * binValue ) 270{ 271 WrapCheckVoid ( zXMPUtils_ConvertToDate_1 ( strValue, binValue ) ); 272} 273 274// ------------------------------------------------------------------------------------------------- 275 276XMP_MethodIntro(TXMPUtils,void):: 277ConvertToDate ( const tStringObj & strValue, 278 XMP_DateTime * binValue ) 279{ 280 TXMPUtils::ConvertToDate ( strValue.c_str(), binValue ); 281} 282 283// ------------------------------------------------------------------------------------------------- 284// ------------------------------------------------------------------------------------------------- 285 286XMP_MethodIntro(TXMPUtils,void):: 287CurrentDateTime ( XMP_DateTime * time ) 288{ 289 WrapCheckVoid ( zXMPUtils_CurrentDateTime_1 ( time ) ); 290} 291 292// ------------------------------------------------------------------------------------------------- 293 294XMP_MethodIntro(TXMPUtils,void):: 295SetTimeZone ( XMP_DateTime * time ) 296{ 297 WrapCheckVoid ( zXMPUtils_SetTimeZone_1 ( time ) ); 298} 299 300// ------------------------------------------------------------------------------------------------- 301 302XMP_MethodIntro(TXMPUtils,void):: 303ConvertToUTCTime ( XMP_DateTime * time ) 304{ 305 WrapCheckVoid ( zXMPUtils_ConvertToUTCTime_1 ( time ) ); 306} 307 308// ------------------------------------------------------------------------------------------------- 309 310XMP_MethodIntro(TXMPUtils,void):: 311ConvertToLocalTime ( XMP_DateTime * time ) 312{ 313 WrapCheckVoid ( zXMPUtils_ConvertToLocalTime_1 ( time ) ); 314} 315 316// ------------------------------------------------------------------------------------------------- 317 318XMP_MethodIntro(TXMPUtils,int):: 319CompareDateTime ( const XMP_DateTime & left, 320 const XMP_DateTime & right ) 321{ 322 WrapCheckInt32 ( result, zXMPUtils_CompareDateTime_1 ( left, right ) ); 323 return result; 324} 325 326// ------------------------------------------------------------------------------------------------- 327// ------------------------------------------------------------------------------------------------- 328 329XMP_MethodIntro(TXMPUtils,void):: 330EncodeToBase64 ( XMP_StringPtr rawStr, 331 XMP_StringLen rawLen, 332 tStringObj * encodedStr ) 333{ 334 XMP_StringPtr encPtr = 0; 335 XMP_StringLen encLen = 0; 336 WrapCheckVoid ( zXMPUtils_EncodeToBase64_1 ( rawStr, rawLen, &encPtr, &encLen ) ); 337 if ( encodedStr != 0 ) encodedStr->assign ( encPtr, encLen ); 338 WXMPUtils_Unlock_1 ( 0 ); 339} 340 341// ------------------------------------------------------------------------------------------------- 342 343XMP_MethodIntro(TXMPUtils,void):: 344EncodeToBase64 ( const tStringObj & rawStr, 345 tStringObj * encodedStr ) 346{ 347 TXMPUtils::EncodeToBase64 ( rawStr.c_str(), (XMP_StringLen)rawStr.size(), encodedStr ); 348} 349 350// ------------------------------------------------------------------------------------------------- 351 352XMP_MethodIntro(TXMPUtils,void):: 353DecodeFromBase64 ( XMP_StringPtr encodedStr, 354 XMP_StringLen encodedLen, 355 tStringObj * rawStr ) 356{ 357 XMP_StringPtr rawPtr = 0; 358 XMP_StringLen rawLen = 0; 359 WrapCheckVoid ( zXMPUtils_DecodeFromBase64_1 ( encodedStr, encodedLen, &rawPtr, &rawLen ) ); 360 if ( rawStr != 0 ) rawStr->assign ( rawPtr, rawLen ); 361 WXMPUtils_Unlock_1 ( 0 ); 362} 363 364// ------------------------------------------------------------------------------------------------- 365 366XMP_MethodIntro(TXMPUtils,void):: 367DecodeFromBase64 ( const tStringObj & encodedStr, 368 tStringObj * rawStr ) 369{ 370 TXMPUtils::DecodeFromBase64 ( encodedStr.c_str(), (XMP_StringLen)encodedStr.size(), rawStr ); 371} 372 373// ------------------------------------------------------------------------------------------------- 374// ------------------------------------------------------------------------------------------------- 375 376// ------------------------------------------------------------------------------------------------- 377 378XMP_MethodIntro(TXMPUtils,void):: 379PackageForJPEG ( const TXMPMeta<tStringObj> & xmpObj, 380 tStringObj * standardXMP, 381 tStringObj * extendedXMP, 382 tStringObj * extendedDigest ) 383{ 384 XMP_StringPtr stdStr = 0; 385 XMP_StringLen stdLen = 0; 386 XMP_StringPtr extStr = 0; 387 XMP_StringLen extLen = 0; 388 XMP_StringPtr digestStr = 0; 389 XMP_StringLen digestLen = 0; 390 WrapCheckVoid ( zXMPUtils_PackageForJPEG_1 ( xmpObj.GetInternalRef(), 391 &stdStr, &stdLen, &extStr, &extLen, &digestStr, &digestLen ) ); 392 if ( standardXMP != 0 ) standardXMP->assign ( stdStr, stdLen ); 393 if ( extendedXMP != 0 ) extendedXMP->assign ( extStr, extLen ); 394 if ( extendedDigest != 0 ) extendedDigest->assign ( digestStr, digestLen ); 395 WXMPUtils_Unlock_1 ( 0 ); 396} 397 398// ------------------------------------------------------------------------------------------------- 399 400XMP_MethodIntro(TXMPUtils,void):: 401MergeFromJPEG ( TXMPMeta<tStringObj> * fullXMP, 402 const TXMPMeta<tStringObj> & extendedXMP ) 403{ 404 WrapCheckVoid ( zXMPUtils_MergeFromJPEG_1 ( fullXMP->GetInternalRef(), extendedXMP.GetInternalRef() ) ); 405} 406 407// ------------------------------------------------------------------------------------------------- 408// ------------------------------------------------------------------------------------------------- 409 410XMP_MethodIntro(TXMPUtils,void):: 411CatenateArrayItems ( const TXMPMeta<tStringObj> & xmpObj, 412 XMP_StringPtr schemaNS, 413 XMP_StringPtr arrayName, 414 XMP_StringPtr separator, 415 XMP_StringPtr quotes, 416 XMP_OptionBits options, 417 tStringObj * catedStr ) 418{ 419 XMP_StringPtr catedPtr = 0; 420 XMP_StringLen catedLen = 0; 421 WrapCheckVoid ( zXMPUtils_CatenateArrayItems_1 ( xmpObj.GetInternalRef(), schemaNS, arrayName, 422 separator, quotes, options, &catedPtr, &catedLen ) ); 423 if ( catedStr != 0 ) catedStr->assign ( catedPtr, catedLen ); 424 WXMPUtils_Unlock_1 ( 0 ); 425} 426 427// ------------------------------------------------------------------------------------------------- 428 429XMP_MethodIntro(TXMPUtils,void):: 430SeparateArrayItems ( TXMPMeta<tStringObj> * xmpObj, 431 XMP_StringPtr schemaNS, 432 XMP_StringPtr arrayName, 433 XMP_OptionBits options, 434 XMP_StringPtr catedStr ) 435{ 436 if ( xmpObj == 0 ) throw XMP_Error ( kXMPErr_BadParam, "Null output SXMPMeta pointer" ); 437 WrapCheckVoid ( zXMPUtils_SeparateArrayItems_1 ( xmpObj->GetInternalRef(), schemaNS, arrayName, options, catedStr ) ); 438} 439 440// ------------------------------------------------------------------------------------------------- 441 442XMP_MethodIntro(TXMPUtils,void):: 443SeparateArrayItems ( TXMPMeta<tStringObj> * xmpObj, 444 XMP_StringPtr schemaNS, 445 XMP_StringPtr arrayName, 446 XMP_OptionBits options, 447 const tStringObj & catedStr ) 448{ 449 TXMPUtils::SeparateArrayItems ( xmpObj, schemaNS, arrayName, options, catedStr.c_str() ); 450} 451 452// ------------------------------------------------------------------------------------------------- 453 454XMP_MethodIntro(TXMPUtils,void):: 455RemoveProperties ( TXMPMeta<tStringObj> * xmpObj, 456 XMP_StringPtr schemaNS /* = 0 */, 457 XMP_StringPtr propName /* = 0 */, 458 XMP_OptionBits options /* = 0 */ ) 459{ 460 if ( xmpObj == 0 ) throw XMP_Error ( kXMPErr_BadParam, "Null output SXMPMeta pointer" ); 461 WrapCheckVoid ( zXMPUtils_RemoveProperties_1 ( xmpObj->GetInternalRef(), schemaNS, propName, options ) ); 462} 463 464// ------------------------------------------------------------------------------------------------- 465 466XMP_MethodIntro(TXMPUtils,void):: 467AppendProperties ( const TXMPMeta<tStringObj> & source, 468 TXMPMeta<tStringObj> * dest, 469 XMP_OptionBits options /* = 0 */ ) 470{ 471 if ( dest == 0 ) throw XMP_Error ( kXMPErr_BadParam, "Null output SXMPMeta pointer" ); 472 WrapCheckVoid ( zXMPUtils_AppendProperties_1 ( source.GetInternalRef(), dest->GetInternalRef(), options ) ); 473} 474 475// ------------------------------------------------------------------------------------------------- 476 477XMP_MethodIntro(TXMPUtils,void):: 478DuplicateSubtree ( const TXMPMeta<tStringObj> & source, 479 TXMPMeta<tStringObj> * dest, 480 XMP_StringPtr sourceNS, 481 XMP_StringPtr sourceRoot, 482 XMP_StringPtr destNS /*= 0 */, 483 XMP_StringPtr destRoot /* = 0 */, 484 XMP_OptionBits options /* = 0 */ ) 485{ 486 if ( dest == 0 ) throw XMP_Error ( kXMPErr_BadParam, "Null output SXMPMeta pointer" ); 487 WrapCheckVoid ( zXMPUtils_DuplicateSubtree_1 ( source.GetInternalRef(), dest->GetInternalRef(), 488 sourceNS, sourceRoot, destNS, destRoot, options ) ); 489} 490 491// ================================================================================================= 492 493// ================================================================================================= 494