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