LLDB  mainline
CFCMutableArray.cpp
Go to the documentation of this file.
1 //===-- CFCMutableArray.cpp -----------------------------------------------===//
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 "CFCMutableArray.h"
10 #include "CFCString.h"
11 
12 // CFCString constructor
14  : CFCReleaser<CFMutableArrayRef>(s) {}
15 
16 // CFCMutableArray copy constructor
18  : CFCReleaser<CFMutableArrayRef>(rhs) // NOTE: this won't make a copy of the
19  // array, just add a new reference to
20  // it
21 {}
22 
23 // CFCMutableArray copy constructor
25  if (this != &rhs)
26  *this = rhs; // NOTE: this operator won't make a copy of the array, just add
27  // a new reference to it
28  return *this;
29 }
30 
31 // Destructor
33 
34 CFIndex CFCMutableArray::GetCount() const {
35  CFMutableArrayRef array = get();
36  if (array)
37  return ::CFArrayGetCount(array);
38  return 0;
39 }
40 
41 CFIndex CFCMutableArray::GetCountOfValue(CFRange range,
42  const void *value) const {
43  CFMutableArrayRef array = get();
44  if (array)
45  return ::CFArrayGetCountOfValue(array, range, value);
46  return 0;
47 }
48 
49 CFIndex CFCMutableArray::GetCountOfValue(const void *value) const {
50  CFMutableArrayRef array = get();
51  if (array)
52  return ::CFArrayGetCountOfValue(array, CFRangeMake(0, GetCount()), value);
53  return 0;
54 }
55 
56 const void *CFCMutableArray::GetValueAtIndex(CFIndex idx) const {
57  CFMutableArrayRef array = get();
58  if (array) {
59  const CFIndex num_array_items = ::CFArrayGetCount(array);
60  if (0 <= idx && idx < num_array_items) {
61  return ::CFArrayGetValueAtIndex(array, idx);
62  }
63  }
64  return NULL;
65 }
66 
67 bool CFCMutableArray::SetValueAtIndex(CFIndex idx, const void *value) {
68  CFMutableArrayRef array = get();
69  if (array != NULL) {
70  const CFIndex num_array_items = ::CFArrayGetCount(array);
71  if (0 <= idx && idx < num_array_items) {
72  ::CFArraySetValueAtIndex(array, idx, value);
73  return true;
74  }
75  }
76  return false;
77 }
78 
79 bool CFCMutableArray::AppendValue(const void *value, bool can_create) {
80  CFMutableArrayRef array = get();
81  if (array == NULL) {
82  if (!can_create)
83  return false;
84  array =
85  ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
86  reset(array);
87  }
88  if (array != NULL) {
89  ::CFArrayAppendValue(array, value);
90  return true;
91  }
92  return false;
93 }
94 
96  CFStringEncoding encoding,
97  bool can_create) {
98  CFMutableArrayRef array = get();
99  if (array == NULL) {
100  if (!can_create)
101  return false;
102  array =
103  ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
104  reset(array);
105  }
106  if (array != NULL) {
107  CFCString cf_str(s, encoding);
108  ::CFArrayAppendValue(array, cf_str.get());
109  return true;
110  }
111  return false;
112 }
113 
115  const char *s, bool can_create) {
116  CFMutableArrayRef array = get();
117  if (array == NULL) {
118  if (!can_create)
119  return false;
120  array =
121  ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
122  reset(array);
123  }
124  if (array != NULL) {
125  CFCString cf_path;
126  cf_path.SetFileSystemRepresentation(s);
127  ::CFArrayAppendValue(array, cf_path.get());
128  return true;
129  }
130  return false;
131 }
CFCMutableArray::operator=
CFCMutableArray & operator=(const CFCMutableArray &rhs)
Definition: CFCMutableArray.cpp:24
CFCMutableArray::GetCount
CFIndex GetCount() const
Definition: CFCMutableArray.cpp:34
CFCMutableArray::GetValueAtIndex
const void * GetValueAtIndex(CFIndex idx) const
Definition: CFCMutableArray.cpp:56
CFCMutableArray::AppendFileSystemRepresentationAsCFString
bool AppendFileSystemRepresentationAsCFString(const char *s, bool can_create=true)
Definition: CFCMutableArray.cpp:114
CFCMutableArray.h
CFCString
Definition: CFCString.h:16
CFCReleaser
CFCString::SetFileSystemRepresentation
CFStringRef SetFileSystemRepresentation(const char *path)
Definition: CFCString.cpp:41
CFCMutableArray::AppendCStringAsCFString
bool AppendCStringAsCFString(const char *cstr, CFStringEncoding encoding=kCFStringEncodingUTF8, bool can_create=true)
Definition: CFCMutableArray.cpp:95
CFCMutableArray::GetCountOfValue
CFIndex GetCountOfValue(const void *value) const
Definition: CFCMutableArray.cpp:49
CFCMutableArray::SetValueAtIndex
bool SetValueAtIndex(CFIndex idx, const void *value)
Definition: CFCMutableArray.cpp:67
CFCMutableArray::~CFCMutableArray
virtual ~CFCMutableArray()
CFCMutableArray::CFCMutableArray
CFCMutableArray(CFMutableArrayRef array=NULL)
Definition: CFCMutableArray.cpp:13
CFCMutableArray
Definition: CFCMutableArray.h:14
CFCString.h
CFCMutableArray::AppendValue
bool AppendValue(const void *value, bool can_create=true)
Definition: CFCMutableArray.cpp:79