Browse Source

add bloblist specialization. DOES NOT COMPILE, YET.

master
roker 4 years ago
parent
commit
176d649476
  1. 46
      src/bloblist.cc
  2. 63
      src/bloblist.hh
  3. 3
      src/types.hh
  4. 3
      src/wrapper.hh

46
src/bloblist.cc

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

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

3
src/types.hh

@ -5,6 +5,7 @@
#define LIBPEPDATATYPES_TYPES_HH
#include "wrapper.hh"
#include "bloblist.hh" // full specialization of ListWrapper<bloblist_t*, void>.
#include <stdexcept>
#include <pEp/pEpEngine.h>
@ -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*>;

3
src/wrapper.hh

@ -156,11 +156,8 @@ public:
void clear();
void push_back(Element&&);
void push_back(Wrapper<Element>&&);
};
} // end of namespace pEp
#endif // LIBPEPDATATYPES_WRAPPER_HH

Loading…
Cancel
Save