|
|
@ -4,6 +4,8 @@ |
|
|
|
#ifndef LIBPEPDATATYPES_WRAPPER_HH |
|
|
|
#define LIBPEPDATATYPES_WRAPPER_HH |
|
|
|
|
|
|
|
#include <initializer_list> |
|
|
|
|
|
|
|
namespace pEp |
|
|
|
{ |
|
|
|
|
|
|
@ -69,7 +71,10 @@ public: |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
protected: |
|
|
|
|
|
|
|
Wrapper(T* _value) : value{_value} {} |
|
|
|
|
|
|
|
// must be defined for each wrapped type:
|
|
|
|
template<class... Args> |
|
|
|
T* _new(Args...); |
|
|
@ -80,6 +85,44 @@ private: |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Wraps single-linked lists and provides an interface compatible
|
|
|
|
// to std::forward_list
|
|
|
|
template<class T, class Element> |
|
|
|
class ListWrapper; |
|
|
|
|
|
|
|
|
|
|
|
template<class T, class Element> |
|
|
|
class ListWrapper<T*, Element> : public Wrapper<T*> |
|
|
|
{ |
|
|
|
public: |
|
|
|
struct Trait; |
|
|
|
typedef Wrapper<T*> Base; |
|
|
|
typedef ListWrapper<T*, Element> iterator; // FIXME: different type necessary?
|
|
|
|
|
|
|
|
static Element T::* const Value; // to access the current value
|
|
|
|
|
|
|
|
using Base::Base; |
|
|
|
using Base::value; |
|
|
|
|
|
|
|
ListWrapper() : Base() {} |
|
|
|
ListWrapper(const std::initializer_list<Element>& i); |
|
|
|
|
|
|
|
iterator begin() { return value; } |
|
|
|
iterator end() const { return iterator{}; } |
|
|
|
int size() const; |
|
|
|
bool empty() const; |
|
|
|
|
|
|
|
// I am my own iterator
|
|
|
|
iterator operator++() { return (value ? value = value->next : value); } |
|
|
|
Element operator*() { return value->Value; } |
|
|
|
|
|
|
|
void clear(); |
|
|
|
void push_back(Element&&); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end of namespace pEp
|
|
|
|
|
|
|
|
#endif // LIBPEPDATATYPES_WRAPPER_HH
|
|
|
|