1 //===-- CFData.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 // Created by Greg Clayton on 1/16/08. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "CFData.h" 15 16 //---------------------------------------------------------------------- 17 // CFData constructor 18 //---------------------------------------------------------------------- 19 CFData::CFData(CFDataRef data) : 20 CFReleaser<CFDataRef>(data) 21 { 22 23 } 24 25 //---------------------------------------------------------------------- 26 // CFData copy constructor 27 //---------------------------------------------------------------------- 28 CFData::CFData(const CFData& rhs) : 29 CFReleaser<CFDataRef>(rhs) 30 { 31 32 } 33 34 //---------------------------------------------------------------------- 35 // CFData copy constructor 36 //---------------------------------------------------------------------- 37 CFData& 38 CFData::operator=(const CFData& rhs) 39 40 { 41 *this = rhs; 42 return *this; 43 } 44 45 //---------------------------------------------------------------------- 46 // Destructor 47 //---------------------------------------------------------------------- 48 CFData::~CFData() 49 { 50 } 51 52 53 CFIndex 54 CFData::GetLength() const 55 { 56 CFDataRef data = get(); 57 if (data) 58 return CFDataGetLength (data); 59 return 0; 60 } 61 62 63 const uint8_t* 64 CFData::GetBytePtr() const 65 { 66 CFDataRef data = get(); 67 if (data) 68 return CFDataGetBytePtr (data); 69 return NULL; 70 } 71 72 CFDataRef 73 CFData::Serialize(CFPropertyListRef plist, CFPropertyListFormat format) 74 { 75 CFAllocatorRef alloc = kCFAllocatorDefault; 76 reset(); 77 CFReleaser<CFWriteStreamRef> stream (::CFWriteStreamCreateWithAllocatedBuffers (alloc, alloc)); 78 ::CFWriteStreamOpen (stream.get()); 79 CFIndex len = ::CFPropertyListWriteToStream (plist, stream.get(), format, NULL); 80 if (len > 0) 81 reset((CFDataRef)::CFWriteStreamCopyProperty (stream.get(), kCFStreamPropertyDataWritten)); 82 ::CFWriteStreamClose (stream.get()); 83 return get(); 84 } 85 86