1 //===-- CFCMutableSet.cpp -------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "CFCMutableSet.h" 10 11 12 // CFCString constructor CFCMutableSet(CFMutableSetRef s)13CFCMutableSet::CFCMutableSet(CFMutableSetRef s) 14 : CFCReleaser<CFMutableSetRef>(s) {} 15 16 // CFCMutableSet copy constructor 17 CFCMutableSet::CFCMutableSet(const CFCMutableSet &rhs) = default; 18 19 // CFCMutableSet copy constructor operator =(const CFCMutableSet & rhs)20const CFCMutableSet &CFCMutableSet::operator=(const CFCMutableSet &rhs) { 21 if (this != &rhs) 22 *this = rhs; 23 return *this; 24 } 25 26 // Destructor 27 CFCMutableSet::~CFCMutableSet() = default; 28 GetCount() const29CFIndex CFCMutableSet::GetCount() const { 30 CFMutableSetRef set = get(); 31 if (set) 32 return ::CFSetGetCount(set); 33 return 0; 34 } 35 GetCountOfValue(const void * value) const36CFIndex CFCMutableSet::GetCountOfValue(const void *value) const { 37 CFMutableSetRef set = get(); 38 if (set) 39 return ::CFSetGetCountOfValue(set, value); 40 return 0; 41 } 42 GetValue(const void * value) const43const void *CFCMutableSet::GetValue(const void *value) const { 44 CFMutableSetRef set = get(); 45 if (set) 46 return ::CFSetGetValue(set, value); 47 return NULL; 48 } 49 AddValue(const void * value,bool can_create)50const void *CFCMutableSet::AddValue(const void *value, bool can_create) { 51 CFMutableSetRef set = get(); 52 if (set == NULL) { 53 if (!can_create) 54 return NULL; 55 set = ::CFSetCreateMutable(kCFAllocatorDefault, 0, &kCFTypeSetCallBacks); 56 reset(set); 57 } 58 if (set != NULL) { 59 ::CFSetAddValue(set, value); 60 return value; 61 } 62 return NULL; 63 } 64 RemoveValue(const void * value)65void CFCMutableSet::RemoveValue(const void *value) { 66 CFMutableSetRef set = get(); 67 if (set) 68 ::CFSetRemoveValue(set, value); 69 } 70 RemoveAllValues()71void CFCMutableSet::RemoveAllValues() { 72 CFMutableSetRef set = get(); 73 if (set) 74 ::CFSetRemoveAllValues(set); 75 } 76