diff --git a/src/types.hh b/src/types.hh index 18f97ec..3c14eb2 100644 --- a/src/types.hh +++ b/src/types.hh @@ -21,6 +21,7 @@ namespace pEp using Identity = Wrapper<::pEp_identity*>; using StringPair = Wrapper<::stringpair_t*>; + using StringPairList = ListWrapper<::stringpair_list_t*, ::stringpair_t*>; using Message = Wrapper<::message*>; diff --git a/src/wrapper.hh b/src/wrapper.hh index 2733539..deb48be 100644 --- a/src/wrapper.hh +++ b/src/wrapper.hh @@ -4,6 +4,8 @@ #ifndef LIBPEPDATATYPES_WRAPPER_HH #define LIBPEPDATATYPES_WRAPPER_HH +#include + namespace pEp { @@ -69,7 +71,10 @@ public: } -private: +protected: + + Wrapper(T* _value) : value{_value} {} + // must be defined for each wrapped type: template T* _new(Args...); @@ -80,6 +85,44 @@ private: }; +// Wraps single-linked lists and provides an interface compatible +// to std::forward_list +template +class ListWrapper; + + +template +class ListWrapper : public Wrapper +{ +public: + struct Trait; + typedef Wrapper Base; + typedef ListWrapper 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& 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