File: cfdataref.h

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (96 lines) | stat: -rw-r--r-- 3,404 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/osx/core/cfdataref.h
// Purpose:     wxCFDataRef class
// Author:      Stefan Csomor
// Modified by:
// Created:     2007/05/10
// Copyright:   (c) 2007 Stefan Csomor
// Licence:     wxWindows licence
// Notes:       See http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBinaryData/index.html
/////////////////////////////////////////////////////////////////////////////
/*! @header     wx/osx/core/cfdataref.h
    @abstract   wxCFDataRef template class
*/

#ifndef _WX_MAC_COREFOUNDATION_CFDATAREF_H__
#define _WX_MAC_COREFOUNDATION_CFDATAREF_H__

#include "wx/osx/core/cfref.h"

#include <CoreFoundation/CFData.h>

/*! @class wxCFDataRef
    @discussion Properly retains/releases reference to CoreFoundation data objects
*/
class wxCFDataRef : public wxCFRef< CFDataRef >
{
public:
    /*! @method     wxCFDataRef
        @abstract   Creates a NULL data ref
    */
    wxCFDataRef()
    {}

    typedef wxCFRef<CFDataRef> super_type;

    /*! @method     wxCFDataRef
        @abstract   Assumes ownership of p and creates a reference to it.
        @templatefield otherType    Any type.
        @param p        The raw pointer to assume ownership of.  May be NULL.
        @discussion Like shared_ptr, it is assumed that the caller has a strong reference to p and intends
                    to transfer ownership of that reference to this ref holder.  If the object comes from
                    a Create or Copy method then this is the correct behaviour.  If the object comes from
                    a Get method then you must CFRetain it yourself before passing it to this constructor.
                    A handy way to do this is to use the non-member wxCFRefFromGet factory funcion.
                    This method is templated and takes an otherType *p.  This prevents implicit conversion
                    using an operator refType() in a different ref-holding class type.
    */
    explicit wxCFDataRef(CFDataRef r)
    :   super_type(r)
    {}

    /*! @method     wxCFDataRef
        @abstract   Copies a ref holder of the same type
        @param otherRef The other ref holder to copy.
        @discussion Ownership will be shared by the original ref and the newly created ref. That is,
                    the object will be explicitly retained by this new ref.
    */
    wxCFDataRef(const wxCFDataRef& otherRef)
    :  super_type( otherRef )
    {}

    /*! @method     wxCFDataRef
        @abstract   Copies raw data into a data ref
        @param data The raw data.
        @param length The data length.
    */
    wxCFDataRef(const UInt8* data, CFIndex length)
    : super_type(CFDataCreate(kCFAllocatorDefault, data, length))
    {
    }

    /*! @method     GetLength
        @abstract   returns the length in bytes of the data stored
    */
    CFIndex GetLength() const
    {
        if ( m_ptr )
            return CFDataGetLength( *this );
        else
            return 0;
    }

    /*! @method     GetBytes
        @abstract   Copies the data into an external buffer
        @param range The desired range.
        @param buffer The target buffer.
    */
    void GetBytes( CFRange range, UInt8 *buffer ) const
    {
        if ( m_ptr )
            CFDataGetBytes(m_ptr, range, buffer);
    }
};

#endif //ifndef _WX_MAC_COREFOUNDATION_CFDATAREF_H__