Browse Source

okay, we allow copying for all Wrapper where copy_out() is implemented.

master
roker 4 years ago
parent
commit
7973a9638b
  1. 2
      src/identity.cc
  2. 20
      src/wrapper.hh

2
src/identity.cc

@ -24,7 +24,7 @@ namespace pEp
} }
template<> template<>
::pEp_identity* Wrapper<::pEp_identity*>::copy_out() ::pEp_identity* Wrapper<::pEp_identity*>::copy_out() const
{ {
return identity_dup(value); return identity_dup(value);
} }

20
src/wrapper.hh

@ -62,11 +62,7 @@ public:
template<class... Args> template<class... Args>
Wrapper(Args... args) : value{ this->_new(args...) } {} Wrapper(Args... args) : value{ this->_new(args...) } {}
// no implicit copying... (yet?) // move is easy, efficient and generic:
Wrapper(const Wrapper<T*>&) = delete;
void operator=(const Wrapper<T*>&) = delete;
// must be implemented separately for each T
Wrapper(Wrapper<T*>&& victim) Wrapper(Wrapper<T*>&& victim)
: value{ victim.value} : value{ victim.value}
{ {
@ -80,6 +76,18 @@ public:
victim.value = nullptr; victim.value = nullptr;
return *this; return *this;
} }
Wrapper(const Wrapper<T*>& orig)
: value{ orig.copy_out() }
{}
Wrapper<T*>& operator=(const Wrapper<T*>& orig)
{
if(&orig == this) return *this;
_free(value);
value = orig.copy_out();
return *this;
}
~Wrapper() ~Wrapper()
{ {
@ -107,7 +115,7 @@ public:
// only implemented for the datatypes where necessay. // only implemented for the datatypes where necessay.
// other implementations can follow if necessary. // other implementations can follow if necessary.
T* copy_out(); T* copy_out() const;
protected: protected:

Loading…
Cancel
Save