DetectorGraph
2.0
|
A dictionary-based translator that uses shared memory in TopicStates. More...
Go to the source code of this file.
A dictionary-based translator that uses shared memory in TopicStates.
This examples implements a very basic translator based only on word replacements.
DetectorGraph uses C++ copies to propagate information across Topics & Detectors. This is fine & desirable for small amounts of data but can become prohibitive for large objects. In such cases the recommended pattern is to wrap the large resource using an appropriate smart pointer (e.g. std::shared_ptr).
The one caveat is that, as Detectors start accessing shared memory, the DetectorGraph framework alone cannot guarantee the hermetic nature of detectors - a detector's data (i.e. the data a member pointer points to) may change even though no Evaluate('new value') for that member was called.
In cases where the large data piece only has only read-only use, a const_shared_ptr can be used to partially address the concern mentioned above.
In this example, the TranslationDictionary
TopicState carries a large, immutable object and does so using a shared_ptr<const T>:
A different example that also uses this pattern is Fancy Vending Machine:
This sample implements the following graph:
Definition in file portuguesetranslator.cpp.