10 WPLString
= 0x57504c01,
12 WPLArray
= 0x57504c03,
13 WPLDictionary
= 0x57504c04
17 typedef struct W_PropList
{
32 static WMCompareDataProc
*strCmp
= (WMCompareDataProc
*) strcmp
;
37 WMSetPropListStringComparer(WMCompareDataProc
*comparer
)
40 strCmp
= (WMCompareDataProc
*) strcmp
;
47 hashPropList(WMPropList
*plist
)
54 switch (plist
->type
) {
56 key
= plist
->d
.string
;
59 ctr
= (ctr
+ 1) % sizeof (char *);
64 key
= WMDataBytes(plist
->d
.data
);
65 for (i
=0; i
<WMGetDataLength(plist
->d
.data
); i
++) {
67 ctr
= (ctr
+ 1) % sizeof (char *);
72 wwarning(_("Only string or data is supported for a proplist dictionary key"));
80 WMCreatePropListString(char *str
)
84 wassertrv(str
!=NULL
, NULL
);
86 plist
= (WMPropList
*)wmalloc(sizeof(WMPropList
));
88 plist
->type
= WPLString
;
89 plist
->d
.string
= wstrdup(str
);
90 plist
->retainCount
= 1;
97 WMCreatePropListDataWithBytes(unsigned char *bytes
, unsigned int length
)
101 wassertrv(length
!=0 && bytes
!=NULL
, NULL
);
103 plist
= (WMPropList
*)wmalloc(sizeof(WMPropList
));
105 plist
->type
= WPLData
;
106 plist
->d
.data
= WMCreateDataWithBytes(bytes
, length
);
107 plist
->retainCount
= 1;
114 WMCreatePropListDataWithBytesNoCopy(unsigned char *bytes
, unsigned int length
,
115 WMFreeDataProc
*destructor
)
119 wassertrv(length
!=0 && bytes
!=NULL
, NULL
);
121 plist
= (WMPropList
*)wmalloc(sizeof(WMPropList
));
123 plist
->type
= WPLData
;
124 plist
->d
.data
= WMCreateDataWithBytesNoCopy(bytes
, length
, destructor
);
125 plist
->retainCount
= 1;
132 WMCreatePropListDataWithData(WMData
*data
)
136 wassertrv(data
!=NULL
, NULL
);
138 plist
= (WMPropList
*)wmalloc(sizeof(WMPropList
));
140 plist
->type
= WPLData
;
141 plist
->d
.data
= WMRetainData(data
);
142 plist
->retainCount
= 1;
149 WMIsPropListEqualWith(WMPropList
*plist
, WMPropList
*other
)
151 WMPropList
*key1
, *key2
, *item1
, *item2
;
152 WMHashEnumerator enumerator
;
155 if (plist
->type
!= other
->type
)
158 switch(plist
->type
) {
160 return ((*strCmp
)(plist
->d
.string
, other
->d
.string
) == 0);
162 return WMIsDataEqualToData(plist
->d
.data
, other
->d
.data
);
164 n
= WMGetArrayItemCount(plist
->d
.array
);
165 if (n
!= WMGetArrayItemCount(other
->d
.array
))
167 for (i
=0; i
<n
; i
++) {
168 item1
= WMGetFromArray(plist
->d
.array
, i
);
169 item2
= WMGetFromArray(other
->d
.array
, i
);
170 if (!WMIsPropListEqualWith(item1
, item2
))
175 if (WMCountHashTable(plist
->d
.dict
) != WMCountHashTable(other
->d
.dict
))
177 enumerator
= WMEnumerateHashTable(plist
->d
.dict
);
178 while (WMNextHashEnumeratorItemAndKey(&enumerator
, (void**)&item1
,
180 item2
= WMHashGet(other
->d
.dict
, key1
);
181 if (!item2
|| !item1
|| !WMIsPropListEqualWith(item1
, item2
))
186 wwarning(_("Used proplist functions on non-WMPropLists objects"));
187 wassertrv(False
, False
);
195 typedef unsigned (*hashFunc
)(const void*);
196 typedef Bool (*isEqualFunc
)(const void*, const void*);
197 typedef void* (*retainFunc
)(const void*);
198 typedef void (*releaseFunc
)(const void*);
201 const WMHashTableCallbacks WMPropListHashCallbacks
= {
202 (hashFunc
)hashPropList
,
203 (isEqualFunc
)WMIsPropListEqualWith
,