
4 changed files with 111 additions and 4 deletions
@ -0,0 +1,46 @@ |
|||
#include "bloblist.hh" |
|||
|
|||
#include <pEp/bloblist.h> |
|||
|
|||
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
|
@ -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 <pEp/bloblist.h> |
|||
|
|||
namespace pEp |
|||
{ |
|||
|
|||
|
|||
template<> |
|||
class ListWrapper<::bloblist_t*, void> : public Wrapper<::bloblist_t*> |
|||
{ |
|||
public: |
|||
typedef ::bloblist_t Blob; |
|||
typedef Wrapper<Blob*> Base; |
|||
typedef ListWrapper<Blob*, void> 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
|
Loading…
Reference in new issue