| Xavax C++ Library | Class Index FAQ Overview |
| Constructor Summary |
Object()
Construct an object of class Object.
|
| Method Summary | |
T*
|
cast<T>()
Determine if a pointer to this object can be safely cast as a pointer to type T*. |
const T*
|
cast<T>() const
Determine if a pointer to a const object can be safely cast as a pointer to type const T*. |
const Class*
|
classRecord() const
Return the class record for this object. |
const Class*
|
ClassRecord()
Return the class record for class Object. |
Object*
|
clone() const
Return a new copy of this object. |
Object*
|
create()
Create an object of this class. |
long
|
hashCode()
Return a hash value for this object. |
| Macro Summary | |
CxDefineClass(name, parent,
creator)Define the class record for a class deriving from Object.
|
|
CxDefineClassNM(name, parent,
creator)Define the class record for a class with no data members deriving from Object.
|
|
CxDefineTemplateClass(name, parent,
creator)Define the class record for a template class deriving from Object.
|
|
CxDefineTemplateClassNM(name, parent,
creator)Define the class record for a template class with no data members deriving from Object.
|
|
CxStandardMethods(name)Declares the virtual and static methods and static data required by a class deriving from Object.
|
|
| Related Classes | |
| Class | |
| Constructor Detail |
Object()
| Method Detail |
T* cast<T>()
T*.
If this is a member of the specified
class or a derived class, return this
cast as T*; otherwise, return null.
T must be a class derived from Object
and must implement the ClassRecord method.
this cast as T* if the cast is valid;
otherwise, returns null.
const T* cast() const
const T*.
If this is a member of the specified
class or a derived class, return this
cast as const T*; otherwise, return null.
T must be a class derived from Object
and must implement the ClassRecord method.
this cast as const T*
if the cast is valid; otherwise, returns null.
const Class* classRecord() const
static const Class* ClassRecord()
Object* clone() const
Object* create()
Class::create
method to function.
A pointer to this static method should be passed to the
Class
constructor when the class record is initialized.
long hashCode() const
this
cast as a long.
| Macro Detail |
CxDefineClass(name, parent)
Class object)
for a class deriving from Object and implements the
classRecord and
ClassRecord methods.
This macro assumes the existance of a static array
of member descriptors named _members.
This macro is typically used near the beginning
of the implementation file.
name - the class name.parent - the parent class name.CxDefineClassNM(name, parent)
Class object)
for a class with no members
deriving from Object and implements the
classRecord and
ClassRecord methods.
This macro is typically used near the beginning
of the implementation file.
name - the class name.parent - the parent class name.CxDefineTemplateClass(name, parent, creator)
Class object)
for a template class deriving from Object
and implements the
classRecord and
ClassRecord methods.
This macro assumes the existance of a static array
of member descriptors named _members.
This macro is typically used near the beginning
of the implementation file.
name - the class name.parent - the parent class name.creator - static function to create an object.CxDefineTemplateClassNM(name, parent, creator)
Class object)
for a class with no members
deriving from Object and implements the
classRecord and
ClassRecord methods.
This macro is typically used near the beginning
of the implementation file.
name - the class name.parent - the parent class name.creator - static function to create an object.CxStandardMethods(name)
Object.
This macro should be the last line
within the definition of a class.
name - the class name.
| Example Code |
#include Headers_h
#include Headers_h
#include Cx_h
#include Object_h
#include <iostream.h>
//
// Define classes with the following inheritance tree
// to use for testing the cast methods.
//
// Object
// |
// +------+------+
// | |
// Gadget Widget
// |
// Scrollbar
//
class Widget : public Object {
public:
Widget() {};
~Widget() {};
CxStandardMethods(Widget);
};
CxDefineClassNM(Widget, Object);
class Gadget : public Object {
public:
Gadget() {};
~Gadget() {};
CxStandardMethods(Gadget);
};
CxDefineClassNM(Gadget, Object);
class Scrollbar : public Widget {
public:
Scrollbar() {};
~Scrollbar() {};
CxStandardMethods(Scrollbar);
};
CxDefineClassNM(Scrollbar, Widget);
//
// Test the cast method. Casting up the inheritance tree
// (from Widget to Object) should pass. Casting down
// the tree (from Widget to Scrollbar) or sideways (from
// Widget to Gadget) should fail.
//
void test1()
{
CxTraceEnter("test1");
Widget* wp = new Widget();
Gadget* p1 = wp->cast<Gadget>();
cout << "cast Widget to Gadget "
<< (p1 ? "passed" : "failed") << endl;
Object* p2 = wp->cast<Object>();
cout << "cast Widget to Object "
<< (p2 ? "passed" : "failed") << endl;
Widget* p3 = wp->cast<Widget>();
cout << "cast Widget to Widget "
<< (p3 ? "passed" : "failed") << endl;
Scrollbar* p4 = wp->cast<Scrollbar>();
cout << "cast Widget to Scrollbar "
<< (p4 ? "passed" : "failed") << endl;
CxTraceReturn;
}
//
// Test the const cast method.
//
void test2()
{
CxTraceEnter("test2");
const Widget* wp = new Widget();
const Gadget* p1 = wp->cast<Gadget>();
cout << "cast const Widget to const Gadget "
<< (p1 ? "passed" : "failed") << endl;
const Object* p2 = wp->cast<Object>();
cout << "cast const Widget to const Object "
<< (p2 ? "passed" : "failed") << endl;
const Widget* p3 = wp->cast<Widget>();
cout << "cast const Widget to const Widget "
<< (p3 ? "passed" : "failed") << endl;
const Scrollbar* p4 = wp->cast<Scrollbar>();
cout << "cast const Widget to const Scrollbar "
<< (p4 ? "passed" : "failed") << endl;
CxTraceReturn;
}
main(int argc, char **argv)
{
CxTraceEnter("main");
test1();
test2();
CxTraceReturn EXIT_SUCCESS;
}
Copyright © 2003 Xavax Inc. -- All Rights Reserved