1 //--------------------------------------------------------------------------
2 // Name:        src/arrayholder.h
3 // Purpose:     A simple template class that can hold and delete a pointer
4 //              to a C array
5 //
6 // Author:      Robin Dunn
7 //
8 // Created:     20-Oct-2011
9 // Copyright:   (c) 2011-2018 by Total Control Software
10 // Licence:     wxWindows license
11 //--------------------------------------------------------------------------
12 
13 #ifndef ARRAYHOLDER_H
14 #define ARRAYHOLDER_H
15 // Sometimes we need to hold on to a C array and keep it alive, but typical
16 // SIP code will treat it as a temporary and delete it as soon as the ctor or
17 // method call is done. This class can hold a pointer to the array and will
18 // delete the array in its dtor, and by making this class be wrappable we can
19 // make a PyObject for it that is then owned by some other object, and
20 // Python's GC will take care of the delaying the cleanup until it's no longer
21 // needed.
22 
23 template <class T>
24 class wxCArrayHolder
25 {
26 public:
wxCArrayHolder()27     wxCArrayHolder() : m_array(NULL) {}
~wxCArrayHolder()28     ~wxCArrayHolder() {
29         delete [] m_array;
30         m_array = NULL;
31     }
32     T* m_array;
33 };
34 
35 typedef wxCArrayHolder<int>      wxIntCArrayHolder;
36 typedef wxCArrayHolder<wxString> wxStringCArrayHolder;
37 typedef wxCArrayHolder<wxDash>   wxDashCArrayHolder;
38 
39 #endif
40 //--------------------------------------------------------------------------
41