The root of the SW system is sobject, as its name implies, an abstraction of objects in the universal sense. Its main support is as follows:
Run time class information (RuntimeClass)
Runtime class information is an extremely important part of classical program structure. MFC, VCL, OWL, and turbovision all support run-time-time class information. It is probably the only thing in the Classic object class that is more practical. It is also the most confusing place for the object class. To put it simply, runtime-type information has two main uses:
A) Creating objects
b) Determine the type of object
In fact, the implementation mechanism of RuntimeClass is not mysterious. It is simply through class registration to associate the class name with its parent class, instance creation function.
SW System Running time class information is defined as:
typedef SObject * (*FNBUILDER)();
struct SRuntimeClass
{
LPCTSTR m_lpszClassName;// 类名
SRuntimeClass * m_lpBaseClass;// 父类
FNBUILDER m_fnCreator;// 实例创建
SRuntimeClass *m_lpPrevClass;
};
Each of the SW system's classes should have a Sruntimeclass instance to describe the class. You can use __typeid (class) to locate the RuntimeClass information for this class. This macro is exactly the same as the MFC Runtime_class (CLASS) macro.
Note that Sruntimeclass has a member M_lpprevclass, which is only used to maintain runtimeclass linked lists in the system. This allows the user to query the Run-time class information of a class by the name of the class, and to create an object of that class. For example, the following serialization techniques need to do this.