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 CFCMutableSet(const CFCMutableSet & rhs)17CFCMutableSet::CFCMutableSet(const CFCMutableSet &rhs) 18 : CFCReleaser<CFMutableSetRef>(rhs) {} 19 20 // CFCMutableSet copy constructor operator =(const CFCMutableSet & rhs)21const CFCMutableSet &CFCMutableSet::operator=(const CFCMutableSet &rhs) { 22 if (this != &rhs) 23 *this = rhs; 24 return *this; 25 } 26 27 // Destructor ~CFCMutableSet()28CFCMutableSet::~CFCMutableSet() {} 29 GetCount() const30CFIndex CFCMutableSet::GetCount() const { 31 CFMutableSetRef set = get(); 32 if (set) 33 return ::CFSetGetCount(set); 34 return 0; 35 } 36 GetCountOfValue(const void * value) const37CFIndex CFCMutableSet::GetCountOfValue(const void *value) const { 38 CFMutableSetRef set = get(); 39 if (set) 40 return ::CFSetGetCountOfValue(set, value); 41 return 0; 42 } 43 GetValue(const void * value) const44const void *CFCMutableSet::GetValue(const void *value) const { 45 CFMutableSetRef set = get(); 46 if (set) 47 return ::CFSetGetValue(set, value); 48 return NULL; 49 } 50 AddValue(const void * value,bool can_create)51const void *CFCMutableSet::AddValue(const void *value, bool can_create) { 52 CFMutableSetRef set = get(); 53 if (set == NULL) { 54 if (!can_create) 55 return NULL; 56 set = ::CFSetCreateMutable(kCFAllocatorDefault, 0, &kCFTypeSetCallBacks); 57 reset(set); 58 } 59 if (set != NULL) { 60 ::CFSetAddValue(set, value); 61 return value; 62 } 63 return NULL; 64 } 65 RemoveValue(const void * value)66void CFCMutableSet::RemoveValue(const void *value) { 67 CFMutableSetRef set = get(); 68 if (set) 69 ::CFSetRemoveValue(set, value); 70 } 71 RemoveAllValues()72void CFCMutableSet::RemoveAllValues() { 73 CFMutableSetRef set = get(); 74 if (set) 75 ::CFSetRemoveAllValues(set); 76 } 77