Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CFCMutableSet.cpp ---------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "CFCMutableSet.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | |
| 17 | //---------------------------------------------------------------------- |
| 18 | // CFCString constructor |
| 19 | //---------------------------------------------------------------------- |
| 20 | CFCMutableSet::CFCMutableSet(CFMutableSetRef s) : |
| 21 | CFCReleaser<CFMutableSetRef> (s) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | //---------------------------------------------------------------------- |
| 26 | // CFCMutableSet copy constructor |
| 27 | //---------------------------------------------------------------------- |
| 28 | CFCMutableSet::CFCMutableSet(const CFCMutableSet& rhs) : |
| 29 | CFCReleaser<CFMutableSetRef> (rhs) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | //---------------------------------------------------------------------- |
| 34 | // CFCMutableSet copy constructor |
| 35 | //---------------------------------------------------------------------- |
| 36 | const CFCMutableSet& |
| 37 | CFCMutableSet::operator=(const CFCMutableSet& rhs) |
| 38 | { |
| 39 | if (this != &rhs) |
| 40 | *this = rhs; |
| 41 | return *this; |
| 42 | } |
| 43 | |
| 44 | //---------------------------------------------------------------------- |
| 45 | // Destructor |
| 46 | //---------------------------------------------------------------------- |
| 47 | CFCMutableSet::~CFCMutableSet() |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | |
| 52 | CFIndex |
| 53 | CFCMutableSet::GetCount() const |
| 54 | { |
| 55 | CFMutableSetRef set = get(); |
| 56 | if (set) |
| 57 | return ::CFSetGetCount (set); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | CFIndex |
| 62 | CFCMutableSet::GetCountOfValue(const void *value) const |
| 63 | { |
| 64 | CFMutableSetRef set = get(); |
| 65 | if (set) |
| 66 | return ::CFSetGetCountOfValue (set, value); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | const void * |
| 71 | CFCMutableSet::GetValue(const void *value) const |
| 72 | { |
| 73 | CFMutableSetRef set = get(); |
| 74 | if (set) |
| 75 | return ::CFSetGetValue(set, value); |
| 76 | return NULL; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | const void * |
| 81 | CFCMutableSet::AddValue(const void *value, bool can_create) |
| 82 | { |
| 83 | CFMutableSetRef set = get(); |
| 84 | if (set == NULL) |
| 85 | { |
| 86 | if (can_create == false) |
Greg Clayton | f8e98a6 | 2010-07-23 15:37:46 +0000 | [diff] [blame] | 87 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | set = ::CFSetCreateMutable(kCFAllocatorDefault, 0, &kCFTypeSetCallBacks); |
| 89 | reset ( set ); |
| 90 | } |
| 91 | if (set != NULL) |
| 92 | { |
| 93 | ::CFSetAddValue(set, value); |
| 94 | return value; |
| 95 | } |
| 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | void |
| 100 | CFCMutableSet::RemoveValue(const void *value) |
| 101 | { |
| 102 | CFMutableSetRef set = get(); |
| 103 | if (set) |
| 104 | ::CFSetRemoveValue(set, value); |
| 105 | } |
| 106 | |
| 107 | void |
| 108 | CFCMutableSet::RemoveAllValues() |
| 109 | { |
| 110 | CFMutableSetRef set = get(); |
| 111 | if (set) |
| 112 | ::CFSetRemoveAllValues(set); |
| 113 | } |
| 114 | |