From 176d649476e4c058f56ccd8e15d4a26517f9b698 Mon Sep 17 00:00:00 2001 From: roker Date: Fri, 18 Jun 2021 12:59:55 +0200 Subject: [PATCH] add bloblist specialization. DOES NOT COMPILE, YET. --- src/bloblist.cc | 46 ++++++++++++++++++++++++++++++++++++ src/bloblist.hh | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ src/types.hh | 3 ++- src/wrapper.hh | 3 --- 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 src/bloblist.cc create mode 100644 src/bloblist.hh diff --git a/src/bloblist.cc b/src/bloblist.cc new file mode 100644 index 0000000..8e22462 --- /dev/null +++ b/src/bloblist.cc @@ -0,0 +1,46 @@ +#include "bloblist.hh" + +#include + +namespace pEp +{ + template<> + void Wrapper<::bloblist_t*>::_free(::bloblist_t* bl) + { + ::free_bloblist(bl); + } + + + template<> + int BlobList::size() const + { + return bloblist_length(value); + } + + // faster than .size()==0 because it's not necessary to iterate throgh the whole list + template<> + bool BlobList::empty() const + { + return !(value && value->value); + } + + template<> + void BlobList::clear() + { + free_bloblist(value); + value = nullptr; + } + + template<> + void BlobList::push_back(const char*&& s) + { + auto last = stringlist_add(value, s); + if(value==nullptr) + value = last; + } + +//////////////// + + template class ListWrapper<::bloblist_t*, ::bloblist_t*>; + +} // end of namespace pEp diff --git a/src/bloblist.hh b/src/bloblist.hh new file mode 100644 index 0000000..2b04fda --- /dev/null +++ b/src/bloblist.hh @@ -0,0 +1,63 @@ +// This file is under GNU General Public License 3.0 +// see LICENSE.txt + +#ifndef LIBPEPDATATYPES_BLOBLIST_HH +#define LIBPEPDATATYPES_BLOBLIST_HH + +#include "wrapper.hh" +#include + +namespace pEp +{ + + +template<> +class ListWrapper<::bloblist_t*, void> : public Wrapper<::bloblist_t*> +{ +public: + typedef ::bloblist_t Blob; + typedef Wrapper Base; + typedef ListWrapper LW; + + + // does not own the *value + class iterator + { + public: + iterator() = default; + + iterator operator++() { return (value ? value = value->next : value); } + Blob& operator*() { return *value; } + Blob* operator->() { return value; } + const Blob& operator*() const { return *value; } + const Blob* operator->() const { return value; } + bool operator==(const iterator& other) const { return value == other.value; } + bool operator!=(const iterator& other) const { return value != other.value; } + + private: + iterator(::bloblist_t* _t) : value{_t} {} + ::bloblist_t* value = nullptr; + friend class ListWrapper<::bloblist_t*, void>; + }; + + + using Base::value; + + ListWrapper() : Base() {} + + + iterator begin() { return iterator{value}; } + iterator end() const { return iterator{}; } + int size() const; + bool empty() const; + + void clear(); + void push_back(Blob&&); + void emplace_back(char* data, size_t size, const char* mime_type, const char* filename); +}; + + using BlobList = ListWrapper<::bloblist_t*, void>; + +} // end of namespace pEp + +#endif // LIBPEPDATATYPES_BLOBLIST_HH diff --git a/src/types.hh b/src/types.hh index 8a6dbd9..5239615 100644 --- a/src/types.hh +++ b/src/types.hh @@ -5,6 +5,7 @@ #define LIBPEPDATATYPES_TYPES_HH #include "wrapper.hh" +#include "bloblist.hh" // full specialization of ListWrapper. #include #include @@ -24,7 +25,7 @@ namespace pEp using StringPairList = ListWrapper<::stringpair_list_t*, ::stringpair_t*>; using StringList = ListWrapper<::stringlist_t*, const char*>; - using BlobList = ListWrapper<::bloblist_t*, ::bloblist_t*>; + using BlobList = ListWrapper<::bloblist_t*, void>; using Message = Wrapper<::message*>; diff --git a/src/wrapper.hh b/src/wrapper.hh index 2c42aba..6c80fe0 100644 --- a/src/wrapper.hh +++ b/src/wrapper.hh @@ -156,11 +156,8 @@ public: void clear(); void push_back(Element&&); void push_back(Wrapper&&); - }; - - } // end of namespace pEp #endif // LIBPEPDATATYPES_WRAPPER_HH