[futurebasic] cftimezone cfdictionary

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2004 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Thu, 30 Sep 2004 09:51:00 -0400
Responding to Waverly's question about 
CFTimeZoneCopyAbbreviationDictionary, Robert 
Purves wrote:

>The demo below answers your question as it was asked, and gives an good
>idea of the contents of the dictionary...


The Console dump was just too ugly for me. So 
here's my quick and dirty modification at peeking 
into a dictionary based on your code.



Using Robert Purves' drop-into-the-console
view of a Core Foundation dictionary, this
modification returns the dictionary contents
as Pascal strings.


// from CFTimeZone.h
#define CFTimeZoneRef as Ptr // to opaque stuff
toolbox fn CFTimeZoneCopyAbbreviationDictionary() = CFDictionaryRef

// from CFDictionary.h
toolbox fn CFDictionaryGetCount( CFDictionaryRef theDict ) = CFIndex
toolbox CFDictionaryGetKeysAndValues( CFDictionaryRef theDict, Ptr
keys, Ptr values )

// from CFString.h
toolbox CFShow( Ptr )

clear local mode
local fn CFStringRefToPascal$( ref as CFStringRef )
dim as Str255 outStr

long if ( ref )
long if fn CFStringGetPascalString( ref, @outStr, ¬
                            256, _kCFStringEncodingASCII )
CFRelease( ref )
end if
outStr = "error"
end if

end fn = outStr

dim as CFDictionaryRef  dict
dict  = fn CFTimeZoneCopyAbbreviationDictionary()

Typically, what you do with a dictionary is to look things up.
Here, though, we convert the CFStringRefs created by
(key/value pairs) into Pascal for printing in FB

window 1

dim as CFIndex          count
dim as long             j
count = fn CFDictionaryGetCount( dict )

xref keys(_maxInt)   as CFStringRef
xref values(_maxInt) as CFStringRef

dim as Str255           keyStr, valueStr

keys   = fn NewPtr( count*sizeof( CFStringRef ) )
values = fn NewPtr( count*sizeof( CFStringRef ) )
CFDictionaryGetKeysAndValues( dict, keys, values )
CFRelease( dict ) // release what we copied
j = 0
def tab 6
while ( j < count )
keyStr   = fn CFStringRefToPascal$(   keys(j) )
valueStr = fn CFStringRefToPascal$( values(j) )
print j; ". ", keyStr, valueStr

include "Subs Quick Event Loop.Incl"