summaryrefslogtreecommitdiff
path: root/source/Host/macosx/cfcpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Host/macosx/cfcpp')
-rw-r--r--source/Host/macosx/cfcpp/CFCBundle.cpp99
-rw-r--r--source/Host/macosx/cfcpp/CFCBundle.h50
-rw-r--r--source/Host/macosx/cfcpp/CFCData.cpp82
-rw-r--r--source/Host/macosx/cfcpp/CFCData.h35
-rw-r--r--source/Host/macosx/cfcpp/CFCMutableArray.cpp166
-rw-r--r--source/Host/macosx/cfcpp/CFCMutableArray.h39
-rw-r--r--source/Host/macosx/cfcpp/CFCMutableDictionary.cpp529
-rw-r--r--source/Host/macosx/cfcpp/CFCMutableDictionary.h79
-rw-r--r--source/Host/macosx/cfcpp/CFCMutableSet.cpp114
-rw-r--r--source/Host/macosx/cfcpp/CFCMutableSet.h53
-rw-r--r--source/Host/macosx/cfcpp/CFCReleaser.h158
-rw-r--r--source/Host/macosx/cfcpp/CFCString.cpp195
-rw-r--r--source/Host/macosx/cfcpp/CFCString.h41
-rw-r--r--source/Host/macosx/cfcpp/CoreFoundationCPP.h30
14 files changed, 1670 insertions, 0 deletions
diff --git a/source/Host/macosx/cfcpp/CFCBundle.cpp b/source/Host/macosx/cfcpp/CFCBundle.cpp
new file mode 100644
index 0000000000000..71b074993661d
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCBundle.cpp
@@ -0,0 +1,99 @@
+//===-- CFCBundle.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CFCBundle.h"
+#include "CFCString.h"
+
+//----------------------------------------------------------------------
+// CFCBundle constructor
+//----------------------------------------------------------------------
+CFCBundle::CFCBundle(const char *path) :
+ CFCReleaser<CFBundleRef>()
+{
+ if (path && path[0])
+ SetPath(path);
+}
+
+CFCBundle::CFCBundle(CFURLRef url) :
+ CFCReleaser<CFBundleRef>(url ? CFBundleCreate(NULL, url) : NULL)
+{
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+CFCBundle::~CFCBundle()
+{
+}
+
+//----------------------------------------------------------------------
+// Set the path for a bundle by supplying a
+//----------------------------------------------------------------------
+bool
+CFCBundle::SetPath (const char *path)
+{
+ CFAllocatorRef alloc = kCFAllocatorDefault;
+ // Release our old bundle and URL
+ reset();
+
+ // Make a CFStringRef from the supplied path
+ CFCString cf_path;
+ cf_path.SetFileSystemRepresentation(path);
+ if (cf_path.get())
+ {
+ // Make our Bundle URL
+ CFCReleaser<CFURLRef> bundle_url (::CFURLCreateWithFileSystemPath (alloc, cf_path.get(), kCFURLPOSIXPathStyle, true));
+ if (bundle_url.get())
+ reset (::CFBundleCreate (alloc, bundle_url.get()));
+ }
+ return get() != NULL;
+}
+
+bool
+CFCBundle::GetPath (char *dst, size_t dst_len)
+{
+ CFBundleRef bundle = get();
+ if (bundle)
+ {
+ CFCReleaser<CFURLRef> bundle_url (CFBundleCopyBundleURL (bundle));
+ if (bundle_url.get())
+ {
+ Boolean resolveAgainstBase = 0;
+ return ::CFURLGetFileSystemRepresentation (bundle_url.get(), resolveAgainstBase, (UInt8 *)dst, dst_len) != 0;
+ }
+ }
+ return false;
+}
+
+CFStringRef
+CFCBundle::GetIdentifier () const
+{
+ CFBundleRef bundle = get();
+ if (bundle != NULL)
+ return ::CFBundleGetIdentifier (bundle);
+ return NULL;
+}
+
+CFTypeRef
+CFCBundle::GetValueForInfoDictionaryKey(CFStringRef key) const
+{
+ CFBundleRef bundle = get();
+ if (bundle != NULL)
+ return ::CFBundleGetValueForInfoDictionaryKey(bundle, key);
+ return NULL;
+}
+
+CFURLRef
+CFCBundle::CopyExecutableURL () const
+{
+ CFBundleRef bundle = get();
+ if (bundle != NULL)
+ return CFBundleCopyExecutableURL(bundle);
+ return NULL;
+}
diff --git a/source/Host/macosx/cfcpp/CFCBundle.h b/source/Host/macosx/cfcpp/CFCBundle.h
new file mode 100644
index 0000000000000..1cd1b681af840
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCBundle.h
@@ -0,0 +1,50 @@
+//===-- CFCBundle.h ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CoreFoundationCPP_CFBundle_h_
+#define CoreFoundationCPP_CFBundle_h_
+
+#include "CFCReleaser.h"
+
+class CFCBundle : public CFCReleaser<CFBundleRef>
+{
+public:
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CFCBundle (const char *path = NULL);
+ CFCBundle (CFURLRef url);
+
+ virtual
+ ~CFCBundle();
+
+ CFURLRef
+ CopyExecutableURL () const;
+
+ CFStringRef
+ GetIdentifier () const;
+
+ CFTypeRef
+ GetValueForInfoDictionaryKey(CFStringRef key) const;
+
+ bool
+ GetPath (char *dst, size_t dst_len);
+
+ bool
+ SetPath (const char *path);
+
+private:
+ // Disallow copy and assignment constructors
+ CFCBundle(const CFCBundle&);
+
+ const CFCBundle&
+ operator=(const CFCBundle&);
+};
+
+#endif // #ifndef CoreFoundationCPP_CFBundle_h_
diff --git a/source/Host/macosx/cfcpp/CFCData.cpp b/source/Host/macosx/cfcpp/CFCData.cpp
new file mode 100644
index 0000000000000..4f49368ad8adf
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCData.cpp
@@ -0,0 +1,82 @@
+//===-- CFCData.cpp ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CFCData.h"
+
+//----------------------------------------------------------------------
+// CFCData constructor
+//----------------------------------------------------------------------
+CFCData::CFCData(CFDataRef data) :
+ CFCReleaser<CFDataRef>(data)
+{
+
+}
+
+//----------------------------------------------------------------------
+// CFCData copy constructor
+//----------------------------------------------------------------------
+CFCData::CFCData(const CFCData& rhs) :
+ CFCReleaser<CFDataRef>(rhs)
+{
+
+}
+
+//----------------------------------------------------------------------
+// CFCData copy constructor
+//----------------------------------------------------------------------
+CFCData&
+CFCData::operator=(const CFCData& rhs)
+
+{
+ if (this != &rhs)
+ *this = rhs;
+ return *this;
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+CFCData::~CFCData()
+{
+}
+
+
+CFIndex
+CFCData::GetLength() const
+{
+ CFDataRef data = get();
+ if (data)
+ return CFDataGetLength (data);
+ return 0;
+}
+
+
+const uint8_t*
+CFCData::GetBytePtr() const
+{
+ CFDataRef data = get();
+ if (data)
+ return CFDataGetBytePtr (data);
+ return NULL;
+}
+
+CFDataRef
+CFCData::Serialize(CFPropertyListRef plist, CFPropertyListFormat format)
+{
+ CFAllocatorRef alloc = kCFAllocatorDefault;
+ reset();
+ CFCReleaser<CFWriteStreamRef> stream (::CFWriteStreamCreateWithAllocatedBuffers (alloc, alloc));
+ ::CFWriteStreamOpen (stream.get());
+ CFIndex len = ::CFPropertyListWriteToStream (plist, stream.get(), format, NULL);
+ if (len > 0)
+ reset((CFDataRef)::CFWriteStreamCopyProperty (stream.get(), kCFStreamPropertyDataWritten));
+ ::CFWriteStreamClose (stream.get());
+ return get();
+}
+
diff --git a/source/Host/macosx/cfcpp/CFCData.h b/source/Host/macosx/cfcpp/CFCData.h
new file mode 100644
index 0000000000000..6a718f54c0555
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCData.h
@@ -0,0 +1,35 @@
+//===-- CFCData.h -----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CoreFoundationCPP_CFData_h_
+#define CoreFoundationCPP_CFData_h_
+
+#include "CFCReleaser.h"
+
+class CFCData : public CFCReleaser<CFDataRef>
+{
+public:
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CFCData(CFDataRef data = NULL);
+ CFCData(const CFCData& rhs);
+ CFCData& operator=(const CFCData& rhs);
+ virtual ~CFCData();
+
+ CFDataRef Serialize(CFPropertyListRef plist, CFPropertyListFormat format);
+ const uint8_t* GetBytePtr () const;
+ CFIndex GetLength () const;
+protected:
+ //------------------------------------------------------------------
+ // Classes that inherit from CFCData can see and modify these
+ //------------------------------------------------------------------
+};
+
+#endif // #ifndef CoreFoundationCPP_CFData_h_
diff --git a/source/Host/macosx/cfcpp/CFCMutableArray.cpp b/source/Host/macosx/cfcpp/CFCMutableArray.cpp
new file mode 100644
index 0000000000000..c3c0a11193a7c
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCMutableArray.cpp
@@ -0,0 +1,166 @@
+//===-- CFCMutableArray.cpp -------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CFCMutableArray.h"
+#include "CFCString.h"
+
+//----------------------------------------------------------------------
+// CFCString constructor
+//----------------------------------------------------------------------
+CFCMutableArray::CFCMutableArray(CFMutableArrayRef s) :
+ CFCReleaser<CFMutableArrayRef> (s)
+{
+}
+
+//----------------------------------------------------------------------
+// CFCMutableArray copy constructor
+//----------------------------------------------------------------------
+CFCMutableArray::CFCMutableArray(const CFCMutableArray& rhs) :
+ CFCReleaser<CFMutableArrayRef> (rhs) // NOTE: this won't make a copy of the array, just add a new reference to it
+{
+}
+
+//----------------------------------------------------------------------
+// CFCMutableArray copy constructor
+//----------------------------------------------------------------------
+CFCMutableArray&
+CFCMutableArray::operator=(const CFCMutableArray& rhs)
+{
+ if (this != &rhs)
+ *this = rhs; // NOTE: this operator won't make a copy of the array, just add a new reference to it
+ return *this;
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+CFCMutableArray::~CFCMutableArray()
+{
+}
+
+
+CFIndex
+CFCMutableArray::GetCount() const
+{
+ CFMutableArrayRef array = get();
+ if (array)
+ return ::CFArrayGetCount (array);
+ return 0;
+}
+
+CFIndex
+CFCMutableArray::GetCountOfValue(CFRange range, const void *value) const
+{
+ CFMutableArrayRef array = get();
+ if (array)
+ return ::CFArrayGetCountOfValue (array, range, value);
+ return 0;
+}
+
+CFIndex
+CFCMutableArray::GetCountOfValue(const void *value) const
+{
+ CFMutableArrayRef array = get();
+ if (array)
+ return ::CFArrayGetCountOfValue (array, CFRangeMake(0, GetCount()), value);
+ return 0;
+}
+
+const void *
+CFCMutableArray::GetValueAtIndex(CFIndex idx) const
+{
+ CFMutableArrayRef array = get();
+ if (array)
+ {
+ const CFIndex num_array_items = ::CFArrayGetCount (array);
+ if (0 <= idx && idx < num_array_items)
+ {
+ return ::CFArrayGetValueAtIndex (array, idx);
+ }
+ }
+ return NULL;
+}
+
+bool
+CFCMutableArray::SetValueAtIndex(CFIndex idx, const void *value)
+{
+ CFMutableArrayRef array = get();
+ if (array != NULL)
+ {
+ const CFIndex num_array_items = ::CFArrayGetCount (array);
+ if (0 <= idx && idx < num_array_items)
+ {
+ ::CFArraySetValueAtIndex (array, idx, value);
+ return true;
+ }
+ }
+ return false;
+}
+
+
+bool
+CFCMutableArray::AppendValue(const void *value, bool can_create)
+{
+ CFMutableArrayRef array = get();
+ if (array == NULL)
+ {
+ if (can_create == false)
+ return false;
+ array = ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
+ reset ( array );
+ }
+ if (array != NULL)
+ {
+ ::CFArrayAppendValue(array, value);
+ return true;
+ }
+ return false;
+}
+
+
+bool
+CFCMutableArray::AppendCStringAsCFString (const char *s, CFStringEncoding encoding, bool can_create)
+{
+ CFMutableArrayRef array = get();
+ if (array == NULL)
+ {
+ if (can_create == false)
+ return false;
+ array = ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
+ reset ( array );
+ }
+ if (array != NULL)
+ {
+ CFCString cf_str (s, encoding);
+ ::CFArrayAppendValue (array, cf_str.get());
+ return true;
+ }
+ return false;
+}
+
+bool
+CFCMutableArray::AppendFileSystemRepresentationAsCFString (const char *s, bool can_create)
+{
+ CFMutableArrayRef array = get();
+ if (array == NULL)
+ {
+ if (can_create == false)
+ return false;
+ array = ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
+ reset ( array );
+ }
+ if (array != NULL)
+ {
+ CFCString cf_path;
+ cf_path.SetFileSystemRepresentation(s);
+ ::CFArrayAppendValue (array, cf_path.get());
+ return true;
+ }
+ return false;
+}
diff --git a/source/Host/macosx/cfcpp/CFCMutableArray.h b/source/Host/macosx/cfcpp/CFCMutableArray.h
new file mode 100644
index 0000000000000..f78cd92ffab16
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCMutableArray.h
@@ -0,0 +1,39 @@
+//===-- CFCMutableArray.h ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CoreFoundationCPP_CFMutableArray_h_
+#define CoreFoundationCPP_CFMutableArray_h_
+
+#include "CFCReleaser.h"
+
+class CFCMutableArray : public CFCReleaser<CFMutableArrayRef>
+{
+public:
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CFCMutableArray(CFMutableArrayRef array = NULL);
+ CFCMutableArray(const CFCMutableArray& rhs); // This will copy the array contents into a new array
+ CFCMutableArray& operator=(const CFCMutableArray& rhs); // This will re-use the same array and just bump the ref count
+ virtual ~CFCMutableArray();
+
+ CFIndex GetCount() const;
+ CFIndex GetCountOfValue(const void *value) const;
+ CFIndex GetCountOfValue(CFRange range, const void *value) const;
+ const void * GetValueAtIndex(CFIndex idx) const;
+ bool SetValueAtIndex(CFIndex idx, const void *value);
+ bool AppendValue(const void *value, bool can_create = true); // Appends value and optionally creates a CFCMutableArray if this class doesn't contain one
+ bool AppendCStringAsCFString (const char *cstr,
+ CFStringEncoding encoding = kCFStringEncodingUTF8,
+ bool can_create = true);
+ bool AppendFileSystemRepresentationAsCFString (const char *s,
+ bool can_create = true);
+};
+
+#endif // #ifndef CoreFoundationCPP_CFMutableArray_h_
diff --git a/source/Host/macosx/cfcpp/CFCMutableDictionary.cpp b/source/Host/macosx/cfcpp/CFCMutableDictionary.cpp
new file mode 100644
index 0000000000000..bce023bfd616e
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCMutableDictionary.cpp
@@ -0,0 +1,529 @@
+//===-- CFCMutableDictionary.cpp --------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CFCMutableDictionary.h"
+#include "CFCString.h"
+//----------------------------------------------------------------------
+// CFCString constructor
+//----------------------------------------------------------------------
+CFCMutableDictionary::CFCMutableDictionary(CFMutableDictionaryRef s) :
+ CFCReleaser<CFMutableDictionaryRef> (s)
+{
+}
+
+//----------------------------------------------------------------------
+// CFCMutableDictionary copy constructor
+//----------------------------------------------------------------------
+CFCMutableDictionary::CFCMutableDictionary(const CFCMutableDictionary& rhs) :
+ CFCReleaser<CFMutableDictionaryRef> (rhs)
+{
+}
+
+//----------------------------------------------------------------------
+// CFCMutableDictionary copy constructor
+//----------------------------------------------------------------------
+const CFCMutableDictionary&
+CFCMutableDictionary::operator=(const CFCMutableDictionary& rhs)
+{
+ if (this != &rhs)
+ *this = rhs;
+ return *this;
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+CFCMutableDictionary::~CFCMutableDictionary()
+{
+}
+
+
+CFIndex
+CFCMutableDictionary::GetCount() const
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ return ::CFDictionaryGetCount (dict);
+ return 0;
+}
+
+CFIndex
+CFCMutableDictionary::GetCountOfKey(const void *key) const
+
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ return ::CFDictionaryGetCountOfKey (dict, key);
+ return 0;
+}
+
+CFIndex
+CFCMutableDictionary::GetCountOfValue(const void *value) const
+
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ return ::CFDictionaryGetCountOfValue (dict, value);
+ return 0;
+}
+
+void
+CFCMutableDictionary::GetKeysAndValues(const void **keys, const void **values) const
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ ::CFDictionaryGetKeysAndValues (dict, keys, values);
+}
+
+
+const void *
+CFCMutableDictionary::GetValue(const void *key) const
+
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ return ::CFDictionaryGetValue (dict, key);
+ return NULL;
+}
+
+Boolean
+CFCMutableDictionary::GetValueIfPresent(const void *key, const void **value_handle) const
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ return ::CFDictionaryGetValueIfPresent (dict, key, value_handle);
+ return false;
+}
+
+
+CFMutableDictionaryRef
+CFCMutableDictionary::Dictionary(bool can_create)
+{
+ CFMutableDictionaryRef dict = get();
+ if (can_create && dict == NULL)
+ {
+ dict = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ reset ( dict );
+ }
+ return dict;
+}
+
+bool
+CFCMutableDictionary::AddValue(CFStringRef key, const void *value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, value);
+ return true;
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValue(CFStringRef key, const void *value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, value);
+ return true;
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::AddValueSInt8(CFStringRef key, int8_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt8Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueSInt8(CFStringRef key, int8_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt8Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::AddValueSInt16(CFStringRef key, int16_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt16Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueSInt16(CFStringRef key, int16_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt16Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::AddValueSInt32(CFStringRef key, int32_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueSInt32(CFStringRef key, int32_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::AddValueSInt64(CFStringRef key, int64_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt64Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueSInt64(CFStringRef key, int64_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt64Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::AddValueUInt8(CFStringRef key, uint8_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // Have to promote to the next size type so things don't appear negative of the MSBit is set...
+ int16_t sval = value;
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt16Type, &sval));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueUInt8(CFStringRef key, uint8_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // Have to promote to the next size type so things don't appear negative of the MSBit is set...
+ int16_t sval = value;
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt16Type, &sval));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+
+bool
+CFCMutableDictionary::AddValueUInt16(CFStringRef key, uint16_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // Have to promote to the next size type so things don't appear negative of the MSBit is set...
+ int32_t sval = value;
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &sval));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueUInt16(CFStringRef key, uint16_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // Have to promote to the next size type so things don't appear negative of the MSBit is set...
+ int32_t sval = value;
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &sval));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::AddValueUInt32(CFStringRef key, uint32_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // Have to promote to the next size type so things don't appear negative of the MSBit is set...
+ int64_t sval = value;
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt64Type, &sval));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueUInt32(CFStringRef key, uint32_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // Have to promote to the next size type so things don't appear negative of the MSBit is set...
+ int64_t sval = value;
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt64Type, &sval));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+
+bool
+CFCMutableDictionary::AddValueUInt64(CFStringRef key, uint64_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // The number may appear negative if the MSBit is set in "value". Due to a limitation of
+ // CFNumber, there isn't a way to have it show up otherwise as of this writing.
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt64Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+
+bool
+CFCMutableDictionary::SetValueUInt64(CFStringRef key, uint64_t value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // The number may appear negative if the MSBit is set in "value". Due to a limitation of
+ // CFNumber, there isn't a way to have it show up otherwise as of this writing.
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt64Type, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::AddValueDouble(CFStringRef key, double value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // The number may appear negative if the MSBit is set in "value". Due to a limitation of
+ // CFNumber, there isn't a way to have it show up otherwise as of this writing.
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberDoubleType, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueDouble(CFStringRef key, double value, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ // The number may appear negative if the MSBit is set in "value". Due to a limitation of
+ // CFNumber, there isn't a way to have it show up otherwise as of this writing.
+ CFCReleaser<CFNumberRef> cf_number(::CFNumberCreate (kCFAllocatorDefault, kCFNumberDoubleType, &value));
+ if (cf_number.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_number.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::AddValueCString(CFStringRef key, const char *cstr, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCString cf_str(cstr, kCFStringEncodingUTF8);
+ if (cf_str.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionaryAddValue (dict, key, cf_str.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+CFCMutableDictionary::SetValueCString(CFStringRef key, const char *cstr, bool can_create)
+{
+ CFMutableDictionaryRef dict = Dictionary(can_create);
+ if (dict != NULL)
+ {
+ CFCString cf_str(cstr, kCFStringEncodingUTF8);
+ if (cf_str.get())
+ {
+ // Let the dictionary own the CFNumber
+ ::CFDictionarySetValue (dict, key, cf_str.get());
+ return true;
+ }
+ }
+ return false;
+}
+
+
+void
+CFCMutableDictionary::RemoveAllValues()
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ ::CFDictionaryRemoveAllValues(dict);
+}
+
+void
+CFCMutableDictionary::RemoveValue(const void *value)
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ ::CFDictionaryRemoveValue(dict, value);
+}
+void
+CFCMutableDictionary::ReplaceValue(const void *key, const void *value)
+{
+ CFMutableDictionaryRef dict = get();
+ if (dict)
+ ::CFDictionaryReplaceValue (dict, key, value);
+}
+
diff --git a/source/Host/macosx/cfcpp/CFCMutableDictionary.h b/source/Host/macosx/cfcpp/CFCMutableDictionary.h
new file mode 100644
index 0000000000000..a1cfb68f569e1
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCMutableDictionary.h
@@ -0,0 +1,79 @@
+//===-- CFCMutableDictionary.h ----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CoreFoundationCPP_CFMutableDictionary_h_
+#define CoreFoundationCPP_CFMutableDictionary_h_
+
+#include "CFCReleaser.h"
+
+class CFCMutableDictionary : public CFCReleaser<CFMutableDictionaryRef>
+{
+public:
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CFCMutableDictionary(CFMutableDictionaryRef s = NULL);
+ CFCMutableDictionary(const CFCMutableDictionary& rhs);
+ virtual ~CFCMutableDictionary();
+
+ //------------------------------------------------------------------
+ // Operators
+ //------------------------------------------------------------------
+ const CFCMutableDictionary&
+ operator=(const CFCMutableDictionary& rhs);
+
+
+ CFIndex GetCount() const;
+ CFIndex GetCountOfKey(const void *value) const;
+ CFIndex GetCountOfValue(const void *value) const;
+ void GetKeysAndValues(const void **keys, const void **values) const;
+ const void * GetValue(const void *key) const;
+ Boolean GetValueIfPresent(const void *key, const void **value_handle) const;
+ bool AddValue(CFStringRef key, const void *value, bool can_create = false);
+ bool SetValue(CFStringRef key, const void *value, bool can_create = false);
+ bool AddValueSInt8(CFStringRef key, int8_t value, bool can_create = false);
+ bool SetValueSInt8(CFStringRef key, int8_t value, bool can_create = false);
+ bool AddValueSInt16(CFStringRef key, int16_t value, bool can_create = false);
+ bool SetValueSInt16(CFStringRef key, int16_t value, bool can_create = false);
+ bool AddValueSInt32(CFStringRef key, int32_t value, bool can_create = false);
+ bool SetValueSInt32(CFStringRef key, int32_t value, bool can_create = false);
+ bool AddValueSInt64(CFStringRef key, int64_t value, bool can_create = false);
+ bool SetValueSInt64(CFStringRef key, int64_t value, bool can_create = false);
+ bool AddValueUInt8(CFStringRef key, uint8_t value, bool can_create = false);
+ bool SetValueUInt8(CFStringRef key, uint8_t value, bool can_create = false);
+ bool AddValueUInt16(CFStringRef key, uint16_t value, bool can_create = false);
+ bool SetValueUInt16(CFStringRef key, uint16_t value, bool can_create = false);
+ bool AddValueUInt32(CFStringRef key, uint32_t value, bool can_create = false);
+ bool SetValueUInt32(CFStringRef key, uint32_t value, bool can_create = false);
+ bool AddValueUInt64(CFStringRef key, uint64_t value, bool can_create = false);
+ bool SetValueUInt64(CFStringRef key, uint64_t value, bool can_create = false);
+ bool AddValueDouble(CFStringRef key, double value, bool can_create = false);
+ bool SetValueDouble(CFStringRef key, double value, bool can_create = false);
+ bool AddValueCString(CFStringRef key, const char *cstr, bool can_create = false);
+ bool SetValueCString(CFStringRef key, const char *cstr, bool can_create = false);
+ void RemoveValue(const void *value);
+ void ReplaceValue(const void *key, const void *value);
+ void RemoveAllValues();
+ CFMutableDictionaryRef Dictionary(bool can_create);
+
+
+protected:
+ //------------------------------------------------------------------
+ // Classes that inherit from CFCMutableDictionary can see and modify these
+ //------------------------------------------------------------------
+
+private:
+ //------------------------------------------------------------------
+ // For CFCMutableDictionary only
+ //------------------------------------------------------------------
+
+};
+
+
+#endif // CoreFoundationCPP_CFMutableDictionary_h_
diff --git a/source/Host/macosx/cfcpp/CFCMutableSet.cpp b/source/Host/macosx/cfcpp/CFCMutableSet.cpp
new file mode 100644
index 0000000000000..afc09e180b6b6
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCMutableSet.cpp
@@ -0,0 +1,114 @@
+//===-- CFCMutableSet.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CFCMutableSet.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+
+//----------------------------------------------------------------------
+// CFCString constructor
+//----------------------------------------------------------------------
+CFCMutableSet::CFCMutableSet(CFMutableSetRef s) :
+ CFCReleaser<CFMutableSetRef> (s)
+{
+}
+
+//----------------------------------------------------------------------
+// CFCMutableSet copy constructor
+//----------------------------------------------------------------------
+CFCMutableSet::CFCMutableSet(const CFCMutableSet& rhs) :
+ CFCReleaser<CFMutableSetRef> (rhs)
+{
+}
+
+//----------------------------------------------------------------------
+// CFCMutableSet copy constructor
+//----------------------------------------------------------------------
+const CFCMutableSet&
+CFCMutableSet::operator=(const CFCMutableSet& rhs)
+{
+ if (this != &rhs)
+ *this = rhs;
+ return *this;
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+CFCMutableSet::~CFCMutableSet()
+{
+}
+
+
+CFIndex
+CFCMutableSet::GetCount() const
+{
+ CFMutableSetRef set = get();
+ if (set)
+ return ::CFSetGetCount (set);
+ return 0;
+}
+
+CFIndex
+CFCMutableSet::GetCountOfValue(const void *value) const
+{
+ CFMutableSetRef set = get();
+ if (set)
+ return ::CFSetGetCountOfValue (set, value);
+ return 0;
+}
+
+const void *
+CFCMutableSet::GetValue(const void *value) const
+{
+ CFMutableSetRef set = get();
+ if (set)
+ return ::CFSetGetValue(set, value);
+ return NULL;
+}
+
+
+const void *
+CFCMutableSet::AddValue(const void *value, bool can_create)
+{
+ CFMutableSetRef set = get();
+ if (set == NULL)
+ {
+ if (can_create == false)
+ return NULL;
+ set = ::CFSetCreateMutable(kCFAllocatorDefault, 0, &kCFTypeSetCallBacks);
+ reset ( set );
+ }
+ if (set != NULL)
+ {
+ ::CFSetAddValue(set, value);
+ return value;
+ }
+ return NULL;
+}
+
+void
+CFCMutableSet::RemoveValue(const void *value)
+{
+ CFMutableSetRef set = get();
+ if (set)
+ ::CFSetRemoveValue(set, value);
+}
+
+void
+CFCMutableSet::RemoveAllValues()
+{
+ CFMutableSetRef set = get();
+ if (set)
+ ::CFSetRemoveAllValues(set);
+}
+
diff --git a/source/Host/macosx/cfcpp/CFCMutableSet.h b/source/Host/macosx/cfcpp/CFCMutableSet.h
new file mode 100644
index 0000000000000..78f7a8be81d20
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCMutableSet.h
@@ -0,0 +1,53 @@
+//===-- CFCMutableSet.h -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CoreFoundationCPP_CFMutableSet_h_
+#define CoreFoundationCPP_CFMutableSet_h_
+
+#include "CFCReleaser.h"
+
+class CFCMutableSet : public CFCReleaser<CFMutableSetRef>
+{
+public:
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CFCMutableSet(CFMutableSetRef s = NULL);
+ CFCMutableSet(const CFCMutableSet& rhs);
+ virtual ~CFCMutableSet();
+
+ //------------------------------------------------------------------
+ // Operators
+ //------------------------------------------------------------------
+ const CFCMutableSet&
+ operator=(const CFCMutableSet& rhs);
+
+
+ CFIndex GetCount() const;
+ CFIndex GetCountOfValue(const void *value) const;
+ const void * GetValue(const void *value) const;
+ const void * AddValue(const void *value, bool can_create);
+ void RemoveValue(const void *value);
+ void RemoveAllValues();
+
+
+
+protected:
+ //------------------------------------------------------------------
+ // Classes that inherit from CFCMutableSet can see and modify these
+ //------------------------------------------------------------------
+
+private:
+ //------------------------------------------------------------------
+ // For CFCMutableSet only
+ //------------------------------------------------------------------
+
+};
+
+#endif // CoreFoundationCPP_CFMutableSet_h_
diff --git a/source/Host/macosx/cfcpp/CFCReleaser.h b/source/Host/macosx/cfcpp/CFCReleaser.h
new file mode 100644
index 0000000000000..67dd2ead57990
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCReleaser.h
@@ -0,0 +1,158 @@
+//===-- CFCReleaser.h -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CoreFoundationCPP_CFReleaser_h_
+#define CoreFoundationCPP_CFReleaser_h_
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#ifdef __cplusplus
+
+#include <assert.h>
+
+//----------------------------------------------------------------------
+// Templatized CF helper class that can own any CF pointer and will
+// call CFRelease() on any valid pointer it owns unless that pointer is
+// explicitly released using the release() member function. This class
+// is designed to mimic the std::auto_ptr<T> class and has all of the
+// same functions. The one thing to watch out for is the
+// CFCReleaser<T>::release() function won't actually CFRelease any owned
+// pointer, it is designed to relinquish ownership of the pointer just
+// like std:auto_ptr<T>::release() does.
+//----------------------------------------------------------------------
+template <class T>
+class CFCReleaser
+{
+public:
+ //----------------------------------------------------------
+ // Constructor that takes a pointer to a CF object that is
+ // to be released when this object goes out of scope
+ //----------------------------------------------------------
+ CFCReleaser(T ptr = NULL) :
+ _ptr(ptr)
+ {
+ }
+
+ //----------------------------------------------------------
+ // Copy constructor
+ //
+ // Note that copying a CFCReleaser will not transfer
+ // ownership of the contained pointer, but it will bump its
+ // reference count. This is where this class differs from
+ // std::auto_ptr.
+ //----------------------------------------------------------
+ CFCReleaser(const CFCReleaser& rhs) :
+ _ptr(rhs.get())
+ {
+ if (get())
+ ::CFRetain(get());
+ }
+
+
+ //----------------------------------------------------------
+ // The destructor will release the pointer that it contains
+ // if it has a valid pointer.
+ //----------------------------------------------------------
+ virtual ~CFCReleaser()
+ {
+ reset();
+ }
+
+ //----------------------------------------------------------
+ // Assignment operator.
+ //
+ // Note that assigning one CFCReleaser to another will
+ // not transfer ownership of the contained pointer, but it
+ // will bump its reference count. This is where this class
+ // differs from std::auto_ptr.
+ //----------------------------------------------------------
+ CFCReleaser&
+ operator= (const CFCReleaser<T>& rhs)
+ {
+ if (this != &rhs)
+ {
+ // Replace our owned pointer with the new one
+ reset(rhs.get());
+ // Retain the current pointer that we own
+ if (get())
+ ::CFRetain(get());
+ }
+ return *this;
+ }
+
+ //----------------------------------------------------------
+ // Get the address of the contained type in case it needs
+ // to be passed to a function that will fill in a pointer
+ // value. The function currently will assert if _ptr is not
+ // NULL because the only time this method should be used is
+ // if another function will modify the contents, and we
+ // could leak a pointer if this is not NULL. If the
+ // assertion fires, check the offending code, or call
+ // reset() prior to using the "ptr_address()" member to make
+ // sure any owned objects has CFRelease called on it.
+ // I had to add the "enforce_null" bool here because some
+ // API's require the pointer address even though they don't change it.
+ //----------------------------------------------------------
+ T*
+ ptr_address(bool enforce_null = true)
+ {
+ if (enforce_null)
+ assert (_ptr == NULL);
+ return &_ptr;
+ }
+
+ //----------------------------------------------------------
+ // Access the pointer itself
+ //----------------------------------------------------------
+ T
+ get()
+ {
+ return _ptr;
+ }
+
+ const T
+ get() const
+ {
+ return _ptr;
+ }
+
+
+ //----------------------------------------------------------
+ // Set a new value for the pointer and CFRelease our old
+ // value if we had a valid one.
+ //----------------------------------------------------------
+ void
+ reset(T ptr = NULL)
+ {
+ if ((_ptr != NULL) && (ptr != _ptr))
+ ::CFRelease(_ptr);
+ _ptr = ptr;
+ }
+
+ //----------------------------------------------------------
+ // Release ownership without calling CFRelease. This class
+ // is designed to mimic std::auto_ptr<T>, so the release
+ // method releases ownership of the contained pointer
+ // and does NOT call CFRelease.
+ //----------------------------------------------------------
+ T
+ release()
+ {
+ T tmp = _ptr;
+ _ptr = NULL;
+ return tmp;
+ }
+
+private:
+ T _ptr;
+};
+
+#endif // #ifdef __cplusplus
+#endif // #ifndef CoreFoundationCPP_CFReleaser_h_
+
diff --git a/source/Host/macosx/cfcpp/CFCString.cpp b/source/Host/macosx/cfcpp/CFCString.cpp
new file mode 100644
index 0000000000000..81a96b824999c
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCString.cpp
@@ -0,0 +1,195 @@
+//===-- CFCString.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CFCString.h"
+#include <string>
+#include <glob.h>
+
+//----------------------------------------------------------------------
+// CFCString constructor
+//----------------------------------------------------------------------
+CFCString::CFCString(CFStringRef s) :
+ CFCReleaser<CFStringRef> (s)
+{
+}
+
+//----------------------------------------------------------------------
+// CFCString copy constructor
+//----------------------------------------------------------------------
+CFCString::CFCString(const CFCString& rhs) :
+ CFCReleaser<CFStringRef> (rhs)
+{
+
+}
+
+//----------------------------------------------------------------------
+// CFCString copy constructor
+//----------------------------------------------------------------------
+CFCString&
+CFCString::operator=(const CFCString& rhs)
+{
+ if (this != &rhs)
+ *this = rhs;
+ return *this;
+}
+
+CFCString::CFCString (const char *cstr, CFStringEncoding cstr_encoding) :
+ CFCReleaser<CFStringRef> ()
+{
+ if (cstr && cstr[0])
+ {
+ reset(::CFStringCreateWithCString(kCFAllocatorDefault, cstr, cstr_encoding));
+ }
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+CFCString::~CFCString()
+{
+}
+
+const char *
+CFCString::GetFileSystemRepresentation(std::string& s)
+{
+ return CFCString::FileSystemRepresentation(get(), s);
+}
+
+CFStringRef
+CFCString::SetFileSystemRepresentation (const char *path)
+{
+ CFStringRef new_value = NULL;
+ if (path && path[0])
+ new_value = ::CFStringCreateWithFileSystemRepresentation (kCFAllocatorDefault, path);
+ reset(new_value);
+ return get();
+}
+
+
+CFStringRef
+CFCString::SetFileSystemRepresentationFromCFType (CFTypeRef cf_type)
+{
+ CFStringRef new_value = NULL;
+ if (cf_type != NULL)
+ {
+ CFTypeID cf_type_id = ::CFGetTypeID(cf_type);
+
+ if (cf_type_id == ::CFStringGetTypeID())
+ {
+ // Retain since we are using the existing object
+ new_value = (CFStringRef)::CFRetain(cf_type);
+ }
+ else if (cf_type_id == ::CFURLGetTypeID())
+ {
+ new_value = ::CFURLCopyFileSystemPath((CFURLRef)cf_type, kCFURLPOSIXPathStyle);
+ }
+ }
+ reset(new_value);
+ return get();
+}
+
+CFStringRef
+CFCString::SetFileSystemRepresentationAndExpandTilde (const char *path)
+{
+ std::string expanded_path;
+ if (CFCString::ExpandTildeInPath(path, expanded_path))
+ SetFileSystemRepresentation(expanded_path.c_str());
+ else
+ reset();
+ return get();
+}
+
+const char *
+CFCString::UTF8(std::string& str)
+{
+ return CFCString::UTF8(get(), str);
+}
+
+// Static function that puts a copy of the UTF8 contents of CF_STR into STR
+// and returns the C string pointer that is contained in STR when successful, else
+// NULL is returned. This allows the std::string parameter to own the extracted string,
+// and also allows that string to be returned as a C string pointer that can be used.
+
+const char *
+CFCString::UTF8 (CFStringRef cf_str, std::string& str)
+{
+ if (cf_str)
+ {
+ const CFStringEncoding encoding = kCFStringEncodingUTF8;
+ CFIndex max_utf8_str_len = CFStringGetLength (cf_str);
+ max_utf8_str_len = CFStringGetMaximumSizeForEncoding (max_utf8_str_len, encoding);
+ if (max_utf8_str_len > 0)
+ {
+ str.resize(max_utf8_str_len);
+ if (!str.empty())
+ {
+ if (CFStringGetCString (cf_str, &str[0], str.size(), encoding))
+ {
+ str.resize(strlen(str.c_str()));
+ return str.c_str();
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+const char*
+CFCString::ExpandTildeInPath(const char* path, std::string &expanded_path)
+{
+ glob_t globbuf;
+ if (::glob (path, GLOB_TILDE, NULL, &globbuf) == 0)
+ {
+ expanded_path = globbuf.gl_pathv[0];
+ ::globfree (&globbuf);
+ }
+ else
+ expanded_path.clear();
+
+ return expanded_path.c_str();
+}
+
+// Static function that puts a copy of the file system representation of CF_STR
+// into STR and returns the C string pointer that is contained in STR when
+// successful, else NULL is returned. This allows the std::string parameter
+// to own the extracted string, and also allows that string to be returned as
+// a C string pointer that can be used.
+
+const char *
+CFCString::FileSystemRepresentation (CFStringRef cf_str, std::string& str)
+{
+ if (cf_str)
+ {
+ CFIndex max_length = ::CFStringGetMaximumSizeOfFileSystemRepresentation (cf_str);
+ if (max_length > 0)
+ {
+ str.resize(max_length);
+ if (!str.empty())
+ {
+ if (::CFStringGetFileSystemRepresentation (cf_str, &str[0], str.size()))
+ {
+ str.erase(::strlen(str.c_str()));
+ return str.c_str();
+ }
+ }
+ }
+ }
+ str.erase();
+ return NULL;
+}
+
+
+CFIndex
+CFCString::GetLength() const
+{
+ CFStringRef str = get();
+ if (str)
+ return CFStringGetLength (str);
+ return 0;
+}
diff --git a/source/Host/macosx/cfcpp/CFCString.h b/source/Host/macosx/cfcpp/CFCString.h
new file mode 100644
index 0000000000000..27c090313ece6
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CFCString.h
@@ -0,0 +1,41 @@
+//===-- CFCString.h ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CoreFoundationCPP_CFString_h_
+#define CoreFoundationCPP_CFString_h_
+
+#include <iosfwd>
+
+#include "CFCReleaser.h"
+
+class CFCString : public CFCReleaser<CFStringRef>
+{
+public:
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CFCString (CFStringRef cf_str = NULL);
+ CFCString (const char *s, CFStringEncoding encoding = kCFStringEncodingUTF8);
+ CFCString (const CFCString& rhs);
+ CFCString& operator= (const CFCString& rhs);
+ virtual ~CFCString ();
+
+ const char * GetFileSystemRepresentation (std::string& str);
+ CFStringRef SetFileSystemRepresentation (const char *path);
+ CFStringRef SetFileSystemRepresentationFromCFType (CFTypeRef cf_type);
+ CFStringRef SetFileSystemRepresentationAndExpandTilde (const char *path);
+ const char * UTF8 (std::string& str);
+ CFIndex GetLength() const;
+ static const char *UTF8 (CFStringRef cf_str, std::string& str);
+ static const char *FileSystemRepresentation (CFStringRef cf_str, std::string& str);
+ static const char *ExpandTildeInPath(const char* path, std::string &expanded_path);
+
+};
+
+#endif // #ifndef CoreFoundationCPP_CFString_h_
diff --git a/source/Host/macosx/cfcpp/CoreFoundationCPP.h b/source/Host/macosx/cfcpp/CoreFoundationCPP.h
new file mode 100644
index 0000000000000..6843e2649cdab
--- /dev/null
+++ b/source/Host/macosx/cfcpp/CoreFoundationCPP.h
@@ -0,0 +1,30 @@
+//===-- CoreFoundationCPP.h -------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//----------------------------------------------------------------------
+//
+// CoreFoundationCPP.h
+// CoreFoundationCPP
+//
+// Created by Greg Clayton on 4/23/09.
+//
+//
+//----------------------------------------------------------------------
+
+#ifndef CoreFoundationCPP_CoreFoundationCPP_H_
+#define CoreFoundationCPP_CoreFoundationCPP_H_
+
+#include <CoreFoundationCPP/CFCBundle.h>
+#include <CoreFoundationCPP/CFCData.h>
+#include <CoreFoundationCPP/CFCReleaser.h>
+#include <CoreFoundationCPP/CFCMutableArray.h>
+#include <CoreFoundationCPP/CFCMutableDictionary.h>
+#include <CoreFoundationCPP/CFCMutableSet.h>
+#include <CoreFoundationCPP/CFCString.h>
+
+#endif // CoreFoundationCPP_CoreFoundationCPP_H_