~wxClassInfo();
- wxObject *CreateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
+ wxObject *CreateObject() const
+ { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
bool IsDynamic() const { return (NULL != m_objectConstructor); }
const wxChar *GetClassName() const { return m_className; }
const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; }
int GetSize() const { return m_objectSize; }
- wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
+ wxObjectConstructorFn GetConstructor() const
+ { return m_objectConstructor; }
static const wxClassInfo *GetFirst() { return sm_first; }
const wxClassInfo *GetNext() const { return m_next; }
static wxClassInfo *FindClass(const wxChar *className);
( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
}
-#if WXWIN_COMPATIBILITY_2_4
- // Initializes parent pointers and hash table for fast searching.
- wxDEPRECATED( static void InitializeClasses() );
- // Cleans up hash table used for fast searching.
- wxDEPRECATED( static void CleanUpClasses() );
-#endif
-
public:
const wxChar *m_className;
int m_objectSize;
WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
-#if WXWIN_COMPATIBILITY_2_4
-inline void wxClassInfo::InitializeClasses() {}
-inline void wxClassInfo::CleanUpClasses() {}
-#endif
-
// ----------------------------------------------------------------------------
// Dynamic class macros
// ----------------------------------------------------------------------------
#define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
#endif
-// Only VC++ 6.0 and CodeWarrior compilers get overloaded delete that matches new
-#if ( defined(__VISUALC__) && (__VISUALC__ >= 1200) ) || (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
+// Only VC++ 6 and CodeWarrior get overloaded delete that matches new
+#if (defined(__VISUALC__) && (__VISUALC__ >= 1200)) || \
+ (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
#define _WX_WANT_DELETE_VOID_WXCHAR_INT
#endif
public:
wxObjectRefData() : m_count(1) { }
- virtual ~wxObjectRefData() { }
int GetRefCount() const { return m_count; }
+ void IncRef() { m_count++; }
+ void DecRef();
+
+protected:
+ // this object should never be destroyed directly but only as a
+ // result of a DecRef() call:
+ virtual ~wxObjectRefData() { }
+
private:
+ // our refcount:
int m_count;
};
+// ----------------------------------------------------------------------------
+// wxObjectDataPtr: helper class to avoid memleaks because of missing calls
+// to wxObjectRefData::DecRef
+// ----------------------------------------------------------------------------
+
+template <class T>
+class wxObjectDataPtr
+{
+public:
+ typedef T element_type;
+
+ wxEXPLICIT wxObjectDataPtr(T *ptr = NULL) : m_ptr(ptr) {}
+
+ // copy ctor
+ wxObjectDataPtr(const wxObjectDataPtr<T> &tocopy)
+ : m_ptr(tocopy.m_ptr)
+ {
+ if (m_ptr)
+ m_ptr->IncRef();
+ }
+
+ ~wxObjectDataPtr()
+ {
+ if (m_ptr)
+ m_ptr->DecRef();
+ }
+
+ T *get() const { return m_ptr; }
+ T *operator->() const { return get(); }
+
+ void reset(T *ptr)
+ {
+ if (m_ptr)
+ m_ptr->DecRef();
+ m_ptr = ptr;
+ }
+
+ wxObjectDataPtr& operator=(const wxObjectDataPtr &tocopy)
+ {
+ if (m_ptr)
+ m_ptr->DecRef();
+ m_ptr = tocopy.m_ptr;
+ if (m_ptr)
+ m_ptr->IncRef();
+ return *this;
+ }
+
+ wxObjectDataPtr& operator=(T *ptr)
+ {
+ if (m_ptr)
+ m_ptr->DecRef();
+ m_ptr = ptr;
+ if (m_ptr)
+ m_ptr->IncRef();
+ return *this;
+ }
+
+private:
+ T *m_ptr;
+};
+
// ----------------------------------------------------------------------------
// wxObject: the root class of wxWidgets object hierarchy
// ----------------------------------------------------------------------------
// Make sure this object has only one reference
void UnShare() { AllocExclusive(); }
+ // check if this object references the same data as the other one
+ bool IsSameAs(const wxObject& o) const { return m_refData == o.m_refData; }
+
protected:
// ensure that our data is not shared with anybody else: if we have no
// data, it is created using CreateRefData() below, if we have shared data
// it is copied using CloneRefData(), otherwise nothing is done
void AllocExclusive();
- // both methods must be implemented if AllocExclusive() is used, not pure virtual
- // only because of the backwards compatibility reasons
+ // both methods must be implemented if AllocExclusive() is used, not pure
+ // virtual only because of the backwards compatibility reasons
// create a new m_refData
virtual wxObjectRefData *CreateRefData() const;
#ifdef _MSC_VER
return (wxClassInfo*) m_classInfo;
#else
- return wx_const_cast(wxClassInfo *, m_classInfo);
+ wxDynamicClassInfo *nonconst = wx_const_cast(wxDynamicClassInfo *, m_classInfo);
+ return wx_static_cast(wxClassInfo *, nonconst);
#endif
}