This example demonstrates the usage of the importcomponent
-element in the reference counting mechanism provided by ACT.
The Numbers-component provides a class Variable
that can hold a numerical value.
The Calculation-component provides a class Calculator
that can sum or multiply instances of class Variable
.
- Run ACT for
Calculation.xml
(This repo already contains autogenerated sources and a working implementation). ACT automatically also generates the Numbers-component fromNumbers.xml
. - Build one of the implementations:
- C++
- Pascal
- Build and run one of the following examples
- CppDynamic
- Cpp
- Pascal
- Python
-
To be injected, the Numbers-component must specify a
symbollookupmethod
in its component definition-file. Thesymbollookupmethod
provides the addresses of all functions exported by the Numbers-component and is generated and implemented automatically by ACT. -
The definition of the Numbers-component is injected into the component
Calculator
via theimportcomponent
in theCalculation.xml
-file. To allow injecting any of the imported components into the Calculation-component, it must provide ainjectionmethod
. Theinjectionmethod
takes thesymbollookupmethod
of the injected componenent (Numbers) to create a language binding of that component inside the outer component (Calculation) at runtime. -
The Numbers-component is injected into the Calculation-component at runtime via an explicit call of
calculationWrapper->InjectComponent("Numbers", numbersWrapper->GetSymbolLookupMethod());
(analogously in other languages).
-
Reference-counting for all classes is now (v1.6.0) the default in ACT. It is implemented in the base-class by
- an integer member
m_nReferenceCount
within the base-class of a component and methods IncRefCount
which increases the reference count of an instance.DecRefCount
which decreases the reference count and deletes the instance, if it has reached zero.
In addition:
- The
releasemethod
now (v1.6.0) does not simple delete/free an instance of a class, but instead callsDecRefCount
. - All components must define an
acquiremethod
in the global section of their xml. Its autogenerated implementation callsIncRefCount
. - In order to use shared-pointers of instances of ACT-classes (C++ only, not Pascal), only use the autogenerated
shared_ptr<>
-classes$NameSpace::PI$ClassName
. They have a custom deletor that correctly callsDecRefCount
.
- an integer member
-
A Calculator instance can enlist a Variable-instance. The implementation of the enlist-method increases the reference-count of the enlisted Variable-instance, i.e. it acquires shared ownership of it. Thus, one can release the ownership of this Variable-instance on the user-code side.
-
One can retrieve a Variable-instance that is enlisted in a Calculator. This also increases the reference-count of this instance.
-
Reference-counting can be disabled by modifing the implemetation of a component's base class:
- Remove the
m_nReferenceCount
-member of the base class. - Modify the
IncRefCount
-method to do nothing. - Mpdify the
DecRefCount
-method such that it always deletes the instance.
- Remove the