]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/scpdarry.tex
set up scrollbars correctly when we don't need them (fixes the problems reported...
[wxWidgets.git] / docs / latex / wx / scpdarry.tex
CommitLineData
762e1997 1\section{\class{wxScopedArray}}\label{wxscopedarray}
5b222f1c
JS
2
3This is a simple scoped smart pointer array implementation that is similar to
4the \urlref{Boost}{http://www.boost.org} smart pointers but rewritten to
5use macros instead.
6
7\wxheading{Example}
8
fc2171bd 9Below is an example of using a wxWidgets scoped smart pointer and
5b222f1c
JS
10pointer array.
11
12\begin{verbatim}
13 class MyClass { /* ... */ };
14
15 // declare a smart pointer to a MyClass called wxMyClassPtr
16 wxDECLARE_SCOPED_PTR(MyClass, wxMyClassPtr)
17 // declare a smart pointer to an array of chars
18 wxDECLARE_SCOPED_ARRAY(char, wxCharArray)
19
20 ...
21
22 // define the first pointer class, must be complete
23 wxDEFINE_SCOPED_PTR(MyClass, wxMyClassPtr)
24 // define the second pointer class
25 wxDEFINE_SCOPED_ARRAY(char, wxCharArray)
26
27 // create an object with a new pointer to MyClass
28 wxMyClassPtr theObj(new MyClass());
29 // reset the pointer (deletes the previous one)
30 theObj.reset(new MyClass());
31
32 // access the pointer
33 theObj->MyFunc();
34
35 // create an object with a new array of chars
36 wxCharArray theCharObj(new char[100]);
37
38 // access the array
39 theCharObj[0] = "!";
40\end{verbatim}
41
42\wxheading{Declaring new smart pointer types}
43
44\begin{verbatim}
45 wxDECLAR_SCOPED_ARRAY( TYPE, // type of the values
46 CLASSNAME ); // name of the class
47\end{verbatim}
48
49A smart pointer holds a pointer to an object (which must be complete
2b5f62a0 50when wxDEFINE\_SCOPED\_ARRAY() is called). The memory used by the object is
5b222f1c
JS
51deleted when the smart pointer goes out of scope. The first argument
52of the macro is the pointer type, the second is the name of the new
53smart pointer class being created. Below we will use wxScopedArray to
54represent the scoped pointer array class, but the user may create the class
55with any legal name.
56
57\wxheading{Include files}
58
59<wx/ptr\_scpd.h>
60
61\wxheading{See also}
62
63\helpref{wxScopedPtr}{wxscopedptr}\rtfsp
64
65\latexignore{\rtfignore{\wxheading{Members}}}
66
39275175 67\membersection{wxScopedArray::wxScopedArray}\label{wxscopedarrayctor}
5b222f1c
JS
68
69\func{}{wxScopedArray}{\param{type}{ * T = NULL}}
70
71Creates the smart pointer with the given pointer or none if NULL. On
72compilers that support it, this uses the explicit keyword.
73
39275175 74\membersection{wxScopedArray::reset}\label{wxscopedarrayreset}
5b222f1c
JS
75
76\func{\void}{reset}{\param{T}{ p * = NULL}}
77
78Deletes the currently held pointer and sets it to 'p' or to NULL if no
79arguments are specified. This function does check to make sure that the
80pointer you are assigning is not the same pointer that is already stored.
81
39275175 82\membersection{wxScopedArray::operator []}\label{wxscopedarraybracket}
5b222f1c
JS
83
84\func{const T \&}{operator []}{\param{long int}{i}}
85
86This operator acts like the standard [] indexing operator for C++ arrays. The
87function does not do bounds checking.
88
39275175 89\membersection{wxScopedArray::get}\label{wxscopedarrayget}
5b222f1c
JS
90
91\func{const T*}{get}{\void}
92
93This operator gets the pointer stored in the smart pointer or returns NULL if
94there is none.
95
39275175 96\membersection{wxScopedArray::swap}\label{wxscopedarrayswap}
5b222f1c
JS
97
98\func{\void}{swap}{\param{wxScopedPtr}{ \& ot}}
99
100Swap the pointer inside the smart pointer with 'ot'. The pointer being swapped
101must be of the same type (hence the same class name).
102