You must make a class complex-persistent if it contains
complex functionality.
To make a class complex-persistent and usable within InfoSphere® DataStage® and QualityStage®, follow these rules:
- Your class must publicly inherit from APT_Persistent, directly
or indirectly.
- Concrete classes must use the APT_DECLARE_PERSISTENT macro in
the .h file and the APT_IMPLEMENT_PERSISTENT macro in the .C file.
Similarly, abstract classes must use the APT_DECLARE_ABSTRACT_PERSISTENT
macro in the .h file and the APT_IMPLEMENT_ABSTRACT_PERSISTENT macro
in the .C file. These macros generate operator>>, operator<<,
and operator|| overloads automatically to support serialization.
- You must create a default constructor. The default constructor
need not be public; it can be protected or private. A compiler-generated
default constructor is acceptable.
- You must implement APT_Persistent::serialize() in all derivations,
regardless of whether the derived class is concrete or abstract. The
APT_DECLARE_PERSISTENT macro includes a declaration for APT_Persistent::serialize()
in the .h file. APT_Persistent::serialize() is the only function that
you must define to support persistence in a derived class. All three
serialization operators are declared and defined by macros in terms
of APT_Persistent::serialize().
- You must provide Run-Time Type Information (RTTI) support on the
derived class. RTTI currently is not supported for template classes.
The following example shows how to apply the rules to make your
class complex-persistent:
In a file named ComplexPersistentClass.h, you define a complex
persistent class named
ComplexPersistentClass.
#include <apt_framework/orchestrate.h>
class ComplexPersistentClass: public APT_Persistent // Rule 1
{
APT_DECLARE_PERSISTENT(ComplexPersistentClass);// Rules 2 & 4
APT_DECLARE_RTTI(ComplexPersistentClass); // Rule 5
public:
ComplexPersistentClass(int, float);
private:
ComplexPersistentClass(); // Rule 3
int i_;
float f_;
};
In the file ComplexPersistentClass.C, the class is implemented
as follows:
#include "ComplexPersistentClass.h"
APT_IMPLEMENT_PERSISTENT(ComplexPersistentClass); // Rule 2
APT_IMPLEMENT_RTTI_ONEBASE(ComplexPersistentClass, // Rule 5
APT_Persistent);
ComplexPersistentClass::ComplexPersistentClass() // Rule 3
: i_(0), f_(0.0) {}
CompexPersistentClass::ComplexPersistentClass(int i, float f)
: i_(i), f_(f) {}
void Complex PersistentClass::serialize(APT_Archive& archive,
APT_UInt8) // Rule 4
{
archive || i_;
archive || f_;
}
The definition of APT_Persistent::serialize() uses the
built-in forms of APT_Archive::operator|| to implement persistence
for ComplexPersistentClass.