LLDB mainline
CFCData.cpp
Go to the documentation of this file.
1//===-- CFCData.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 "CFCData.h"
10
11// CFCData constructor
13
14// CFCData copy constructor
15CFCData::CFCData(const CFCData &rhs) = default;
16
17// CFCData copy constructor
19
20{
21 if (this != &rhs)
22 *this = rhs;
23 return *this;
24}
25
26// Destructor
27CFCData::~CFCData() = default;
28
29CFIndex CFCData::GetLength() const {
30 CFDataRef data = get();
31 if (data)
32 return CFDataGetLength(data);
33 return 0;
34}
35
36const uint8_t *CFCData::GetBytePtr() const {
37 CFDataRef data = get();
38 if (data)
39 return CFDataGetBytePtr(data);
40 return NULL;
41}
42
43CFDataRef CFCData::Serialize(CFPropertyListRef plist,
44 CFPropertyListFormat format) {
45 CFAllocatorRef alloc = kCFAllocatorDefault;
46 reset();
48 ::CFWriteStreamCreateWithAllocatedBuffers(alloc, alloc));
49 ::CFWriteStreamOpen(stream.get());
50 CFIndex len = ::CFPropertyListWrite(plist, stream.get(), format, 0, nullptr);
51 if (len > 0)
52 reset((CFDataRef)::CFWriteStreamCopyProperty(stream.get(),
53 kCFStreamPropertyDataWritten));
54 ::CFWriteStreamClose(stream.get());
55 return get();
56}
CFCData(CFDataRef data=NULL)
Definition: CFCData.cpp:12
const uint8_t * GetBytePtr() const
Definition: CFCData.cpp:36
CFIndex GetLength() const
Definition: CFCData.cpp:29
~CFCData() override
CFDataRef Serialize(CFPropertyListRef plist, CFPropertyListFormat format)
Definition: CFCData.cpp:43
CFCData & operator=(const CFCData &rhs)
Definition: CFCData.cpp:18
void reset(CFDataRef ptr=NULL)
Definition: CFCReleaser.h:86