Typed property handle
So far, generic database access has been discussed. In contrast to generic property handles, typed property handles provide direct access to instance data in the context of a C++ class definition. Typed property handles are supported via template classes. Instead of referring to the selected instance in the property node, the application may directly refer to instance properties returned by the SET template class.
SET< Person > persons(...); // create typed property handle
persons.count(); // call property handle functions
persons->name; // refer to person member
persons.iPtr()->name; // same as above
persons->UpdateAge(); // calling Person class member function
The -> operator causes calling the generic template class function iPtr() , which returns a typed pointer to the selected instance (in the example above to Person * .
When using typed property handles, the system will not be informed about instance modifications and the application program has to signal updates explicitly. Moreover, no data conversion will be performed and has to be managed by the application program as well.
Another disadvantage is, that one must not define virtual functions for types used in typed property handles, since the ODABA instance factory does not create virtual function vectors.
Hence, we suggest always using generic property handles rather than typed property handles.
// using typed Property Handles
SET<Person> persons(os, "Person::Persons", PI_Write");
while ( persons.Next() )
if ( persons->UpdateAge() ) // calling Person member function
persons.Modify(); // calling property handle function
// Update function as implemented in the Person Class
bool Person::UpdateAge() {
int old_age;
dbdt current;
current.SetDate();
age = birth_date.Year() - current_year;
return ( age != old_age);
}
// using generic property handles with update control
Property persons(os, "Person", PI_Write");
Property birth_date(&persons, "birth_date");
Property age(&persons, "age");
Date current;
int year = current.setDate().Year();
while ( persons.Next() )
age = year - birth_date.GetDate().Year();
If you find an urgent need for using typed property handles including virtual function support, we will provide this shortly.