xref: /openbsd-src/gnu/llvm/lldb/source/Host/macosx/cfcpp/CFCMutableSet.cpp (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1dda28197Spatrick //===-- CFCMutableSet.cpp -------------------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9061da546Spatrick #include "CFCMutableSet.h"
10061da546Spatrick 
11061da546Spatrick 
12061da546Spatrick // CFCString constructor
CFCMutableSet(CFMutableSetRef s)13061da546Spatrick CFCMutableSet::CFCMutableSet(CFMutableSetRef s)
14061da546Spatrick     : CFCReleaser<CFMutableSetRef>(s) {}
15061da546Spatrick 
16061da546Spatrick // CFCMutableSet copy constructor
17*f6aab3d8Srobert CFCMutableSet::CFCMutableSet(const CFCMutableSet &rhs) = default;
18061da546Spatrick 
19061da546Spatrick // CFCMutableSet copy constructor
operator =(const CFCMutableSet & rhs)20061da546Spatrick const CFCMutableSet &CFCMutableSet::operator=(const CFCMutableSet &rhs) {
21061da546Spatrick   if (this != &rhs)
22061da546Spatrick     *this = rhs;
23061da546Spatrick   return *this;
24061da546Spatrick }
25061da546Spatrick 
26061da546Spatrick // Destructor
27be691f3bSpatrick CFCMutableSet::~CFCMutableSet() = default;
28061da546Spatrick 
GetCount() const29061da546Spatrick CFIndex CFCMutableSet::GetCount() const {
30061da546Spatrick   CFMutableSetRef set = get();
31061da546Spatrick   if (set)
32061da546Spatrick     return ::CFSetGetCount(set);
33061da546Spatrick   return 0;
34061da546Spatrick }
35061da546Spatrick 
GetCountOfValue(const void * value) const36061da546Spatrick CFIndex CFCMutableSet::GetCountOfValue(const void *value) const {
37061da546Spatrick   CFMutableSetRef set = get();
38061da546Spatrick   if (set)
39061da546Spatrick     return ::CFSetGetCountOfValue(set, value);
40061da546Spatrick   return 0;
41061da546Spatrick }
42061da546Spatrick 
GetValue(const void * value) const43061da546Spatrick const void *CFCMutableSet::GetValue(const void *value) const {
44061da546Spatrick   CFMutableSetRef set = get();
45061da546Spatrick   if (set)
46061da546Spatrick     return ::CFSetGetValue(set, value);
47061da546Spatrick   return NULL;
48061da546Spatrick }
49061da546Spatrick 
AddValue(const void * value,bool can_create)50061da546Spatrick const void *CFCMutableSet::AddValue(const void *value, bool can_create) {
51061da546Spatrick   CFMutableSetRef set = get();
52061da546Spatrick   if (set == NULL) {
53061da546Spatrick     if (!can_create)
54061da546Spatrick       return NULL;
55061da546Spatrick     set = ::CFSetCreateMutable(kCFAllocatorDefault, 0, &kCFTypeSetCallBacks);
56061da546Spatrick     reset(set);
57061da546Spatrick   }
58061da546Spatrick   if (set != NULL) {
59061da546Spatrick     ::CFSetAddValue(set, value);
60061da546Spatrick     return value;
61061da546Spatrick   }
62061da546Spatrick   return NULL;
63061da546Spatrick }
64061da546Spatrick 
RemoveValue(const void * value)65061da546Spatrick void CFCMutableSet::RemoveValue(const void *value) {
66061da546Spatrick   CFMutableSetRef set = get();
67061da546Spatrick   if (set)
68061da546Spatrick     ::CFSetRemoveValue(set, value);
69061da546Spatrick }
70061da546Spatrick 
RemoveAllValues()71061da546Spatrick void CFCMutableSet::RemoveAllValues() {
72061da546Spatrick   CFMutableSetRef set = get();
73061da546Spatrick   if (set)
74061da546Spatrick     ::CFSetRemoveAllValues(set);
75061da546Spatrick }
76