Browse Source

add ListWrapper<T,E>. define StringPairList.

master
roker 5 months ago
parent
commit
0f8cdd048a
2 changed files with 45 additions and 1 deletions
  1. +1
    -0
      src/types.hh
  2. +44
    -1
      src/wrapper.hh

+ 1
- 0
src/types.hh View File

@ -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*>;


+ 44
- 1
src/wrapper.hh View File

@ -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

Loading…
Cancel
Save