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