1 //  ----------------------------------------------------------------------------
2 //  MODULE    : OLEProperties.cpp
3 //  LANGUAGE  : C++
4 //  AUTHOR    : Yue Zhang
5 //  DATE    : Tuesday, Janurary 23, 1996
6 //  DESCRIPTION : This file contains  OLE Property Set object
7 //
8 //  COMMENT   : An OLEProperty class contains a variant structure which holds
9 //          all the data types defined in the property set (see also variant.h
10 //          and OLEcomm.h ). Including,
11 //
12 //              PROPERTY TYPE       DATA TYPE
13 //                VT_EMPTY,           no bytes
14 //                VT_NULL,            no bytes
15 //                VT_I1,    VT_UI1,   char/ unsigned char
16 //                VT_I2,    VT_UI2,   short/ unsigned short
17 //                VT_I4,    VT_UI4,   long/ unsigned long
18 //                VT_R4,              float
19 //                VT_R8,              double
20 //                VT_INT,   VT_UINT,  int/unsigned int
21 //                VT_I8,    VT_UI8,   int/unsigned int
22 //                VT_BOOL,            boolean (short)
23 //                VT_ERROR,           SCODE (int32_t)
24 //                VT_CY,              CY ({ long, unsigned long })
25 //                VT_DATE,            DATE (double)
26 //                VT_FILETIME,        FILETIME ({unsigned long, unsigned long})
27 //                VT_LPSTR,           char *
28 //                VT_BSTR,            char *
29 //                VT_LPWSTR,          unsigned short *
30 //                VT_BLOB,            BLOB ({unsigned long, unsigned char *})
31 //                VT_CF,              CLIPDATA ({unsigned long, unsigned long, unsigned char *})
32 //                VT_CLSID,           CLSID (two short, one long, 8 bytes)
33 //                VT_VARIANT,         VARIANT (four short, one double)
34 //                VT_VECTOR,          VECTOR (unsigned long, BYTE *)
35 //                VT_STREAM,          LPSTR
36 //                VT_STORAGE,         LPSTR
37 //                VT_STREAMED_OBJECT, LPSTR
38 //                VT_STORED_OBJECT,   LPSTR
39 //                VT_BLOB_OBJECT,     LPSTR
40 //
41 //        OLEProperty class also supports data types defined in the FPXBaselineIO.h,
42 //        Including,
43 //
44 //                FPXStr,                     { unsigned long, unsigned char * }
45 //                FPXShortArray,              { unsigned long, unsigned short * }
46 //                FPXLongArray,               { unsigned long, unsigned long * }
47 //                FPXRealArray,               { unsigned long, float * }
48 //                FPXWideStr,                 { unsigned long, unsigned short * }
49 //                FPXWideStrArray,            { unsigned long, FPXWideStr * }
50 //                FPXStrArray,                { unsigned long, FPXStr * }
51 //                FPXfiletime,                { unsigned long, unsigned long }
52 //                FPXSpacialFrequencyResponseBlockArray  { unsigned long, FPXSpacialFrequencyResponseBlock* }
53 //                FPXCFA_PatternBlockArray    { unsigned long, FPXCFA_PatternBlock* }
54 //                FPXOECF_BlockArray          { unsigned long, FPXOECF_Block*}
55 //                FPXScannedImageSizeBlock    { float, float, FPXResolutionUnit }
56 //
57 //  SCCSID            : @(#)oleprop.cpp 1.5 10:45:17 12 Sep 1997
58 //  ----------------------------------------------------------------------------
59 //  Copyright (c) 1999 Digital Imaging Group, Inc.
60 //  For conditions of distribution and use, see copyright notice
61 //  in Flashpix.h
62 //  ----------------------------------------------------------------------------
63 
64 //  Includes
65 //  --------
66 
67 #if defined(USE_LEGACY_INCLUDES)
68 #  include <iostream.h>
69 #  include <fstream.h>
70 #else
71 #  include <iostream>
72 #  include <fstream>
73    using namespace std;
74 #endif
75 
76 #ifndef OLECommun_h
77   #include "olecomm.h"
78 #endif
79 #ifndef FlashPixUtils_h
80   #include "fpxutils.h"
81 #endif
82 #ifndef OLECore_h
83   #include "olecore.h"
84 #endif
85 #ifndef OLEProperties_h
86   #include  "oleprop.h"
87 #endif
88 #ifndef OLEPropertySet_h
89   #include  "oleprops.h"
90 #endif
91 
92 //  Constants
93 //  ---------
94 
95 //  Variables
96 //  ---------
97 
98 //  ----------------------------------------------------------------------------
99 
100 //  ----------------------------------------------------------------------------
101 
102 //  ----------------------------------------------------------------------------
103 //  Methods
104 //  ----------------------------------------------------------------------------
105 
106 
107 //-------------------------------------------------------------------------------------------
108 //          OLEProperties functions
109 //-------------------------------------------------------------------------------------------
110 
111 // This function creates an OLEProperty class from a property set and section with property ID
112 // and type specified
OLEProperty(OLEPropertySet * parentPropSet,OLEPropertySection * parentPropSection,DWORD properID,DWORD properType)113 OLEProperty::OLEProperty (OLEPropertySet* parentPropSet, OLEPropertySection *parentPropSection,
114     DWORD properID, DWORD properType)
115 {
116   parPropSet    = parentPropSet;                  // Keep the property set from which it is created
117   OLEPropSec    = parentPropSection;              // Keep the property section from which it is created
118   propID        = properID;                       // Store the property ID
119   V_VT(&val)    = (unsigned short) properType;    // Store the property type
120   len           = parPropSet->SizeVT(properType); // Get the size of property
121   Clear();                                        // Reset the variant structure in which alldata is
122   // going to be stored
123   pDict = 0;                                      // FIX_DICT_PROP - clear dictionary pointer
124 }
125 
~OLEProperty()126 OLEProperty::~OLEProperty ()
127 {
128   // If the data has been dynamically allocated, delete it
129   switch (val.vt)
130   {
131     case VT_LPSTR:
132     case VT_BSTR: {
133       delete[] V_UI1REF(&val);
134       break;
135     }
136     case VT_LPWSTR: {
137       delete[] (unsigned short *)V_BYREF(&val);
138       break;
139     }
140     case VT_BLOB: {
141       BLOB *pblob = (BLOB *)V_BYREF(&val);
142       DeleteBLOB(pblob);
143       break;
144     }
145     case VT_CF: {
146       CLIPDATA *pcf = (CLIPDATA *)V_BYREF(&val);
147       DeleteCF(pcf);
148       break;
149     }
150   }
151 
152   // If the data is VECTOR, delete it depending on the subtype
153   if ( V_VT(&val) & VT_VECTOR )
154   {
155     VECTOR *pver = (VECTOR *)V_BYREF(&val);
156     DeleteVECTOR(pver, V_VT(&val));
157   }
158 
159   // If the data is DICT_PROP, delete it and it's contents
160   if ( pDict && ( GetPropType() == DICT_PROP_TYPE ))
161     DeleteDICTIONARY(pDict);
162 
163 }
164 
165 
166 //-------------------------------------------------------------------------------------
167 //  The following functions extract VT data types defined in variant.h from the
168 //  OLEProperty class through operator =
169 //-------------------------------------------------------------------------------------
170 
operator short() const171 OLEProperty::operator short() const   { return short(V_I2(&val)); }
operator WORD() const172 OLEProperty::operator WORD() const                  { return (WORD)(V_I2(&val)); }
operator DWORD() const173 OLEProperty::operator DWORD() const           { return (DWORD)(V_I4(&val)); }
operator int() const174 OLEProperty::operator int() const    { return int(V_I4(&val)); }
operator float() const175 OLEProperty::operator float() const   { return float(V_R4(&val)); }
operator double() const176 OLEProperty::operator double() const    { return double(V_R8(&val)); }
operator Boolean() const177 OLEProperty::operator Boolean() const   { return (V_BOOL(&val) != 0); }
operator CY() const178 OLEProperty::operator CY() const    { return CY(V_CY(&val)); }
operator FILETIME() const179 OLEProperty::operator FILETIME() const          { return *(FILETIME *)(&V_CY(&val)); }
180 
operator char*() const181 OLEProperty::operator char*() const
182 {
183   char* str = (char *)V_UI1REF(&val);
184 
185   return DuplicateStr(str);
186 }
187 
operator WCHAR*() const188 OLEProperty::operator WCHAR*() const
189 {
190   WCHAR* wstr = (WCHAR *)V_BYREF(&val);
191 
192   return DuplicateWideStr(wstr);
193 }
194 
operator CLSID*() const195 OLEProperty::operator CLSID*() const
196 {
197   CLSID *clsid = (CLSID *)V_BYREF(&val);
198 
199   if ( !clsid )
200     return NULL;
201 
202   CLSID *cd = new CLSID;
203   if ( !cd )
204     return NULL;
205 
206   memcpy(cd, clsid, sizeof(CLSID));
207 
208   return cd;
209 }
210 
operator const BLOB*() const211 OLEProperty::operator const BLOB*() const
212 {
213   return (const BLOB *)V_BYREF(&val);
214 }
215 
operator BLOB*() const216 OLEProperty::operator BLOB*() const
217 {
218   BLOB *pblob = (BLOB *)V_BYREF(&val);
219 
220   return DuplicateBLOB(pblob);
221 }
222 
operator const CLIPDATA*() const223 OLEProperty::operator const CLIPDATA*() const
224 {
225   return (const CLIPDATA *)V_BYREF(&val);
226 }
227 
operator CLIPDATA*() const228 OLEProperty::operator CLIPDATA*() const
229 {
230   CLIPDATA *pClipData = (CLIPDATA *)V_BYREF(&val);
231 
232   return DuplicateCF(pClipData);
233 }
234 
operator const VECTOR*() const235 OLEProperty::operator const VECTOR*() const
236 {
237   return (const VECTOR *)V_BYREF(&val);
238 }
239 
operator VECTOR*() const240 OLEProperty::operator VECTOR*() const
241 {
242   VECTOR *pvec = (VECTOR *)V_BYREF(&val);
243 
244   return DuplicateVECTOR(pvec, V_VT(&val));
245 }
246 
247 //-------------------------------------------------------------------------------------
248 //  The following functions assign VT data types defined in variant.h to the
249 //  OLEProperty class through operator =
250 //-------------------------------------------------------------------------------------
251 
operator =(const short & v)252 short&    OLEProperty::operator=(const short& v)    { Clear(); V_I2(&val) = v; return V_I2(&val); }
operator =(const WORD & v)253 WORD&   OLEProperty::operator=(const WORD& v)   { Clear(); V_I2(&val) = v; return (WORD&)V_I2(&val); }
operator =(const int32_t & v)254 int32_t&   OLEProperty::operator=(const int32_t& v)   { Clear(); V_I4(&val) = v; return V_I4(&val); }
operator =(const DWORD & v)255 DWORD&    OLEProperty::operator=(const DWORD& v)    { Clear(); V_I4(&val) = v; return (DWORD&)V_I4(&val); }
operator =(const float & v)256 float&    OLEProperty::operator=(const float& v)    { Clear(); V_R4(&val) = v; return V_R4(&val); }
operator =(const double & v)257 double&   OLEProperty::operator=(const double& v)   { Clear(); V_R8(&val) = v; return V_R8(&val); }
operator =(const Boolean & v)258 Boolean&  OLEProperty::operator=(const Boolean& v)  { Clear(); V_BOOL(&val) = v; return (Boolean&)V_BOOL(&val); }
operator =(const CY & v)259 CY&     OLEProperty::operator=(const CY& v)     { Clear(); V_CY(&val) = v; return V_CY(&val); }
operator =(const FILETIME & v)260 FILETIME& OLEProperty::operator=(const FILETIME& v) { Clear(); V_CY(&val) = *((CY *)&v); return *((FILETIME *)&V_CY(&val)); }
261 // FILETIME&  OLEProperty::operator=(const FILETIME& v) { Clear(); *(FILETIME*)(V_CY(&val)) = v; return *(FILETIME*)(V_CY(&val)); }
262 
263 // This function assigns LPSTR to the OLEProperty class through operator =
operator =(const char * v)264 void OLEProperty::operator=(const char * v)
265 {
266   // Save the string into variant, new memory is allocated
267   len = VTtoVariant(&val, v);
268 }
269 
270 // This function assigns LPWSTR to the OLEProperty class through operator =
operator =(const WCHAR * v)271 void OLEProperty::operator=(const WCHAR * v)
272 {
273   // Save the wide string into variant, new memory is allocated
274   len = VTtoVariant(&val, v);
275 
276 }
277 
278 // This function assigns BLOB to the OLEProperty class through operator =
operator =(const BLOB * pblob)279 void OLEProperty::operator=(const BLOB* pblob)
280 {
281   // Save the blob into variant, new memory is allocated
282   len = VTtoVariant(&val, pblob);
283 
284 }
285 
286 // This function assigns CLIPDATA to the OLEProperty class through operator =
operator =(const CLIPDATA * pcf)287 void OLEProperty::operator=(const CLIPDATA * pcf)
288 {
289   // Save the clipdata into variant, new memory is allocated
290   len = VTtoVariant(&val, pcf);
291 
292 }
293 
294 // This function assigns CLSID to the OLEProperty class through operator =
operator =(const CLSID * pcls)295 void OLEProperty::operator=(const CLSID * pcls)
296 {
297   // Save the clsid into variant, new memory is allocated
298   len = VTtoVariant(&val, pcls);
299 
300 }
301 
302 // This function assigns VECTOR to the OLEProperty class through operator =
operator =(const VECTOR * pvector)303 void OLEProperty::operator=(const VECTOR * pvector)
304 {
305   // Save the vector into variant, new memory is allocated
306   len = VTtoVariant(&val, pvector);
307 
308 }
309 
310 
311 //-------------------------------------------------------------------------------------
312 //  The following functions save VT type data into variant structure
313 //-------------------------------------------------------------------------------------
314 
315 // This function duplicate the string and save it into variant
VTtoVariant(VARIANT * pvar,const char * v)316 DWORD VTtoVariant(VARIANT* pvar, const char * v)
317 {
318   char* str;
319 
320   // Duplicate a string
321   if ( !( str = DuplicateStr(v)) )
322     return 0;
323 
324   // Delete the variant contents if it has been allocated before
325   if (V_UI1REF(pvar))
326     delete V_UI1REF(pvar);
327 
328   // Clear the variant
329   V_R8(pvar) = 0;
330 
331   // Save the string into variant.bstrVal
332 #if defined(_WINDOWS)
333   V_UI1REF(pvar) = (unsigned char *)str;
334 #else
335   V_UI1REF(pvar) = (char *)str;
336 #endif
337 
338   return strlen(str);
339 }
340 
341 // This function duplicate the wide string and save it into variant
VTtoVariant(VARIANT * pvar,const WCHAR * v)342 DWORD VTtoVariant(VARIANT* pvar, const WCHAR * v)
343 {
344   WCHAR* wstr;
345 
346   // Duplicate a wide string
347   if ( !( wstr = DuplicateWideStr(v)) )
348     return 0;
349 
350   // Delete the variant contents if it has been allocated before
351   if (V_BYREF(pvar))
352     delete (char *)V_BYREF(pvar);
353 
354   // Clear the variant
355   V_R8(pvar) = 0;
356 
357   // Save the wide string into variant.byref
358   V_BYREF(pvar) = (WCHAR *)wstr;
359 
360   return wcslen(wstr) * sizeof(WCHAR);
361 }
362 
363 // This function duplicate the blob and save it into variant
VTtoVariant(VARIANT * pvar,const BLOB * pblob)364 DWORD VTtoVariant(VARIANT* pvar, const BLOB * pblob)
365 {
366   BLOB* pb;
367 
368   // Duplicate a blob
369   if ( !( pb = DuplicateBLOB(pblob)) )
370     return 0;
371 
372   // Delete the variant contents if it has been allocated before
373   if (V_BYREF(pvar)) {
374     BLOB *tempBlob = (BLOB *)V_BYREF(pvar);
375     DeleteBLOB(tempBlob);
376   }
377 
378   // Clear the variant
379   V_R8(pvar) = 0;
380 
381   // Save the blob into variant.byref
382   V_BYREF(pvar) = pb;
383 
384   return sizeof(DWORD) + pb->cbSize;
385 }
386 
387 // This function duplicate the clipdata and save it into variant
VTtoVariant(VARIANT * pvar,const CLIPDATA * pcf)388 DWORD VTtoVariant(VARIANT* pvar, const CLIPDATA * pcf)
389 {
390   CLIPDATA* pc;
391 
392   // Duplicate a clipdata
393   if ( !( pc = DuplicateCF(pcf)) )
394     return 0;
395 
396   // Delete the variant contents if it has been allocated before
397   if (V_BYREF(pvar)) {
398     CLIPDATA *tempcf = (CLIPDATA *)V_BYREF(pvar);
399     DeleteCF(tempcf);
400   }
401 
402   // Clear the variant
403   V_R8(pvar) = 0;
404 
405   // Save the clipdata into variant.byref
406   V_BYREF(pvar) = pc;
407 
408   return sizeof(DWORD) + pc->cbSize;
409 }
410 
411 // This function duplicate the clsid and save it into variant
VTtoVariant(VARIANT * pvar,const CLSID * pcls)412 DWORD VTtoVariant(VARIANT* pvar, const CLSID * pcls)
413 {
414   // Allocate and copy the memory
415   CLSID * pclsid  = new CLSID;
416   if (pclsid == NULL) {
417     return 0;
418   }
419   memcpy(pclsid, pcls, sizeof(CLSID));
420 
421   // Delete the variant contents if it has been allocated before
422   if (V_BYREF(pvar))
423     delete (char *)V_BYREF(pvar);
424 
425   // Clear the variant
426   V_R8(pvar) = 0;
427 
428   // Save the clsid into variant.byref
429   V_BYREF(pvar) = pclsid;
430 
431   return sizeof(CLSID);
432 }
433 
434 // This function duplicate the vector and save it into variant
VTtoVariant(VARIANT * pvar,const VECTOR * pvector)435 DWORD VTtoVariant(VARIANT* pvar, const VECTOR * pvector)
436 {
437   DWORD type;
438 
439   // If the type is not vector, return NULL
440   if ( !(pvar->vt & VT_VECTOR) )
441     return 0;
442 
443   // Get the subtype of vector
444   type  = pvar->vt;
445   type  ^= VT_VECTOR;
446 
447   // Allocate a new vector
448   VECTOR * pvec = DuplicateVECTOR(pvector, type);
449   if ( !pvec ) {
450     return 0;
451   }
452 
453   // If the VECTOR already exists, delete it first
454   VECTOR *pver = (VECTOR *)V_BYREF(pvar);
455   if ( pver )
456     DeleteVECTOR(pver, V_VT(pvar));
457 
458   V_R8(pvar) = 0;
459 
460   // Put the vector pointer into variant.byref
461   V_BYREF(pvar)   = pvec;
462 
463   return TRUE;
464 }
465 
466 
467 //-------------------------------------------------------------------------------------
468 //  The following functions extract data types defined in FPXBaselineIO.h from the
469 //  OLEProperty class through operator =
470 //-------------------------------------------------------------------------------------
471 
472 // This function extracts FPXStr from OLEProperty class through operator =
473 // The FPXStr is stored as VT_LPSTR type in OLEProperty class
operator FPXStr() const474 OLEProperty::operator FPXStr() const
475 {
476   // Get the string pointer which is referenced by V_BSTR
477   char *buf = (char *)V_UI1REF(&val);
478 
479   // Return the FPX string
480   return LPSTRToFPXStr(buf);
481 }
482 
483 // This function extracts FPXWideStr from OLEProperty class through operator =
484 // The FPXWideStr is stored as VT_LPWSTR type in OLEProperty class
operator FPXWideStr() const485 OLEProperty::operator FPXWideStr() const
486 {
487   return LPWSTRToFPXWideStr((LPWSTR)V_BYREF(&val));
488 }
489 
490 // This function extracts FPXShortArray from OLEProperty class through operator =
491 // The FPXShortArray is stored as VT_UI2 | VT_VECTOR type in OLEProperty class
operator FPXShortArray() const492 OLEProperty::operator FPXShortArray() const
493 {
494   return VectorToFPXShortArray((VECTOR *)V_BYREF(&val));
495 }
496 
497 // This function extracts FPXLongArray from OLEProperty class through operator =
498 // The FPXLongArray is stored as VT_UI4 | VT_VECTOR type in OLEProperty class
operator FPXLongArray() const499 OLEProperty::operator FPXLongArray() const
500 {
501   return VectorToFPXLongArray((VECTOR *)V_BYREF(&val));
502 }
503 
504 // This function extracts FPXRealArray from OLEProperty class through operator =
505 // The FPXRealArray is stored as VT_R4 | VT_VECTOR type in OLEProperty class
operator FPXRealArray() const506 OLEProperty::operator FPXRealArray() const
507 {
508   return VectorToFPXRealArray((VECTOR *)V_BYREF(&val));
509 }
510 
511 // This function extracts FPXClsIDArray from OLEProperty class through operator =
512 // The FPXClsIDArray is stored as VT_CLSID | VT_VECTOR type in OLEProperty class
operator FPXClsIDArray() const513 OLEProperty::operator FPXClsIDArray() const
514 {
515   return VectorToFPXClsIDArray((VECTOR *)V_BYREF(&val));
516 }
517 
518 // This function extracts FPXStrArray from OLEProperty class through operator =
519 // The FPXStrArray is stored as VT_LPSTR | VT_VECTOR type in OLEProperty class
operator FPXStrArray() const520 OLEProperty::operator FPXStrArray() const
521 {
522   return VectorToFPXStrArray((VECTOR *)V_BYREF(&val));
523 }
524 
525 // This function extracts FPXWideStrArray from OLEProperty class through operator =
526 // The FPXWideStrArray is stored as VT_LPWSTR | VT_VECTOR type in OLEProperty class
operator FPXWideStrArray() const527 OLEProperty::operator FPXWideStrArray() const
528 {
529   return VectorToFPXWideStrArray((VECTOR *)V_BYREF(&val));
530 }
531 // PTCH_DCG - /**
532 // This function extracts FPXSpacialFrequencyResponseBlockArray from OLEProperty class
533 // through operator = . The FPXSpacialFrequencyResponseBlockArray is stored as VT_VARIANT
534 // | VT_VECTOR type in OLEProperty class
operator FPXSpacialFrequencyResponseBlock() const535 OLEProperty::operator FPXSpacialFrequencyResponseBlock() const
536 {
537   return VectorToFPXSpacialFrequencyResponseBlock((VECTOR *)V_BYREF(&val));
538 }
539 
540 // This function extracts FPXCFA_PatternBlockArray from OLEProperty class through
541 // operator = . The FPXCFA_PatternBlockArray is stored as VT_VARIANT | VT_VECTOR type
542 // in OLEProperty class
operator FPXCFA_PatternBlock() const543 OLEProperty::operator FPXCFA_PatternBlock() const
544 {
545   return VectorToFPXCFA_PatternBlock((VECTOR *)V_BYREF(&val));
546 }
547 
548 // This function extracts FPXOECF_BlockArray from OLEProperty class through
549 // operator = . The FPXOECF_BlockArray is stored as VT_VARIANT | VT_VECTOR type
550 // in OLEProperty class
operator FPXOECF_Block() const551 OLEProperty::operator FPXOECF_Block() const
552 {
553   return VectorToFPXOECF_Block((VECTOR *)V_BYREF(&val));
554 }
555 // PTCH_DCG - **/
556 // This function extracts FPXScannedImageSizeBlock from OLEProperty class through
557 // operator = . The FPXScannedImageSizeBlock is stored as VT_VARIANT | VT_VECTOR type
558 // in OLEProperty class
operator FPXScannedImageSizeBlock() const559 OLEProperty::operator FPXScannedImageSizeBlock() const
560 {
561   return VectorToFPXScannedImageSizeBlock((VECTOR *)V_BYREF(&val));
562 }
563 
operator FPXOpticalFilterArray() const564 OLEProperty::operator FPXOpticalFilterArray() const
565 {
566   return VectorToFPXOpticalFilterArray((VECTOR *)V_BYREF(&val));
567 }
568 
569 //-------------------------------------------------------------------------------------
570 //  The following functions assign data types defined in FPXBaselineIO.h to the
571 //  OLEProperty class through operator =
572 //-------------------------------------------------------------------------------------
573 
574 // This function assigns FPXStr to the OLEProperty class through operator =
575 // The FPXStr is stored as VT_LPSTR type in OLEProperty class
operator =(const FPXStr & fpxstr)576 const FPXStr& OLEProperty::operator=(const FPXStr& fpxstr)
577 {
578   // Assign the FPXStr to the variant
579   char * str = FPXStrToLPSTR(fpxstr);
580   *this = str;
581 
582   if ( str )
583     delete str;
584 
585   return fpxstr;
586 }
587 
588 // This function assigns FPXWideStr to the OLEProperty class through operator =
589 // The FPXWideStr is stored as VT_LPWSTR type in OLEProperty class
operator =(const FPXWideStr & fpxwstr)590 const FPXWideStr& OLEProperty::operator=(const FPXWideStr& fpxwstr)
591 {
592   // Assign the FPXWideStr to the variant
593   LPWSTR wstr = FPXWideStrToLPWSTR(fpxwstr);
594   *this = wstr;
595 
596   if ( wstr )
597     delete wstr;
598 
599   return fpxwstr;
600 }
601 
602 // This function assigns FPXShortArray to the OLEProperty class through operator =
603 // The FPXShortArray is stored as VT_UI2 | VT_VECTOR type in OLEProperty class
operator =(const FPXShortArray & sa)604 const FPXShortArray& OLEProperty::operator=(const FPXShortArray& sa)
605 {
606   // Convert the FPXShortArray to vector and assign to the OLEProperty
607   VECTOR* vec = FPXShortArrayToVector(sa);
608   *this = vec;
609   DeleteVECTOR(vec, VT_I2);
610 
611   return sa;
612 }
613 
614 // This function assigns FPXLongArray to the OLEProperty class through operator =
615 // The FPXLongArray is stored as VT_UI4 | VT_VECTOR type in OLEProperty class
operator =(const FPXLongArray & la)616 const FPXLongArray& OLEProperty::operator=(const FPXLongArray& la)
617 {
618   // Convert the FPXLongArray to vector and assign to the OLEProperty
619   VECTOR* vec = FPXLongArrayToVector(la);
620   *this = vec;
621   DeleteVECTOR(vec, VT_I4);
622 
623   return la;
624 }
625 
626 // This function assigns FPXRealArray to the OLEProperty class through operator =
627 // The FPXRealArray is stored as VT_R4 | VT_VECTOR type in OLEProperty class
operator =(const FPXRealArray & fa)628 const FPXRealArray& OLEProperty::operator=(const FPXRealArray& fa)
629 {
630   // Convert the FPXRealArray to vector and assign to the OLEProperty
631   VECTOR* vec = FPXRealArrayToVector(fa);
632   *this = vec;
633   DeleteVECTOR(vec, VT_R4);
634 
635   return fa;
636 }
637 
638 // This function assigns FPXClsIDArray to the OLEProperty class through operator =
639 // The FPXClsIDArray is stored as VT_CLSID | VT_VECTOR type in OLEProperty class
operator =(const FPXClsIDArray & ca)640 const FPXClsIDArray& OLEProperty::operator=(const FPXClsIDArray& ca)
641 {
642   // Convert the FPXClsIDArray to vector and assign to the OLEProperty
643   VECTOR* vec = FPXClsIDArrayToVector(ca);
644   *this = vec;
645   DeleteVECTOR(vec, VT_CLSID);
646 
647   return ca;
648 }
649 
650 // This function assigns FPXStrArray to the OLEProperty class through operator =
651 // The FPXStrArray is stored as VT_LPSTR | VT_VECTOR type in the OLEProperty class
operator =(const FPXStrArray & sa)652 const FPXStrArray& OLEProperty::operator=(const FPXStrArray& sa)
653 {
654   // Convert the FPXStrArray to vector and assign to the OLEProperty
655   VECTOR* vec = FPXStrArrayToVector(sa);
656   *this = vec;
657   DeleteVECTOR(vec, VT_LPSTR);
658 
659   return sa;
660 }
661 
662 // This function assigns FPXWideStrArray to the OLEProperty class through operator =
663 // The FPXWideStrArray is stored as VT_LPWSTR | VT_VECTOR type in the OLEProperty class
operator =(const FPXWideStrArray & wa)664 const FPXWideStrArray& OLEProperty::operator=(const FPXWideStrArray& wa)
665 {
666   // Convert the FPXWideStrArray to vector and assign to the OLEProperty
667   VECTOR* vec = FPXWideStrArrayToVector(wa);
668   *this = vec;
669   DeleteVECTOR(vec, VT_LPWSTR);
670 
671   return wa;
672 }
673 // PTCH_DCG - /**
674 // This function assigns FPXSpacialFrequencyResponseBlockArray to the OLEProperty class
675 // through operator = . The FPXSpacialFrequencyResponseBlockArray is stored as VT_VARIANT
676 // | VT_VECTOR type in the OLEProperty class
operator =(const FPXSpacialFrequencyResponseBlock & sfra)677 const FPXSpacialFrequencyResponseBlock& OLEProperty::operator=(const FPXSpacialFrequencyResponseBlock& sfra)
678 {
679   // Convert the FPXSpacialFrequencyResponseBlockArray to vector and assign to the OLEProperty
680   VECTOR* vec = FPXSpacialFrequencyResponseBlockToVector(sfra);
681   *this = vec;
682   DeleteVECTOR(vec, VT_VARIANT);
683 
684   return sfra;
685 }
686 
687 // This function assigns FPXCFA_PatternBlockArray to the OLEProperty class through operator =
688 // The FPXCFA_PatternBlockArray is stored as VT_VARIANT | VT_VECTOR type in the OLEProperty class
operator =(const FPXCFA_PatternBlock & cpba)689 const FPXCFA_PatternBlock& OLEProperty::operator=(const FPXCFA_PatternBlock& cpba)
690 {
691   // Convert the FPXCFA_PatternBlockArray to vector and assign to the OLEProperty
692   VECTOR* vec = FPXCFA_PatternBlockToVector(cpba);
693   *this = vec;
694   DeleteVECTOR(vec, VT_VARIANT);
695 
696   return cpba;
697 }
698 
699 // This function assigns FPXOECF_BlockArray to the OLEProperty class through operator =
700 // The FPXOECF_BlockArray is stored as VT_VARIANT | VT_VECTOR type in the OLEProperty class
operator =(const FPXOECF_Block & oba)701 const FPXOECF_Block& OLEProperty::operator=(const FPXOECF_Block& oba)
702 {
703   // Convert the FPXOECF_BlockArray to vector and assign to the OLEProperty
704   VECTOR* vec = FPXOECF_BlockToVector(oba);
705   *this = vec;
706   DeleteVECTOR(vec, VT_VARIANT);
707 
708   return oba;
709 }
710 // PTCH_DCG - **/
711 // This function assigns FPXScannedImageSizeBlock to the OLEProperty class through operator =
712 // The FPXScannedImageSizeBlock is stored as VT_VARIANT | VT_VECTOR type in the OLEProperty class
operator =(const FPXScannedImageSizeBlock & sisb)713 const FPXScannedImageSizeBlock& OLEProperty::operator=(const FPXScannedImageSizeBlock& sisb)
714 {
715   // Convert the FPXScannedImageSizeBlock to vector and assign to the OLEProperty
716   VECTOR* vec = FPXScannedImageSizeBlockToVector(sisb);
717   *this = vec;
718   DeleteVECTOR(vec, VT_VARIANT);
719 
720   return sisb;
721 }
722 
operator =(const FPXOpticalFilterArray & la)723 const FPXOpticalFilterArray& OLEProperty::operator=(const FPXOpticalFilterArray& la)
724 {
725   // Convert the FPXLongArray to vector and assign to the OLEProperty
726   VECTOR* vec = FPXOpticalFilterArrayToVector(la);
727   *this = vec;
728   DeleteVECTOR(vec, VT_I4);
729 
730   return la;
731 }
732 
733 //-------------------------------------------------------------------------------------------
734 //   Global Functions
735 //
736 //  The following functions convert VT data types defined in variant.h to  those defined in
737 //  FPXBaselineIO.h and vice versa
738 //-------------------------------------------------------------------------------------------
739 
740 
741 // This function converts FPXStr to LPSTR
FPXStrToLPSTR(const FPXStr & fpxstr)742 char* FPXStrToLPSTR(const FPXStr& fpxstr )
743 {
744   char* pstr;
745 
746   // Here we must allocate and copy the memory since we have to add a '\0'
747   // to the end of fpxstr.ptr
748   pstr = new char[fpxstr.length + 1];
749   if (pstr == NULL) {
750     return NULL;
751   }
752   memcpy(pstr, fpxstr.ptr, fpxstr.length);
753 
754   // Add a '\0' to the end of string
755   pstr[fpxstr.length] = '\0';
756 
757   return pstr;
758 }
759 
760 // This function converts FPXWideStr to LPWSTR
FPXWideStrToLPWSTR(const FPXWideStr & fpxwstr)761 LPWSTR FPXWideStrToLPWSTR(const FPXWideStr& fpxwstr )
762 {
763   LPWSTR pwstr;
764 
765   // Here we must allocate and copy the memory since we have to add a '\0'
766   // to the end of fpxwstr.ptr
767   pwstr = new WCHAR[fpxwstr.length + 1];
768   if (pwstr == NULL) {
769     return NULL;
770   }
771   memcpy(pwstr, fpxwstr.ptr, fpxwstr.length * sizeof(WCHAR));
772 
773   // Add a '\0' to the end of string
774   pwstr[fpxwstr.length] = 0;
775 
776   return pwstr;
777 }
778 
779 // PTCH_DCG - added method to copy an array of bytes in an FPXStr to a vector
780 //  of (unsigned) bytes. This is not NULL-terminated, but is padded to 32 bits
781 // This function converts FPXStr to VECTOR
FPXStrToVector(const FPXStr & sa)782 VECTOR* FPXStrToVector(const FPXStr& sa )
783 {
784   VECTOR *pvec;
785 
786   // Allocate a new vector
787   pvec = AllocVECTOR(VT_I1, sa.length);
788   if (pvec == NULL) {
789     return NULL;
790   }
791 
792   // Set the vector length and assign the pointer
793   memcpy(pvec->prgb, sa.ptr, pvec->cElements);
794 
795   return pvec;
796 }
797 
798 // This function converts FPXShortArray to VECTOR
FPXShortArrayToVector(const FPXShortArray & sa)799 VECTOR* FPXShortArrayToVector(const FPXShortArray& sa )
800 {
801   VECTOR *pvec;
802 
803   // Allocate a new vector
804   pvec = AllocVECTOR(VT_I2, sa.length);
805   if (pvec == NULL) {
806     return NULL;
807   }
808 
809   // Set the vector length and assign the pointer
810   memcpy(pvec->prgw, sa.ptr, pvec->cElements * sizeof(short));
811 
812   return pvec;
813 }
814 
815 // This function converts FPXLongArray to VECTOR
FPXLongArrayToVector(const FPXLongArray & la)816 VECTOR* FPXLongArrayToVector(const FPXLongArray& la )
817 {
818   VECTOR *pvec;
819 
820   // Allocate a new vector
821   pvec = AllocVECTOR(VT_I4, la.length);
822   if (pvec == NULL) {
823     return NULL;
824   }
825 
826   // Set the vector length and assign the pointer
827   memcpy(pvec->prgdw, la.ptr, pvec->cElements * 4);
828 
829   return pvec;
830 }
831 
832 // This function converts FPXRealArray to VECTOR
FPXRealArrayToVector(const FPXRealArray & fa)833 VECTOR* FPXRealArrayToVector(const FPXRealArray& fa )
834 {
835   VECTOR *pvec;
836 
837   // Allocate a new vector
838   pvec = AllocVECTOR(VT_R4, fa.length);
839   if (pvec == NULL) {
840     return NULL;
841   }
842 
843   // Set the vector length and assign the pointer
844   memcpy(pvec->prgflt, fa.ptr, pvec->cElements * sizeof(float));
845 
846   return pvec;
847 }
848 
849 // This function converts FPXClsIDArray to VECTOR
FPXClsIDArrayToVector(const FPXClsIDArray & ca)850 VECTOR* FPXClsIDArrayToVector(const FPXClsIDArray& ca )
851 {
852   VECTOR *pvec;
853 
854   // Allocate a new vector
855   pvec = AllocVECTOR(VT_CLSID, ca.length);
856   if (pvec == NULL) {
857     return NULL;
858   }
859 
860   // Set the vector length and assign the pointer
861   memcpy(pvec->pclsid, ca.ptr, pvec->cElements * sizeof(CLSID));
862 
863   return pvec;
864 }
865 
866 // This function converts FPXStrArray to VECTOR
FPXStrArrayToVector(const FPXStrArray & sa)867 VECTOR* FPXStrArrayToVector(const FPXStrArray& sa )
868 {
869   VECTOR *pvec;
870 
871   // Allocate a new vector
872   pvec = AllocVECTOR(VT_LPSTR, sa.length);
873   if (pvec == NULL) {
874     return NULL;
875   }
876 
877   // Here we must allocate and copy the memory since we have to add a '\0'
878   // to the end of string in FPXStrArray
879   for ( DWORD i= 0; i < pvec->cElements; i++ )
880   {
881     // Allocate the memory as for each string in the vector and copy the memory
882     pvec->prgpsz[i] = new char[sa.ptr[i].length + 1];
883     if (pvec->prgpsz[i] == NULL) {
884       return NULL;
885     }
886 
887     memcpy(pvec->prgpsz[i], sa.ptr[i].ptr, sa.ptr[i].length * sizeof(char));
888 
889     // Add the '\0' to the end of the string
890     pvec->prgpsz[i][sa.ptr[i].length] = '\0';
891   }
892 
893   return pvec;
894 }
895 
896 // This function converts FPXWideStrArray to VECTOR
FPXWideStrArrayToVector(const FPXWideStrArray & wa)897 VECTOR* FPXWideStrArrayToVector(const FPXWideStrArray& wa )
898 {
899   VECTOR *pvec;
900 
901   // Allocate a new vector
902   pvec = AllocVECTOR(VT_LPWSTR, wa.length);
903   if (pvec == NULL) {
904     return NULL;
905   }
906 
907   // Here we must allocate and copy the memory since we have to add a '\0'
908   // to the end of wide string in FPXWideStrArray
909   for ( DWORD i= 0; i < pvec->cElements; i++ )
910   {
911     // Allocate the memory as for each wide string in the vector and copy the memory
912     pvec->prgpwz[i] = new WCHAR[wa.ptr[i].length + 1];
913     if (pvec->prgpwz[i] == NULL) {
914       return NULL;
915     }
916     memcpy(pvec->prgpwz[i], wa.ptr[i].ptr, wa.ptr[i].length * sizeof(WCHAR));
917 
918     // Add the '\0' to the end of the wide string
919     pvec->prgpwz[i][wa.ptr[i].length] = 0;
920   }
921 
922   return pvec;
923 }
924 
925 // PTCH_DCG - removed array implementation and updated string type to meet spec
926 // This function converts FPXSpacialFrequencyResponseBlock to VECTOR
FPXSpacialFrequencyResponseBlockToVector(const FPXSpacialFrequencyResponseBlock & sfra)927 VECTOR* FPXSpacialFrequencyResponseBlockToVector(const FPXSpacialFrequencyResponseBlock& sfra )
928 {
929   VECTOR *pvec;
930 
931   // Allocate a new vector
932   // Each FPXSpacialFrequencyResponseBlock has four elements ( two unsigned long, one
933   // FPXWideStrArray, one FPXRealArray)
934   pvec = AllocVECTOR(VT_VARIANT, 4);
935   if (pvec == NULL) {
936     return NULL;
937   }
938 
939   V_VT(&pvec->pvar[0]) = VT_UI4;              // Save the variant type
940   V_I4(&pvec->pvar[0]) = sfra.number_of_columns;      // Save the number_of_columns
941 
942   V_VT(&pvec->pvar[1]) = VT_UI4;              // Save the variant type
943   V_I4(&pvec->pvar[1]) = sfra.number_of_rows;       // Save the number_of_rows
944 
945   V_VT(&pvec->pvar[2]) = VT_LPWSTR | VT_VECTOR;       // Save the variant type
946   V_BYREF(&pvec->pvar[2]) = FPXWideStrArrayToVector(sfra.column_headings);  // Save the column_headings
947 
948   V_VT(&pvec->pvar[3]) = VT_R4 | VT_VECTOR;           // Save the variant type
949   V_BYREF(&pvec->pvar[3]) = FPXRealArrayToVector(sfra.data);  // Save the data
950 
951   return pvec;
952 }
953 
954 // PTCH_DCG - removed array implementation and updated string type to meet spec
955 // This function converts FPXCFA_PatternBlock to VECTOR
FPXCFA_PatternBlockToVector(const FPXCFA_PatternBlock & cpba)956 VECTOR* FPXCFA_PatternBlockToVector(const FPXCFA_PatternBlock& cpba )
957 {
958   VECTOR *pvec;
959 
960   // Allocate a new vector
961   // Each FPXCFA_PatternBlock has three elements ( two unsigned short, one FPXStr)
962   pvec = AllocVECTOR(VT_VARIANT, 3);
963   if (pvec == NULL) {
964     return NULL;
965   }
966 
967   V_VT(&pvec->pvar[0]) = VT_UI2;              // Save the variant type
968   V_I2(&pvec->pvar[0]) = cpba.cfa_repeat_rows;      // Save the cfa_repeat_rows
969 
970   V_VT(&pvec->pvar[1]) = VT_UI2;              // Save the variant type
971   V_I2(&pvec->pvar[1]) = cpba.cfa_repeat_cols;      // Save the cfa_repeat_cols
972 
973   V_VT(&pvec->pvar[2]) = VT_UI1 | VT_VECTOR;        // Save the variant type
974 #ifdef _WINDOWS
975   V_UI1REF(&pvec->pvar[2]) = (unsigned char *)FPXStrToVector(cpba.cfa_array);   // Save the cfa_array
976 #else
977   V_UI1REF(&pvec->pvar[2]) = (char *)FPXStrToVector(cpba.cfa_array);
978 #endif
979 
980   return pvec;
981 }
982 
983 // PTCH_DCG - removed array implementation and updated string type to meet spec
984 // This function converts FPXOECF_BlockArray to VECTOR
FPXOECF_BlockToVector(const FPXOECF_Block & oeba)985 VECTOR* FPXOECF_BlockToVector(const FPXOECF_Block& oeba )
986 {
987   VECTOR *pvec;
988 
989   // Allocate a new vector
990   // Each FPXOECF_Block has four elements ( two unsigned short, one FPXWideStrArray, one
991   // FPXRealArray)
992   pvec = AllocVECTOR(VT_VARIANT, 4);
993   if (pvec == NULL) {
994     return NULL;
995   }
996 
997   V_VT(&pvec->pvar[0]) = VT_UI2;              // Save the variant type
998   V_I2(&pvec->pvar[0]) = oeba.number_of_columns;      // Save the number_of_columns
999 
1000   V_VT(&pvec->pvar[1]) = VT_UI2;              // Save the variant type
1001   V_I2(&pvec->pvar[1]) = oeba.number_of_rows;       // Save the number_of_rows
1002 
1003   V_VT(&pvec->pvar[2]) = VT_LPWSTR | VT_VECTOR;                   // Save the variant type
1004   V_BYREF(&pvec->pvar[2]) = FPXWideStrArrayToVector(oeba.column_headings);  // Save the column_headings
1005 
1006   V_VT(&pvec->pvar[3]) = VT_R4 | VT_VECTOR;               // Save the variant type
1007   V_BYREF(&pvec->pvar[3]) = FPXRealArrayToVector(oeba.data);  // Save the data
1008 
1009   return pvec;
1010 }
1011 
1012 // This function converts FPXScannedImageSizeBlock to VECTOR
FPXScannedImageSizeBlockToVector(const FPXScannedImageSizeBlock & sisb)1013 VECTOR* FPXScannedImageSizeBlockToVector(const FPXScannedImageSizeBlock& sisb )
1014 {
1015   VECTOR *pvec;
1016 
1017   // Allocate a new vector
1018   pvec = new VECTOR;
1019   if (pvec == NULL) {
1020     return NULL;
1021   }
1022 
1023   // Set the vector length and allocate the memory.
1024   // Each FPXScannedImageSizeBlock has three elements ( two float, one unsigned long)
1025   pvec->cElements = 3;
1026   pvec->pvar = new VARIANT[pvec->cElements];
1027   if (pvec->pvar == NULL) {
1028     return NULL;
1029   }
1030 
1031   // Save the three elements in the FPXScannedImageSizeBlock to a variant
1032   V_VT(&pvec->pvar[0]) = VT_R4;         // Save the variant type
1033   V_R4(&pvec->pvar[0]) = sisb.original_size_x;  // Save the original_size_x
1034 
1035   V_VT(&pvec->pvar[1]) = VT_R4;         // Save the variant type
1036   V_R4(&pvec->pvar[1]) = sisb.original_size_y;  // Save the original_size_y
1037 
1038   V_VT(&pvec->pvar[2]) = VT_UI4;          // Save the variant type
1039   V_I4(&pvec->pvar[2]) = sisb.original_size_unit;   // Save the original_size_unit
1040 
1041   return pvec;
1042 }
1043 
1044 // This function converts FPXLongArray to VECTOR
FPXOpticalFilterArrayToVector(const FPXOpticalFilterArray & la)1045 VECTOR* FPXOpticalFilterArrayToVector(const FPXOpticalFilterArray& la )
1046 {
1047   VECTOR *pvec;
1048 
1049   // Allocate a new vector
1050   pvec = AllocVECTOR(VT_I4, la.length);
1051   if (pvec == NULL) {
1052     return NULL;
1053   }
1054 
1055   // Set the vector length and assign the pointer
1056   memcpy(pvec->prgdw, la.ptr, pvec->cElements * sizeof(long));
1057 
1058   return pvec;
1059 }
1060 
1061 // This function converts LPSTR to FPXStr
LPSTRToFPXStr(char * pstr)1062 FPXStr& LPSTRToFPXStr( char* pstr )
1063 {
1064   FPXStr *fpxstr = new FPXStr;
1065 
1066   if (pstr) {
1067     // Allocate for FPXStr
1068     fpxstr->length  = strlen(pstr) +1;
1069     fpxstr->ptr   = new BYTE[fpxstr->length];
1070     if (fpxstr->ptr == NULL) {
1071       fpxstr->length = 0;
1072       return *fpxstr;
1073     }
1074 
1075     memcpy(fpxstr->ptr, pstr, fpxstr->length);
1076   } else {
1077     fpxstr->length  = 0;
1078     fpxstr->ptr   = NULL;
1079   }
1080 
1081   return *fpxstr;
1082 }
1083 
1084 // This function converts LPWSTR to FPXWideStr
LPWSTRToFPXWideStr(LPWSTR pwstr)1085 FPXWideStr& LPWSTRToFPXWideStr( LPWSTR pwstr )
1086 {
1087   FPXWideStr *fpxwstr = new FPXWideStr;
1088 
1089   if (pwstr) {
1090     // Allocate for FPXWideStr
1091     fpxwstr->length   = wcslen(pwstr) + 1;
1092     fpxwstr->ptr    = (LPWSTR)new WCHAR[fpxwstr->length];
1093     if (fpxwstr->ptr == NULL) {
1094       fpxwstr->length = 0;
1095       return *fpxwstr;
1096     }
1097 
1098     memcpy(fpxwstr->ptr, pwstr, fpxwstr->length * sizeof(WCHAR));
1099   } else {
1100     fpxwstr->length = 0;
1101     fpxwstr->ptr  = NULL;
1102   }
1103 
1104   return *fpxwstr;
1105 }
1106 
1107 // This function converts VECTOR to string of bytes with a long count
VectorToStr(VECTOR * vec)1108 FPXStr& VectorToStr( VECTOR* vec )
1109 {
1110   FPXStr *sa = new FPXStr;
1111 
1112   if (vec) {
1113     // Allocate for FPXShortArray
1114     sa->length  = vec->cElements;
1115     sa->ptr   = new unsigned char[sa->length];
1116     if (sa->ptr == NULL) {
1117       sa->length = 0;
1118       return *sa;
1119     }
1120     memcpy(sa->ptr, vec->prgw, sa->length * sizeof(char));
1121   } else {
1122     sa->length  = 0;
1123     sa->ptr   = NULL;
1124   }
1125 
1126   return *sa;
1127 }
1128 
1129 // This function converts VECTOR to FPXShortArray
VectorToFPXShortArray(VECTOR * vec)1130 FPXShortArray& VectorToFPXShortArray( VECTOR* vec )
1131 {
1132   FPXShortArray *sa = new FPXShortArray;
1133 
1134   if (vec) {
1135     // Allocate for FPXShortArray
1136     sa->length  = vec->cElements;
1137     sa->ptr   = new uint16_t[sa->length];
1138     if (sa->ptr == NULL) {
1139       sa->length = 0;
1140       return *sa;
1141     }
1142     memcpy(sa->ptr, vec->prgw, sa->length * sizeof(uint16_t));
1143   } else {
1144     sa->length  = 0;
1145     sa->ptr   = NULL;
1146   }
1147 
1148   return *sa;
1149 }
1150 
1151 // This function converts VECTOR to FPXLongArray
VectorToFPXLongArray(VECTOR * vec)1152 FPXLongArray& VectorToFPXLongArray( VECTOR* vec )
1153 {
1154   FPXLongArray *la = new FPXLongArray;
1155 
1156   if (vec) {
1157     // Allocate for FPXLongArray
1158     la->length  = vec->cElements;
1159     la->ptr   = new uint32_t[la->length];
1160     if (la->ptr == NULL) {
1161       la->length = 0;
1162       return *la;
1163     }
1164 
1165     memcpy(la->ptr, vec->prgdw, la->length * sizeof(uint32_t));
1166   } else {
1167     la->length  = 0;
1168     la->ptr   = NULL;
1169   }
1170 
1171   return *la;
1172 }
1173 
1174 // This function converts VECTOR to FPXRealArray
VectorToFPXRealArray(VECTOR * vec)1175 FPXRealArray& VectorToFPXRealArray( VECTOR* vec )
1176 {
1177   FPXRealArray *fa = new FPXRealArray;
1178 
1179   if (vec) {
1180     // Allocate for FPXRealArray
1181     fa->length  = vec->cElements;
1182     fa->ptr   = new float[fa->length];
1183     if (fa->ptr == NULL) {
1184       fa->length = 0;
1185       return *fa;
1186     }
1187 
1188     memcpy(fa->ptr, vec->prgflt, fa->length * sizeof(float));
1189   } else {
1190     fa->length  = 0;
1191     fa->ptr   = NULL;
1192   }
1193 
1194   return *fa;
1195 }
1196 
1197 // This function converts VECTOR to FPXClsIDArray
VectorToFPXClsIDArray(VECTOR * vec)1198 FPXClsIDArray& VectorToFPXClsIDArray( VECTOR* vec )
1199 {
1200   FPXClsIDArray *ca = new FPXClsIDArray;
1201 
1202   if (vec) {
1203     // Allocate for FPXClsIDArray
1204     ca->length  = vec->cElements;
1205     ca->ptr   = new CLSID[ca->length];
1206     if (ca->ptr == NULL) {
1207       ca->length = 0;
1208       return *ca;
1209     }
1210 
1211     memcpy(ca->ptr, vec->pclsid, ca->length * sizeof(CLSID));
1212   } else {
1213     ca->length  = 0;
1214     ca->ptr   = NULL;
1215   }
1216 
1217   return *ca;
1218 }
1219 
1220 // This function converts VECTOR to FPXStrArray
VectorToFPXStrArray(VECTOR * vec)1221 FPXStrArray& VectorToFPXStrArray( VECTOR* vec )
1222 {
1223   FPXStrArray *sa = new FPXStrArray;
1224 
1225   if (vec) {
1226     // Set the array length and pointer
1227     sa->length  = vec->cElements;
1228     sa->ptr   = new FPXStr[sa->length];
1229     if (sa->ptr == NULL) {
1230       sa->length = 0;
1231       return *sa;
1232     }
1233 
1234     for ( DWORD i= 0; i < sa->length; i++ ) {
1235       sa->ptr[i].length   = strlen(vec->prgpsz[i]);
1236       sa->ptr[i].ptr    = new BYTE[sa->ptr[i].length];
1237       if (sa->ptr[i].ptr == NULL) {
1238         sa->ptr[i].length = 0;
1239         return *sa;
1240       }
1241 
1242       memcpy(sa->ptr[i].ptr, vec->prgpsz[i], sa->ptr[i].length);
1243     }
1244 
1245   } else {
1246     sa->length  = 0;
1247     sa->ptr   = NULL;
1248   }
1249 
1250   return *sa;
1251 }
1252 
1253 // This function converts VECTOR to FPXWideStrArray
VectorToFPXWideStrArray(VECTOR * vec)1254 FPXWideStrArray& VectorToFPXWideStrArray( VECTOR* vec )
1255 {
1256   FPXWideStrArray *wa = new FPXWideStrArray;
1257 
1258   if (vec) {
1259     // Set the array length and allocate the memory
1260     wa->length  = vec->cElements;
1261     wa->ptr   = new FPXWideStr[wa->length];
1262     if (wa->ptr == NULL) {
1263       wa->length = 0;
1264       return *wa;
1265     }
1266 
1267     for ( DWORD i= 0; i < wa->length; i++ ) {
1268       wa->ptr[i].length   = wcslen(vec->prgpwz[i]) + 1;
1269       wa->ptr[i].ptr    = new WCHAR[wa->ptr[i].length];
1270       if (wa->ptr[i].ptr == NULL) {
1271         wa->ptr[i].length = 0;
1272         return *wa;
1273       }
1274       memcpy(wa->ptr[i].ptr, vec->prgpwz[i], wa->ptr[i].length * sizeof(WCHAR));
1275     }
1276 
1277   } else {
1278     wa->length  = 0;
1279     wa->ptr   = NULL;
1280   }
1281 
1282   return *wa;
1283 }
1284 
1285 // PTCH_DCG - removed array implementation and updated string type to meet spec
1286 // This function converts VECTOR to FPXSpacialFrequencyResponseBlockArray
VectorToFPXSpacialFrequencyResponseBlock(VECTOR * pvec)1287 FPXSpacialFrequencyResponseBlock& VectorToFPXSpacialFrequencyResponseBlock( VECTOR* pvec )
1288 {
1289   FPXSpacialFrequencyResponseBlock *sfra = new FPXSpacialFrequencyResponseBlock;
1290 
1291   if (pvec) {
1292     // Each FPXSpacialFrequencyResponseBlock has four elements ( two unsigned long, one
1293     // FPXStrArray, one FPXRealArray)
1294     sfra->number_of_columns = V_I4(&pvec->pvar[0]);   // Save the number_of_columns
1295     sfra->number_of_rows  = V_I4(&pvec->pvar[1]);   // Save the number_of_rows
1296     sfra->column_headings   = VectorToFPXWideStrArray((VECTOR *)V_BYREF(&pvec->pvar[2])); // Save the column_headings
1297     sfra->data        = VectorToFPXRealArray((VECTOR *)V_BYREF(&pvec->pvar[3]));  // Save the data
1298   }
1299 
1300   return *sfra;
1301 }
1302 
1303 // PTCH_DCG - removed array implementation and updated string type to meet spec
1304 // This function converts VECTOR to FPXCFA_PatternBlockArray
VectorToFPXCFA_PatternBlock(VECTOR * pvec)1305 FPXCFA_PatternBlock& VectorToFPXCFA_PatternBlock( VECTOR* pvec )
1306 {
1307   FPXCFA_PatternBlock *cpba = new FPXCFA_PatternBlock;
1308 
1309   if (pvec) {
1310     cpba->cfa_repeat_rows   = V_I2(&pvec->pvar[0]);   // Save the cfa_repeat_rows
1311     cpba->cfa_repeat_cols = V_I2(&pvec->pvar[1]);   // Save the cfa_repeat_cols
1312 #ifdef _WINDOWS
1313     cpba->cfa_array = VectorToStr((VECTOR *)V_BYREF(&pvec->pvar[2])); // Save the cfa_array
1314 //    cpba->cfa_array = LPSTRToFPXStr((char *)V_UI1REF(&pvec->pvar[2]));  // Save the cfa_array
1315 #else
1316     cpba->cfa_array = VectorToStr((VECTOR *)V_BYREF(&pvec->pvar[2])); // Save the cfa_array
1317 #endif
1318   }
1319   return *cpba;
1320 }
1321 
1322 // PTCH_DCG - removed array implementation and updated string type to meet spec
1323 // This function converts VECTOR to FPXOECF_BlockArray
VectorToFPXOECF_Block(VECTOR * pvec)1324 FPXOECF_Block& VectorToFPXOECF_Block( VECTOR* pvec )
1325 {
1326   FPXOECF_Block *oba = new FPXOECF_Block;
1327 
1328   oba->number_of_columns  = V_I2(&pvec->pvar[0]);   // Save the number_of_columns
1329   oba->number_of_rows   = V_I2(&pvec->pvar[1]);   // Save the number_of_rows
1330   oba->column_headings  = VectorToFPXWideStrArray((VECTOR *)V_BYREF(&pvec->pvar[2])); // Save the column_headings
1331   oba->data       = VectorToFPXRealArray((VECTOR *)V_BYREF(&pvec->pvar[3]));  // Save the data
1332 
1333   return *oba;
1334 }
1335 
1336 // This function converts VECTOR to FPXScannedImageSizeBlock
VectorToFPXScannedImageSizeBlock(VECTOR * pvec)1337 FPXScannedImageSizeBlock& VectorToFPXScannedImageSizeBlock( VECTOR* pvec )
1338 {
1339   FPXScannedImageSizeBlock *sisb = new FPXScannedImageSizeBlock;
1340 
1341   if (pvec) {
1342     // Save three variants to a FPXScannedImageSizeBlock
1343     sisb->original_size_x     = V_R4(&pvec->pvar[0]);   // Save the original_size_x
1344     sisb->original_size_y   = V_R4(&pvec->pvar[1]);   // Save the original_size_y
1345     sisb->original_size_unit  = (FPXResolutionUnit)V_I4(&pvec->pvar[2]);    // Save the original_size_unit
1346   } else {
1347     sisb->original_size_x     = (float) 0.0;
1348     sisb->original_size_y   = (float) 0.0;
1349     sisb->original_size_unit  = (FPXResolutionUnit)0;
1350   }
1351 
1352   return *sisb;
1353 }
1354 
1355 // This function converts VECTOR to FPXOpticalFilterArray
VectorToFPXOpticalFilterArray(VECTOR * vec)1356 FPXOpticalFilterArray& VectorToFPXOpticalFilterArray( VECTOR* vec )
1357 {
1358   FPXOpticalFilterArray *la = new FPXOpticalFilterArray;
1359 
1360   if(vec)
1361   {
1362     la->length  = vec->cElements;
1363     la->ptr   = new FPXSpecialEffectsOpticalFilter[la->length];
1364     if (la->ptr == NULL) {
1365       la->length = 0;
1366       return *la;
1367     }
1368     memcpy(la->ptr, vec->prgdw, la->length * sizeof(long));
1369   } else {
1370     la->length  = 0;
1371     la->ptr   = NULL;
1372   }
1373   return *la;
1374 }
1375