diff --git a/src/types.cc b/src/types.cc index cde0c00..845aaab 100644 --- a/src/types.cc +++ b/src/types.cc @@ -65,10 +65,59 @@ namespace pEp { free_stringpair(sp); } + + + template<> + void Wrapper<::stringpair_list_t*>::_free(::stringpair_list_t* spl) + { + free_stringpair_list(spl); + } template<> stringpair_t* stringpair_list_t::* const ListWrapper::Value = &stringpair_list_t::value; + template<> + int StringPairList::size() const + { + return stringpair_list_length(value); + } + + // faster than .size()==0 because it's not necessary to iterate throgh the whole list + template<> + bool StringPairList::empty() const + { + return value && value->value; + } + + template<> + void StringPairList::erase( const StringPairList::iterator& it) + { + if(it.value && it.value->value && it.value->value->key) + { + value = stringpair_list_delete_by_key(value, it.value->value->key); + } + } + + template<> + void StringPairList::clear() + { + free_stringpair_list(value); + value = nullptr; + } + + template<> + void StringPairList::push_back(::stringpair_t*&& sp) + { + stringpair_list_add(value, sp); + sp = nullptr; + } + + template<> + void StringPairList::push_back(StringPair&& sp) + { + stringpair_list_add(value, sp.move_out()); + } + //////////////// template class Wrapper<::pEp_identity>; diff --git a/src/wrapper.hh b/src/wrapper.hh index ce2d71e..3c42a51 100644 --- a/src/wrapper.hh +++ b/src/wrapper.hh @@ -78,7 +78,7 @@ public: } const T* get() const { return value; } - T* move_out() && { T* r = value; value=nullptr; return r;} + T* move_out() { T* r = value; value=nullptr; return r;} friend bool operator==(const Wrapper& a, const Wrapper& b); @@ -151,6 +151,7 @@ public: void erase(const iterator& it); void clear(); void push_back(Element&&); + void push_back(Wrapper&&); };