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