Any variables declared in the implementation source file will, by virtue of Babel's encapsulation, be private. The data can be global to the class -- as in static variables declared within the _includes splicer block at the top of the class's _Impl.cxx file -- or ``local'' to an instance. In the former case, special initialization procedures can be added to the built-in _load() method that is guaranteed to be called exactly once per class -- before any user-defined methods can even be invoked. The latter case relies on the class-specific name space automatically generated in the implementation's header file. As illustrated in the foo.bar example below, the implementor is free to define suitable contents.
namespace foo {
/**
* Symbol "foo.bar" (version 0.1)
*/
class bar_impl : public virtual ::foo::bar
// DO-NOT-DELETE splicer.begin(foo.bar._inherits)
// Put additional inheritance here...
// DO-NOT-DELETE splicer.end(foo.bar._inherits)
{
// All data marked protected will be accessable by
// descendant Impl classes
protected:
bool _wrapped;
// DO-NOT-DELETE splicer.begin(foo.bar._implementation)
char* d_timestamp;
// DO-NOT-DELETE splicer.end(foo.bar._implementation)
public:
/* ...lines deleted... */
}
}
If the object has no state, these functions are typically empty.
The built-in _ctor() method is invoked upon instantiation.
Hence, private data should be initialized in the method. For example
void foo::bar_impl::_ctor() {
// DO-NOT-DELETE splicer.begin(foo.bar._ctor)
time_t currTime = time(NULL);
sidl_String_strdup(d_timestamp, ctime(&currTime));
// DO-NOT-DELETE splicer.end(foo.bar._ctor)
}
To avoid leaking memory, private data must be released during
instance destruction. This is accomplished through the built-in
_dtor() method. The memory is then freed as follows
void foo::bar_impl::_dtor() {
// DO-NOT-DELETE splicer.begin(foo.bar._dtor)
sidl_String_free(d_timestamp);
// DO-NOT-DELETE splicer.end(foo.bar._dtor)
}
Hence, Babel supports the declaration and maintenance of private data on class and instance basis.