-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SofaDefaultType] Extend TypeInfo to handle containers that are not flat array. #3851
base: master
Are you sure you want to change the base?
[SofaDefaultType] Extend TypeInfo to handle containers that are not flat array. #3851
Conversation
The underlying idea is to extend the abstract API of the sofa type info system to implement the proper behavior for specific datastructures. TODO: find better name and more systematic approche for this. Signed-off-by: Damien Marchal <damien.marchal@univ-lille1.fr>
@alxbilger, @fredroy, @hugtalbot I welcome some nameing & refactoring suggestion here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the code is still obscure to me. I need to better understand for a better review.
Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/DataTypeInfoDynamicWrapper.h
Show resolved
Hide resolved
Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/DataTypeInfoDynamicWrapper.h
Show resolved
Hide resolved
@@ -97,34 +96,27 @@ struct DefaultDataTypeInfo | |||
enum { Text = 0 /**< 1 if this type uses text values*/ }; | |||
enum { CopyOnWrite = 0 /**< 1 if this type uses copy-on-write. The memory is shared with its source Data while only the source is changing (and the source modifications are then visible in the current Data). As soon as modifications are applied to the current Data, it will allocate its own value, and no longer shares memory with the source.*/ }; | |||
enum { Container = 0 /**< 1 if this type is a container*/ }; | |||
enum { UniqueKeyContainer = 0 /**< 1 if this type is a container*/ }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the right comment
Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/models/IncompleteTypeInfo.h
Show resolved
Hide resolved
Thanks for your relevant question, actually this is why the PR is in wip. So more details. The TypeInfo type-traits API has several consistancy issues (probably dating back to pre-c++17 area) mixing a lot of different behavior into a single dynamic API... making things very fuzzy. In the current status of the PR I just wanted to draft something to have a gimplse of the look and feel of a more modern code architecture (without breaking everything). Regarding your question about insertion in a vector... the problem is that insert is not a push_back... it means inserting "somewhere" which could of course be implemented on vector. But it would requires a serious work on the AbstractTypeInfo API to make all that consistent.
So in short: I drafted the general implementation, to illustrate what the current TypeInfo is really doing and how to refactor it: https://godbolt.org/z/srsq3ExPq template<class Info>
class AbstractTypeInfoDynamicWrapper : public BaseAbstractTypeInfo
{
public:
bool size() override
{
if constexpr(
Info::IsContainer &&
Info::Properties::IsContainer)
return Info::clear();
throw std::runtime_error("Invalid operation");
}
bool empty() override
{
if constexpr(
Info::IsContainer &&
Info::Properties::IsContainer)
return Info::empty();
throw std::runtime_error("Invalid operation");
}
void setValueInteger(int index, int value) override
{
if constexpr(
!Info::Properties::IsSetContainer &&
Info::Properties::Type == DataType::Integer)
return Info::setAt(index, value);
throw std::runtime_error("Invalid operation");
}
/// ...
} |
Quick test on what could be a direction to fix issue: sofa-framework/SofaPython3#346
I'm now wonder:
If some of you have suggestion, it is more than welcome.
By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if