A C++ wrapper for the basic C datatypes defined by the pEpEngine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

85 lines
1.6 KiB

// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPDATATYPES_WRAPPER_HH
#define LIBPEPDATATYPES_WRAPPER_HH
namespace pEp
{
template<class T>
class Wrapper
{
public:
template<class... Args>
Wrapper(Args... args) : value{ this->_new(args...) } {}
// no implicit copying... (yet?)
Wrapper(const Wrapper<T>&) = delete;
void operator=(const Wrapper<T>&) = delete;
// must be implemented separately for each T
Wrapper(Wrapper<T>&& victim);
Wrapper<T>& operator=(Wrapper<T>&& victim);
~Wrapper();
Wrapper<T> copy() const;
private:
// must be defined for each wrapped type:
template<class... Args>
T* _new(Args...);
T value;
};
// many wrapped datatypes are pointers, we can generalize a lot for them:
template<class T>
class Wrapper<T*>
{
public:
Wrapper() : value{nullptr} {}
template<class... Args>
Wrapper(Args... args) : value{ this->_new(args...) } {}
// no implicit copying... (yet?)
Wrapper(const Wrapper<T*>&) = delete;
void operator=(const Wrapper<T*>&) = delete;
// must be implemented separately for each T
Wrapper(Wrapper<T*>&& victim)
: value{ victim.value}
{
victim.value = nullptr;
}
Wrapper<T*>&& operator=(Wrapper<T*>&& victim)
{
_free();
value = victim.value;
victim.value = nullptr;
}
~Wrapper()
{
_free();
}
private:
// must be defined for each wrapped type:
template<class... Args>
T* _new(Args...);
void _free();
T* value;
};
} // end of namespace pEp
#endif // LIBPEPDATATYPES_WRAPPER_HH