X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c801d85f158c4cba50b588807daabdcbd0ed3853..3f659fd6b10a8a5c899eaa99adc76a55322b33fd:/src/common/object.cpp diff --git a/src/common/object.cpp b/src/common/object.cpp index 4dc8b093b3..8cbdcef7c4 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -20,23 +20,30 @@ #pragma hdrstop #endif +#ifndef WX_PRECOMP #include "wx/hash.h" +#ifdef USE_SERIAL +#include "wx/objstrm.h" +#include "wx/serbase.h" +#endif +#endif #include #include -#if (DEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT +#if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT #include "wx/memory.h" #endif -#if DEBUG || USE_DEBUG_CONTEXT +#if WXDEBUG || USE_DEBUG_CONTEXT // for wxObject::Dump #include #endif #if !USE_SHARED_LIBRARY -wxClassInfo wxObject::classwxObject("wxObject", NULL, NULL, sizeof(wxObject), NULL); -wxClassInfo *wxClassInfo::first = NULL; +wxClassInfo wxObject::classwxObject((char *) "wxObject", (char *) NULL, (char *) NULL, (int ) sizeof(wxObject), (wxObjectConstructorFn) NULL); +wxClassInfo *wxClassInfo::first = (wxClassInfo *) NULL; +wxHashTable wxClassInfo::classTable(wxKEY_STRING); #endif /* @@ -45,12 +52,19 @@ wxClassInfo *wxClassInfo::first = NULL; wxObject::wxObject(void) { - m_refData = NULL; + m_refData = (wxObjectRefData *) NULL; +#ifdef USE_SERIAL + m_serialObj = (wxObject_Serialize *)NULL; +#endif } wxObject::~wxObject(void) { UnRef(); +#ifdef USE_SERIAL + if (m_serialObj) + delete m_serialObj; +#endif } /* @@ -69,7 +83,7 @@ bool wxObject::IsKindOf(wxClassInfo *info) return FALSE; } -#if DEBUG || USE_DEBUG_CONTEXT +#if WXDEBUG || USE_DEBUG_CONTEXT void wxObject::Dump(ostream& str) { if (GetClassInfo() && GetClassInfo()->GetClassName()) @@ -79,7 +93,7 @@ void wxObject::Dump(ostream& str) } #endif -#if DEBUG && USE_MEMORY_TRACING +#if WXDEBUG && USE_MEMORY_TRACING #ifdef new #undef new @@ -114,36 +128,6 @@ void wxObject::operator delete[] (void * buf) * Class info: provides run-time class type information. */ -#ifdef USE_STORABLE_CLASSES - -wxClassInfo::wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn, - wxStorableConstructorFn stoFn ) -{ - className = cName; - baseClassName1 = baseName1; - baseClassName2 = baseName2; - - objectSize = sz; - objectConstructor = fn; - storableConstructor = stoFn; - - next = first; - first = this; - - baseInfo1 = NULL; - baseInfo2 = NULL; -} - -wxObject* wxClassInfo::CreateObject( istream &stream, char *data ) -{ - if (storableConstructor) - return (wxObject *)(*storableConstructor)( stream, data ); - else - return NULL; -} - -#else - wxClassInfo::wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn constr) { className = cName; @@ -156,18 +140,16 @@ wxClassInfo::wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, next = first; first = this; - baseInfo1 = NULL; - baseInfo2 = NULL; + baseInfo1 = (wxClassInfo *) NULL; + baseInfo2 = (wxClassInfo *) NULL; } -#endif - wxObject *wxClassInfo::CreateObject(void) { if (objectConstructor) return (wxObject *)(*objectConstructor)(); else - return NULL; + return (wxObject *) NULL; } wxClassInfo *wxClassInfo::FindClass(char *c) @@ -179,7 +161,7 @@ wxClassInfo *wxClassInfo::FindClass(char *c) return p; p = p->next; } - return NULL; + return (wxClassInfo *) NULL; } // Climb upwards through inheritance hierarchy. @@ -213,14 +195,12 @@ bool wxClassInfo::IsKindOf(wxClassInfo *info) // Set pointers to base class(es) to speed up IsKindOf void wxClassInfo::InitializeClasses(void) { - wxHashTable table(wxKEY_STRING); - // Index all class infos by their class name wxClassInfo *info = first; while (info) { if (info->className) - table.Put(info->className, (wxObject *)info); + classTable.Put(info->className, (wxObject *)info); info = info->next; } @@ -229,39 +209,87 @@ void wxClassInfo::InitializeClasses(void) while (info) { if (info->GetBaseClassName1()) - info->baseInfo1 = (wxClassInfo *)table.Get(info->GetBaseClassName1()); + info->baseInfo1 = (wxClassInfo *)classTable.Get(info->GetBaseClassName1()); if (info->GetBaseClassName2()) - info->baseInfo2 = (wxClassInfo *)table.Get(info->GetBaseClassName2()); + info->baseInfo2 = (wxClassInfo *)classTable.Get(info->GetBaseClassName2()); info = info->next; } + first = NULL; } wxObject *wxCreateDynamicObject(char *name) { - wxClassInfo *info = wxClassInfo::first; - while (info) - { - if (info->className && strcmp(info->className, name) == 0) - return info->CreateObject(); - info = info->next; - } - return NULL; + wxClassInfo *info; + + info = (wxClassInfo *)wxClassInfo::classTable.Get(name); + if (!info) + return (wxObject *)NULL; + + return info->CreateObject(); } -#ifdef USE_STORABLE_CLASSES +#ifdef USE_SERIAL + +#include "wx/serbase.h" +#include "wx/dynlib.h" +#include "wx/msgdlg.h" -wxObject* wxCreateStoredObject( char *name, istream &stream, char *data ) +wxObject* wxCreateStoredObject( wxInputStream &stream ) { - wxClassInfo *info = wxClassInfo::first; - while (info) - { - if (info->className && strcmp(info->className, name) == 0) - return info->CreateObject( stream, data ); - info = info->next; - } - return NULL; + wxObjectInputStream obj_s(stream); + return obj_s.LoadObject(); }; +void wxObject::StoreObject( wxObjectOutputStream& stream ) +{ + wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize"; + wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial"); + + if (!lib) { + wxMessageBox("Can't load wxSerial dynamic library.", "Alert !"); + return; + } + if (!m_serialObj) { + m_serialObj = (WXSERIAL(wxObject) *)lib->CreateObject( obj_name ); + + if (!m_serialObj) { + wxString message; + + message.Printf("Can't find the serialization object (%s) for the object %s", + WXSTRINGCAST obj_name, + WXSTRINGCAST GetClassInfo()->GetClassName()); + wxMessageBox(message, "Alert !"); + return; + } + m_serialObj->SetObject(this); + } + + m_serialObj->StoreObject(stream); +} + +void wxObject::LoadObject( wxObjectInputStream& stream ) +{ + wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize"; + wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial"); + + if (!m_serialObj) { + m_serialObj = (WXSERIAL(wxObject) *)lib->CreateObject( obj_name ); + + if (!m_serialObj) { + wxString message; + + message.Printf("Can't find the serialization object (%s) for the object %s", + WXSTRINGCAST obj_name, + WXSTRINGCAST GetClassInfo()->GetClassName()); + wxMessageBox(message, "Alert !"); + return; + } + m_serialObj->SetObject(this); + } + + m_serialObj->LoadObject(stream); +} + #endif /* @@ -287,7 +315,7 @@ void wxObject::UnRef(void) if (m_refData->m_count == 0) delete m_refData; } - m_refData = NULL; + m_refData = (wxObjectRefData *) NULL; } /*