Sometimes it is possible and beneficial from a performance standpoint to access object fields in a more standard С++ fashion, using setters and getters as opposed to the generated wrapper methods which call the underlying C API
classname_fieldname_put()
andclassname_fieldname_get()
functions. These setters and getters make database fields appear effectively as classproperties
. For example, instead using generated methods like:anObject.aField_get(&value)); anObject.aField_put(1));the
mcocomp
option–smartptr
can be used to generate "smart pointers" that allow the aboveclassname_fieldname_get()
andclassname_fieldname_put()
operation to be written as:value = anObject.aField; anObject.aField = 1;In order to use smart pointer access, simply specify the
-smartptr
option as follows:../../host/bin/mcocomp -hpp -smartptr schema.mcoThe sample
samples/native/core/20-languages/cpp/smartptr
demonstrates the use of smart pointers using the same database as the previous step. Note how the functionpopulate_db()
differs from thecppdemo
sample.