1 //===-- CFCMutableArray.cpp -----------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "CFCMutableArray.h"
10 #include "CFCString.h"
12 // CFCString constructor
13 CFCMutableArray::CFCMutableArray(CFMutableArrayRef s
)
14 : CFCReleaser
<CFMutableArrayRef
>(s
) {}
16 // CFCMutableArray copy constructor
17 CFCMutableArray::CFCMutableArray(const CFCMutableArray
&rhs
) =
18 default; // NOTE: this won't make a copy of the
19 // array, just add a new reference to
22 // CFCMutableArray copy constructor
23 CFCMutableArray
&CFCMutableArray::operator=(const CFCMutableArray
&rhs
) {
25 *this = rhs
; // NOTE: this operator won't make a copy of the array, just add
26 // a new reference to it
31 CFCMutableArray::~CFCMutableArray() = default;
33 CFIndex
CFCMutableArray::GetCount() const {
34 CFMutableArrayRef array
= get();
36 return ::CFArrayGetCount(array
);
40 CFIndex
CFCMutableArray::GetCountOfValue(CFRange range
,
41 const void *value
) const {
42 CFMutableArrayRef array
= get();
44 return ::CFArrayGetCountOfValue(array
, range
, value
);
48 CFIndex
CFCMutableArray::GetCountOfValue(const void *value
) const {
49 CFMutableArrayRef array
= get();
51 return ::CFArrayGetCountOfValue(array
, CFRangeMake(0, GetCount()), value
);
55 const void *CFCMutableArray::GetValueAtIndex(CFIndex idx
) const {
56 CFMutableArrayRef array
= get();
58 const CFIndex num_array_items
= ::CFArrayGetCount(array
);
59 if (0 <= idx
&& idx
< num_array_items
) {
60 return ::CFArrayGetValueAtIndex(array
, idx
);
66 bool CFCMutableArray::SetValueAtIndex(CFIndex idx
, const void *value
) {
67 CFMutableArrayRef array
= get();
69 const CFIndex num_array_items
= ::CFArrayGetCount(array
);
70 if (0 <= idx
&& idx
< num_array_items
) {
71 ::CFArraySetValueAtIndex(array
, idx
, value
);
78 bool CFCMutableArray::AppendValue(const void *value
, bool can_create
) {
79 CFMutableArrayRef array
= get();
84 ::CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
88 ::CFArrayAppendValue(array
, value
);
94 bool CFCMutableArray::AppendCStringAsCFString(const char *s
,
95 CFStringEncoding encoding
,
97 CFMutableArrayRef array
= get();
102 ::CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
106 CFCString
cf_str(s
, encoding
);
107 ::CFArrayAppendValue(array
, cf_str
.get());
113 bool CFCMutableArray::AppendFileSystemRepresentationAsCFString(
114 const char *s
, bool can_create
) {
115 CFMutableArrayRef array
= get();
120 ::CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
125 cf_path
.SetFileSystemRepresentation(s
);
126 ::CFArrayAppendValue(array
, cf_path
.get());