You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I'm trying to overcome the problem of dependency injection by adding a smart pointer to the archive with contains the dependencies via registerSharedPointer. Then, on the serialization functions, I can get this pointer by calling getSharedPointer.
This worked well in my first attempt at registering the pointer to the id 1 (0 can't be used as per getSharedPointer impl), to make this a bit more robust I want to use type_index on the registered type so I don't have to keep a look-up table for id -> pointer extraction. The following is the wrapper code for this:
The problem with this is that first, the cereal id expects a std::uint32_t which will truncate the std::size_t.
Secondly, in the registerSharedPointer there is this line of code which will change the input id:
std::uint32_t const stripped_id = id & ~detail::msb_32bit;
This would be ok(ish) if it also did it on getSharedPointer, however, it does not, which causes the function to fail and throw an exception.
My main concern is the stripping of the id, which seems rather unnecessary, but I could just be missing some very important detail as to why it's there. I tested by changing to std::size_t and not stripping the id and everything worked fine still.
Would be nice to hear your ideas! And possibly some design changes?
The text was updated successfully, but these errors were encountered:
So I'm trying to overcome the problem of dependency injection by adding a smart pointer to the archive with contains the dependencies via registerSharedPointer. Then, on the serialization functions, I can get this pointer by calling getSharedPointer.
This worked well in my first attempt at registering the pointer to the id 1 (0 can't be used as per getSharedPointer impl), to make this a bit more robust I want to use type_index on the registered type so I don't have to keep a look-up table for id -> pointer extraction. The following is the wrapper code for this:
The problem with this is that first, the cereal id expects a std::uint32_t which will truncate the std::size_t.
Secondly, in the registerSharedPointer there is this line of code which will change the input id:
std::uint32_t const stripped_id = id & ~detail::msb_32bit;
This would be ok(ish) if it also did it on getSharedPointer, however, it does not, which causes the function to fail and throw an exception.
My main concern is the stripping of the id, which seems rather unnecessary, but I could just be missing some very important detail as to why it's there. I tested by changing to std::size_t and not stripping the id and everything worked fine still.
Would be nice to hear your ideas! And possibly some design changes?
The text was updated successfully, but these errors were encountered: