Skip to content
Snippets Groups Projects
Commit bda4351c authored by Axel Naumann's avatar Axel Naumann
Browse files

Make TUniWeak out-streamable without weak_ptr or variant support.

Create two members, weak and unique_ptr, as I/O cannot handle variant. So we stream both.
O, and I/O cannot handle weak_ptr, but we really need it, so at least support writing (through THttpServer) by adding a `T*` with the same
value as the weak ptr, and have that streamed. This completely breaks the internal symmetry of TUniWeak, but it should get us started...
parent d86b14a8
No related branches found
No related tags found
No related merge requests found
......@@ -52,11 +52,12 @@ namespace Internal {
template <class T>
class TUniWeakPtr {
union {
// Needs I/O support for union (or variant, actually) {
std::unique_ptr<T> fUnique;
std::weak_ptr<T> fWeak;
};
bool fIsWeak; ///< fUnique or fWeak?
std::weak_ptr<T> fWeak; //! Cannot save for now :-(
T* fWeakForIO = nullptr; // Hack to allow streaming *out* of fWeak (reading is still broken because we don't set fWeak)
// };
bool fIsWeak = false; ///< fUnique or fWeak?
public:
/// \class Accessor
......@@ -97,22 +98,22 @@ public:
}
};
TUniWeakPtr(const std::shared_ptr<T> &ptr): fWeak(ptr), fIsWeak(true) {}
TUniWeakPtr() = default;
TUniWeakPtr(const std::shared_ptr<T> &ptr): fWeak(ptr), fWeakForIO(ptr.get()), fIsWeak(true) {}
TUniWeakPtr(std::unique_ptr<T> &&ptr): fUnique(std::move(ptr)), fIsWeak(false) {}
TUniWeakPtr(TUniWeakPtr &&rhs): fIsWeak(rhs.fIsWeak)
{
if (fIsWeak) {
fWeak.weak_ptr(std::move(rhs.fWeak));
} else
fWeak.unique_ptr(std::move(rhs.fUnique));
if (rhs.fIsWeak) {
fWeak = std::move(rhs.fWeak);
auto shptr = rhs.fWeak.lock();
fWeakForIO = shptr.get();
} else {
fUnique = std::move(rhs.fUnique);
}
}
~TUniWeakPtr()
{
if (fIsWeak)
fWeak.~weak_ptr();
else
fUnique.~unique_ptr();
}
Accessor Get() const { return Accessor(*this); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment