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