Refactor all container pointer references to template types #368
Labels
No Label
API Change
Breaking API Change
bug
build
cosmetics
Documentation
duplicate
feature
help wanted
hotfix
invalid
question
Refactor
Tests
wontfix
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: fsfw/fsfw#368
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Right now, there are some implementation of classes to allow different types of containers for say, a data structure like a queue or an array of pool variables.
This is done by storing a address of the container structure start and the size (so, basically C style)
Examples:
PoolDataSetBase
FIFOBase
However, considering the options available with modern C++, this is not really an ideal solution. One has to write custom copy ctors and assignment ctors, because simply copying the pointer is wrong (rule of 3/5).
However, considering we have working code right now, I might wait with the refactoring steps. This should not change the external API however, because the public interface to be used will still be containers like the
StaticLocalDataSet
, which simply have the base class with the correct template arguments (e.g.std::array
for the StaticLocalDataSet andstd::vector
for the regular LocalDataSet)Refactor all container references as double ** to template typesto Refactor all container pointer references to template typesSome more research:
https://stackoverflow.com/questions/7728478/c-template-class-function-with-arbitrary-container-type-how-to-define-it
That way, I might be able to get rid of the pointers. This should work with
std::array
andstd::vector
.Some prototyping: https://stackoverflow.com/questions/66082447/c-using-container-as-a-template-type/66087589#66087589
Not sure if it's worth the effort though. Would require a new interface because now the object base would be a template. But also interesting, this now feels a little bit like duck typing.
I think the downside is the testing effort. This kind of Templates are difficult to test, especially if the underlying container is totally different. Even if its only two kind of possible template arguments. This makes it rather uninteressting for small and reliable embedded software that doesn't change much. Interesstingly, forbidding copying has a nice side effect. Because copying a container that has a std::vector as an member will allocate memory at runtime and that will be a difficult issue to track down.
Yes