CCRuntimeClass Class Reference

Provide run-time class information and dynamic class creation for objects derived from CCObject. More...

#include <ccobject.h>

List of all members.

Public Member Functions

 void (PASCAL *m_pfnConstruct)(void *p)
CCObjectCreateObject ()
 Dynamic creation of objects. This function should be used when you want to create an object and you do not know what type it should be until runtime. An example would be copying another object derived from CCObject.
BOOL ConstructObject (void *pThis)
 Dynamically construct an instance of this class in the memory pointed to by 'pThis'. Return FALSE if can't construct (i.e. an abstract class).
BOOL IsKindOf (const CCRuntimeClass *pClass) const
 This function will return TRUE if the object is of the same class as that specified by pClass, or if it is derived from the class specified by pClass.
LPCTSTR GetClassName () const
CCRuntimeClassGetBaseClass1 () const
INT32 GetSize () const

Public Attributes

LPCTSTR m_lpszClassName
INT32 m_nObjectSize
UINT32 m_wSchema
CCRuntimeClassm_pBaseClass
CCRuntimeClassm_pNextClass

Static Public Attributes

static CCRuntimeClasspFirstClass = NULL


Detailed Description

Provide run-time class information and dynamic class creation for objects derived from CCObject.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/7/93
See also:
CCObject

Definition at line 124 of file ccobject.h.


Member Function Documentation

BOOL CCRuntimeClass::ConstructObject void *  pThis  ) 
 

Dynamically construct an instance of this class in the memory pointed to by 'pThis'. Return FALSE if can't construct (i.e. an abstract class).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/7/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-
Do not call this function directly - use CreateObject() instead.

Returns:
Errors: -
See also:
CCObject::CreateObject

Definition at line 1039 of file ccobject.cpp.

01040 {
01041     // Make sure memory we've been given is not a brown cylindrical object.
01042     ENSURE( IsValidAddress(pThis, m_nObjectSize), 
01043             "CCRuntimeClass::ConstructObject: pThis pointer is invalid");
01044 
01045     // Try to create the object.
01046     if (m_pfnConstruct != NULL)
01047     {
01048         // It's not an abstract class, so call the constructor
01049         (*m_pfnConstruct)(pThis);
01050         return TRUE;
01051     }
01052     else
01053     {
01054         // Error - cannot construct an instance of an abstract class.
01055         TRACE( _T("Error: Trying to construct object of an abstract class %s.\n"),
01056             m_lpszClassName);
01057         return FALSE;
01058     }
01059 }

CCObject * CCRuntimeClass::CreateObject  ) 
 

Dynamic creation of objects. This function should be used when you want to create an object and you do not know what type it should be until runtime. An example would be copying another object derived from CCObject.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/7/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Pointer to a new object.
See CCObject and CCRuntimeClass for more details.

Returns:
Errors: -
See also:
CCObject; CCRuntimeClass; CC_RUNTIME_CLASS; CCObject::IsKindOf

Definition at line 994 of file ccobject.cpp.

00995 {
00996     void* pObject = NULL;
00997 
00998     // Allocate memory for the new object.
00999     pObject = CCObject::operator new(m_nObjectSize, THIS_FILE, __LINE__);
01000 
01001     // Attempt to construct it using dynamic creation facilities
01002     if ((pObject != NULL) && ConstructObject(pObject))
01003         // All ok - return pointer to new object
01004         return (CCObject*) pObject;
01005     else
01006     {
01007         // Something went wrong...
01008         TRACE0( wxT("Warning: CCRuntimeClass::CreateObject failed\n") );
01009         
01010         // Did the 'new' succeed? If so, deallocate the storage
01011         if (pObject != NULL)
01012             CCObject::operator delete(pObject);  // clean up
01013             
01014         // Object creation failed.
01015         return NULL;
01016     }
01017 }

CCRuntimeClass* CCRuntimeClass::GetBaseClass1  )  const [inline]
 

Definition at line 151 of file ccobject.h.

00151 {return m_pBaseClass;}

LPCTSTR CCRuntimeClass::GetClassName  )  const [inline]
 

Definition at line 150 of file ccobject.h.

00150 {return m_lpszClassName;}

INT32 CCRuntimeClass::GetSize  )  const [inline]
 

Definition at line 152 of file ccobject.h.

00152 {return m_nObjectSize;}

BOOL CCRuntimeClass::IsKindOf const CCRuntimeClass pClass  )  const
 

This function will return TRUE if the object is of the same class as that specified by pClass, or if it is derived from the class specified by pClass.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/7/93
Parameters:
pClass - pointer to the CCRuntimeClass object of the class to compare [INPUTS] against.
Returns:
TRUE if it is a kind of the specified class; FALSE if not.
See also:
CCObject::GetRuntimeClass; CC_RUNTIME_CLASS; CCObject

Definition at line 800 of file ccobject.cpp.

00801 {
00802     // Do some sanity checking
00803     ENSURE( this != NULL,
00804             "CCRuntimeClass::IsKindOf: Object pointer is null");
00805 
00806     // It had better be in valid memory, at least for CCObject size
00807     ENSURE( IsValidAddress(this, sizeof(CCRuntimeClass)),
00808             "CCRuntimeClass::IsKindOf: Object is in invalid memory area");
00809 
00810     // Get the runtime class information for this object
00811     register const CCRuntimeClass* pClassThis = this;
00812     
00813     // Sanity checks
00814     ENSURE( pClass != NULL, 
00815             "CCRuntimeClass::IsKindOf: pClass pointer is null");
00816     ENSURE(pClassThis != NULL, 
00817             "CCRuntimeClass::IsKindOf: pClassThis pointer is null");
00818     
00819     // Check for objects of the same class, or walk the base class chain until
00820     // it runs out, or we find a match.
00821     while (pClassThis != NULL)
00822     {
00823         if (pClassThis == pClass)
00824             return TRUE;
00825         pClassThis = pClassThis->m_pBaseClass;
00826     }
00827     
00828     // No match - these classes are not the same.
00829     return FALSE;
00830 }

CCRuntimeClass::void PASCAL *  m_pfnConstruct  ) 
 


Member Data Documentation

LPCTSTR CCRuntimeClass::m_lpszClassName
 

Definition at line 128 of file ccobject.h.

INT32 CCRuntimeClass::m_nObjectSize
 

Definition at line 131 of file ccobject.h.

CCRuntimeClass* CCRuntimeClass::m_pBaseClass
 

Definition at line 143 of file ccobject.h.

CCRuntimeClass* CCRuntimeClass::m_pNextClass
 

Definition at line 159 of file ccobject.h.

UINT32 CCRuntimeClass::m_wSchema
 

Definition at line 135 of file ccobject.h.

CCRuntimeClass * CCRuntimeClass::pFirstClass = NULL [static]
 

Definition at line 158 of file ccobject.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:52:12 2007 for Camelot by  doxygen 1.4.4