stlab.adobe.com Adobe Systems Incorporated

macintosh_cast.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /****************************************************************************************************/
00008 
00009 #ifndef ADOBE_MACINTOSH_CAST_HPP
00010 #define ADOBE_MACINTOSH_CAST_HPP
00011 
00012 /****************************************************************************************************/
00013 
00014 #include <adobe/macintosh_carbon_safe.hpp>
00015 
00016 /****************************************************************************************************/
00017 
00018 namespace adobe {
00019 
00020 /****************************************************************************************************/
00021 
00022 namespace implementation {
00023 
00024 /****************************************************************************************************/
00025 
00026 typedef ::CFTypeID (*get_cftypeid_proc_t)();
00027 
00028 template <typename ToType> get_cftypeid_proc_t cftypeid_proc_type();
00029 
00030 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFAllocatorRef >()          { return ::CFAllocatorGetTypeID; }
00031 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFArrayRef >()              { return ::CFArrayGetTypeID; }
00032 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFAttributedStringRef >()   { return ::CFAttributedStringGetTypeID; }
00033 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFBagRef >()                { return ::CFBagGetTypeID; }
00034 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFBinaryHeapRef >()         { return ::CFBinaryHeapGetTypeID; }
00035 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFBitVectorRef >()          { return ::CFBitVectorGetTypeID; }
00036 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFBooleanRef >()            { return ::CFBooleanGetTypeID; }
00037 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFBundleRef >()             { return ::CFBundleGetTypeID; }
00038 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFCalendarRef >()           { return ::CFCalendarGetTypeID; }
00039 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFCharacterSetRef >()       { return ::CFCharacterSetGetTypeID; }
00040 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFDataRef >()               { return ::CFDataGetTypeID; }
00041 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFDateFormatterRef >()      { return ::CFDateFormatterGetTypeID; }
00042 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFDateRef >()               { return ::CFDateGetTypeID; }
00043 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFDictionaryRef >()         { return ::CFDictionaryGetTypeID; }
00044 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFLocaleRef >()             { return ::CFLocaleGetTypeID; }
00045 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFMachPortRef >()           { return ::CFMachPortGetTypeID; }
00046 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFMessagePortRef >()        { return ::CFMessagePortGetTypeID; }
00047 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFNotificationCenterRef >() { return ::CFNotificationCenterGetTypeID; }
00048 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFNullRef >()               { return ::CFNullGetTypeID; }
00049 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFNumberFormatterRef >()    { return ::CFNumberFormatterGetTypeID; }
00050 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFNumberRef >()             { return ::CFNumberGetTypeID; }
00051 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFPlugInInstanceRef >()     { return ::CFPlugInInstanceGetTypeID; }
00052 //template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFPlugInRef >()             { return ::CFPlugInGetTypeID; }
00053 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFReadStreamRef >()         { return ::CFReadStreamGetTypeID; }
00054 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFRunLoopObserverRef >()    { return ::CFRunLoopObserverGetTypeID; }
00055 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFRunLoopRef >()            { return ::CFRunLoopGetTypeID; }
00056 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFRunLoopSourceRef >()      { return ::CFRunLoopSourceGetTypeID; }
00057 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFRunLoopTimerRef >()       { return ::CFRunLoopTimerGetTypeID; }
00058 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFSetRef >()                { return ::CFSetGetTypeID; }
00059 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFSocketRef >()             { return ::CFSocketGetTypeID; }
00060 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFStringRef >()             { return ::CFStringGetTypeID; }
00061 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFTimeZoneRef >()           { return ::CFTimeZoneGetTypeID; }
00062 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFTreeRef >()               { return ::CFTreeGetTypeID; }
00063 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFURLRef >()                { return ::CFURLGetTypeID; }
00064 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFUserNotificationRef >()   { return ::CFUserNotificationGetTypeID; }
00065 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFUUIDRef >()               { return ::CFUUIDGetTypeID; }
00066 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFWriteStreamRef >()        { return ::CFWriteStreamGetTypeID; }
00067 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFXMLNodeRef >()            { return ::CFXMLNodeGetTypeID; }
00068 template <> inline get_cftypeid_proc_t cftypeid_proc_type< ::CFXMLParserRef >()          { return ::CFXMLParserGetTypeID; }
00069 
00070 /****************************************************************************************************/
00071 
00072 } // namespace implementation
00073 
00074 /****************************************************************************************************/
00075 
00083 template <typename R>
00084 inline R cf_cast(::CFTypeRef x)
00085 {
00086     if (x == 0)
00087         return reinterpret_cast<R>(0);
00088 
00089     ::CFTypeID src_type_id(::CFGetTypeID(x));
00090     ::CFTypeID dest_type_id(implementation::cftypeid_proc_type<R>()());
00091 
00092     return reinterpret_cast<R>(src_type_id == dest_type_id ? x : 0);
00093 }
00094 
00095 /****************************************************************************************************/
00096 
00097 } // namespace adobe
00098 
00099 /****************************************************************************************************/
00100 
00101 // ADOBE_MACINTOSH_CAST_HPP
00102 #endif
00103 
00104 /****************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google