1 \section{\class{wxObject
}}\label{wxobject
}
3 This is the root class of many of the wxWidgets classes.
4 It declares a virtual destructor which ensures that
5 destructors get called for all derived class objects where necessary.
7 wxObject is the hub of a dynamic object creation
8 scheme, enabling a program to create instances of a class only knowing
9 its string class name, and to query the class hierarchy.
11 The class contains optional debugging versions
12 of
{\bf new
} and
{\bf delete
}, which can help trace memory allocation
13 and deallocation problems.
15 wxObject can be used to implement
\helpref{reference counted
}{trefcount
} objects,
16 such as wxPen, wxBitmap and others (see
\helpref{this list
}{refcountlist
}).
20 \helpref{wxClassInfo
}{wxclassinfo
},
\helpref{Debugging overview
}{debuggingoverview
},
\rtfsp
21 \helpref{wxObjectRefData
}{wxobjectrefdata
}
23 \wxheading{Derived from
}
27 \wxheading{Include files
}
33 \helpref{wxBase
}{librarieslist
}
35 \latexignore{\rtfignore{\wxheading{Members
}}}
37 \membersection{wxObject::wxObject
}\label{wxobjectctor
}
39 \func{}{wxObject
}{\void}
41 \func{}{wxObject
}{\param{const wxObject\&
}{ other
}}
43 Default and copy constructors.
45 \membersection{wxObject::
\destruct{wxObject
}}\label{wxobjectdtor
}
47 \func{}{wxObject
}{\void}
49 Destructor. Performs dereferencing, for those objects
50 that use reference counting.
52 \membersection{wxObject::m
\_refData}\label{wxobjectmrefdata
}
54 \member{wxObjectRefData*
}{m
\_refData}
56 Pointer to an object which is the object's reference-counted data.
60 \helpref{wxObject::Ref
}{wxobjectref
},
\helpref{wxObject::UnRef
}{wxobjectunref
},
\rtfsp
61 \helpref{wxObject::SetRefData
}{wxobjectsetrefdata
},
\rtfsp
62 \helpref{wxObject::GetRefData
}{wxobjectgetrefdata
},
\rtfsp
63 \helpref{wxObjectRefData
}{wxobjectrefdata
}
65 \membersection{wxObject::Dump
}\label{wxobjectdump
}
67 \func{void
}{Dump
}{\param{ostream\&
}{ stream
}}
69 A virtual function that may be redefined by derived classes to allow dumping of
72 This function is only defined in debug build and doesn't exist at all if
73 {\tt \_\_WXDEBUG\_\_} is not defined.
75 \wxheading{Parameters
}
77 \docparam{stream
}{Stream on which to output dump information.
}
81 Currently wxWidgets does not define Dump for derived classes, but
82 programmers may wish to use it for their own applications. Be sure to
83 call the Dump member of the class's base class to allow all information to be
86 The implementation of this function in wxObject just writes the class name of
89 \membersection{wxObject::GetClassInfo
}\label{wxobjectgetclassinfo
}
91 \func{wxClassInfo *
}{GetClassInfo
}{\void}
93 This virtual function is redefined for every class that requires run-time
94 type information, when using DECLARE
\_CLASS macros.
96 \membersection{wxObject::GetRefData
}\label{wxobjectgetrefdata
}
98 \constfunc{wxObjectRefData*
}{GetRefData
}{\void}
100 Returns the
{\bf m
\_refData} pointer.
104 \helpref{wxObject::Ref
}{wxobjectref
},
\helpref{wxObject::UnRef
}{wxobjectunref
},
\helpref{wxObject::m
\_refData}{wxobjectmrefdata
},
\rtfsp
105 \helpref{wxObject::SetRefData
}{wxobjectsetrefdata
},
\rtfsp
106 \helpref{wxObjectRefData
}{wxobjectrefdata
}
108 \membersection{wxObject::IsKindOf
}\label{wxobjectiskindof
}
110 \func{bool
}{IsKindOf
}{\param{wxClassInfo *
}{info
}}
112 Determines whether this class is a subclass of (or the same class as)
115 \wxheading{Parameters
}
117 \docparam{info
}{A pointer to a class information object, which may be obtained
118 by using the CLASSINFO macro.
}
120 \wxheading{Return value
}
122 true if the class represented by
{\it info
} is the same class as
123 this one or is derived from it.
128 bool tmp = obj->IsKindOf(CLASSINFO(wxFrame));
131 \membersection{wxObject::IsSameAs
}\label{wxobjectissameas
}
133 \func{bool
}{IsSameAs
}{\param{const wxObject\&
}{ obj
}}
135 Returns
\true if this object has the same data pointer as
\arg{obj
}. Notice
136 that
\true is returned if the data pointers are
\NULL in both objects.
138 This function only does a
\emph{shallow
} comparison, i.e. it doesn't compare
139 the objects pointed to by the data pointers of these objects.
141 \membersection{wxObject::Ref
}\label{wxobjectref
}
143 \func{void
}{Ref
}{\param{const wxObject\&
}{clone
}}
145 Makes this object refer to the data in
{\it clone
}.
147 \wxheading{Parameters
}
149 \docparam{clone
}{The object to `clone'.
}
153 First this function calls
\helpref{wxObject::UnRef
}{wxobjectunref
} on itself
154 to decrement (and perhaps free) the data it is currently referring to.
156 It then sets its own m
\_refData to point to that of
{\it clone
}, and increments the reference count
161 \helpref{wxObject::UnRef
}{wxobjectunref
},
\helpref{wxObject::m
\_refData}{wxobjectmrefdata
},
\rtfsp
162 \helpref{wxObject::SetRefData
}{wxobjectsetrefdata
},
\helpref{wxObject::GetRefData
}{wxobjectgetrefdata
},
\rtfsp
163 \helpref{wxObjectRefData
}{wxobjectrefdata
}
165 \membersection{wxObject::SetRefData
}\label{wxobjectsetrefdata
}
167 \func{void
}{SetRefData
}{\param{wxObjectRefData*
}{ data
}}
169 Sets the
{\bf m
\_refData} pointer.
173 \helpref{wxObject::Ref
}{wxobjectref
},
\helpref{wxObject::UnRef
}{wxobjectunref
},
\helpref{wxObject::m
\_refData}{wxobjectmrefdata
},
\rtfsp
174 \helpref{wxObject::GetRefData
}{wxobjectgetrefdata
},
\rtfsp
175 \helpref{wxObjectRefData
}{wxobjectrefdata
}
177 \membersection{wxObject::UnRef
}\label{wxobjectunref
}
179 \func{void
}{UnRef
}{\void}
181 Decrements the reference count in the associated data, and if it is zero, deletes the data.
182 The
{\bf m
\_refData} member is set to NULL.
186 \helpref{wxObject::Ref
}{wxobjectref
},
\helpref{wxObject::m
\_refData}{wxobjectmrefdata
},
\rtfsp
187 \helpref{wxObject::SetRefData
}{wxobjectsetrefdata
},
\helpref{wxObject::GetRefData
}{wxobjectgetrefdata
},
\rtfsp
188 \helpref{wxObjectRefData
}{wxobjectrefdata
}
190 \membersection{wxObject::UnShare
}\label{wxobjectunshare
}
192 \func{void
}{UnShare
}{\void}
194 Ensure that this object's data is not shared with any other object.
197 data, it is created using CreateRefData() below, if we have shared data
198 it is copied using CloneRefData(), otherwise nothing is done.
201 \membersection{wxObject::operator new
}\label{wxobjectnew
}
203 \func{void *
}{new
}{\param{size
\_t }{size
},
\param{const wxString\&
}{filename = NULL
},
\param{int
}{ lineNum =
0}}
205 The
{\it new
} operator is defined for debugging versions of the library only, when
206 the identifier
\_\_WXDEBUG\_\_ is defined. It takes over memory allocation, allowing
207 wxDebugContext operations.
209 \membersection{wxObject::operator delete
}\label{wxobjectdelete
}
211 \func{void
}{delete
}{\param{void
}{buf
}}
213 The
{\it delete
} operator is defined for debugging versions of the library only, when
214 the identifier
\_\_WXDEBUG\_\_ is defined. It takes over memory deallocation, allowing
215 wxDebugContext operations.
221 \section{\class{wxObjectRefData
}}\label{wxobjectrefdata
}
223 This class is used to store reference-counted data. Derive classes from this to
224 store your own data. When retrieving information from a
{\bf wxObject
}'s reference data,
225 you will need to cast to your own derived class.
229 \helpref{wxObject
}{wxobject
}
233 \helpref{wxObject
}{wxobject
}
234 \helpref{wxObjectDataPtr<T>
}{wxobjectdataptr
}
235 \helpref{Reference counting
}{trefcount
}
237 \wxheading{Derived from
}
241 \wxheading{Include files
}
251 class MyCar: public wxObject
257 bool IsOk() const
{ return m_refData != NULL;
}
259 bool operator == ( const MyCar& car ) const;
260 bool operator != (const MyCar& car) const
{ return !
(*this == car); }
262 void SetPrice( int price );
263 int GetPrice() const;
266 virtual wxObjectRefData *CreateRefData() const;
267 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
269 DECLARE_DYNAMIC_CLASS(MyCar)
275 class MyCarRefData: public wxObjectRefData
283 MyCarRefData( const MyCarRefData& data )
286 m_price = data.m_price;
289 bool operator == (const MyCarRefData& data) const
291 return m_price == data.m_price;
298 #define M_CARDATA ((MyCarRefData *)m_refData)
300 IMPLEMENT_DYNAMIC_CLASS(MyCar,wxObject)
302 MyCar::MyCar( int price )
304 m_refData = new MyCarRefData();
305 M_CARDATA->m_price = price;
308 wxObjectRefData *MyCar::CreateRefData() const
310 return new MyCarRefData;
313 wxObjectRefData *MyCar::CloneRefData(const wxObjectRefData *data) const
315 return new MyCarRefData
(*(MyCarRefData *)data);
318 bool MyCar::operator == ( const MyCar& car ) const
320 if (m_refData == car.m_refData) return true;
322 if (!m_refData || !car.m_refData) return false;
324 return ( *(MyCarRefData*)m_refData == *(MyCarRefData*)car.m_refData );
327 void MyCar::SetPrice( int price )
331 M_CARDATA->m_price = price;
334 int MyCar::GetPrice() const
336 wxCHECK_MSG( IsOk(), -
1, "invalid car" );
338 return (M_CARDATA->m_price);
345 \helpref{wxBase
}{librarieslist
}
347 \latexignore{\rtfignore{\wxheading{Members
}}}
350 \membersection{wxObjectRefData::wxObjectRefData
}\label{wxobjectrefdatactor
}
352 \func{}{wxObjectRefData
}{\void}
354 Default constructor. Initialises the internal reference count to
1.
356 \membersection{wxObjectRefData::
\destruct{wxObjectRefData
}}\label{wxobjectrefdatadtor
}
358 \func{}{wxObjectRefData
}{\void}
360 Destructor. It's declared
{\tt protected
} so that wxObjectRefData instances will never
361 be destroyed directly but only as result of a
\helpref{DecRef
}{wxobjectrefdatadecref
} call.
363 \membersection{wxObjectRefData::GetRefCount
}\label{wxobjectrefdatagetrefcount
}
365 \constfunc{int
}{GetRefCount
}{\void}
367 Returns the reference count associated with this shared data.
368 When this goes to zero during a
\helpref{DecRef
}{wxobjectrefdatadecref
} call, the object
369 will auto-free itself.
371 \membersection{wxObjectRefData::DecRef
}\label{wxobjectrefdatadecref
}
373 \func{void
}{DecRef
}{\void}
375 Decrements the reference count associated with this shared data and, if it reaches zero,
376 destroys this instance of wxObjectRefData releasing its memory.
378 Please note that after calling this function, the caller should absolutely avoid to use
379 the pointer to this instance since it may not be valid anymore.
381 \membersection{wxObjectRefData::IncRef
}\label{wxobjectrefdataincref
}
383 \func{void
}{IncRef
}{\void}
385 Increments the reference count associated with this shared data.