NICTA / SmartGridToolbox

Smart Grid Simulation Library (C++14)
http://nicta.github.io/SmartGridToolbox
24 stars 10 forks source link

Actions to expire upon deletion of their subject? #41

Closed dexterurbane closed 7 years ago

dexterurbane commented 7 years ago

Ideally, actions should behave as if they are an observer that is totally separate from the event they observe. In particular, when the subject of an action goes out of scope / is destructed, the action should no longer exist.

The current architecture, however, stores the actions inside the event. This is sometimes appropriate - for example, the action could be an arbitrary std::function, such as a logging function.

Think about how we can reconcile these two facts.

dexterurbane commented 7 years ago

Solution perhaps something along the lines of:

Need to distinguish between actions that are owned by the event, and those that are externally owned.

dexterurbane commented 7 years ago

On last point: Action uses PIMPL, with shared_ptr to ActionImpl. In action destructor, if the use count is two, then we need to remove the action from its event.

dexterurbane commented 7 years ago

Fixed.