64
if (propInfo->isPropName("seed")) {
setSeed(propInfo->getPropAsINT32());
} else if (propInfo->isPropName("total.rows")) {
setTotalRows(propInfo->getPropAsINT64());
} else {
CNKProc::setProperty(propInfo);
}
}
This code checks the property name against each of the accepted
string values, extracts the argument value as the appropriate type, and
calls an object method to set the appropriate property. If none of the
property names match, the superclass method is called to handle any
other property names.
getProperty is implemented in much the
same way:
void CNKProcRandomReader::getProperty(
CNKPropertyInfo* propInfo) {
if (propInfo->isPropName("seed")) {
propInfo->setPropAsINT32(getSeed());
} else if (propInfo->isPropName("total.rows")) {
propInfo->setPropAsINT64(getTotalRows());
} else {
CNKProc::getProperty(propInfo);
}
}
This code calls an object method to get the appropriate value, and
calls
propInfo->setPropAsXXX to set the first argument appropriately.
As with
setProperty, if none of the property names match, the
superclass method is called to handle any other property names.
One downside of the
setProperty/getProperty scheme for passing
information between Java and C++ is that the Java code needs to use
the same property names as the C++ methods (like
"total.rows" in
the example above). Maintaining consistency between the C++
property names and the ones used by the Java functions is a possible
source of error. Strictly speaking, the documentation of a subclass of
CNKObj should include documentation for the property names that it
can interpret via
get/setProperty.
Comentarios a estos manuales