
2 changed files with 0 additions and 161 deletions
@ -1,91 +0,0 @@ |
|||||
// C++ encapsulation of bloblist_t in pEp engine
|
|
||||
// this file is under GNU GPL 3.0, see LICENSE.txt
|
|
||||
|
|
||||
|
|
||||
#include "BlobList.hh" |
|
||||
|
|
||||
namespace pEp { |
|
||||
namespace Common { |
|
||||
BlobList::Iterator& BlobList::Iterator::operator= (const BlobList::Iterator& second) |
|
||||
{ |
|
||||
p = second.p; |
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
const BlobList::Blob& BlobList::Iterator::operator* () |
|
||||
{ |
|
||||
if (!p) |
|
||||
throw out_of_range("BlobList::Iterator points to nowhere"); |
|
||||
|
|
||||
if (_p != p) { |
|
||||
_b = { p->filename, p->mime_type, p->value, p->size, p->disposition }; |
|
||||
_p = p; |
|
||||
} |
|
||||
return _b; |
|
||||
} |
|
||||
|
|
||||
BlobList::Iterator& BlobList::Iterator::operator++ () |
|
||||
{ |
|
||||
if (!p) |
|
||||
throw out_of_range("BlobList::Iterator points to nowhere"); |
|
||||
|
|
||||
p = p->next; |
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
BlobList::Iterator BlobList::Iterator::operator++ (int) |
|
||||
{ |
|
||||
Iterator second = *this; |
|
||||
++(*this); |
|
||||
return second; |
|
||||
} |
|
||||
|
|
||||
BlobList::Iterator BlobList::end() |
|
||||
{ |
|
||||
return BlobList::Iterator(); |
|
||||
} |
|
||||
|
|
||||
BlobList::Iterator BlobList::begin() |
|
||||
{ |
|
||||
BlobList::Iterator _begin; |
|
||||
_begin.iterating = this; |
|
||||
_begin.p = this->bl.get(); |
|
||||
return _begin; |
|
||||
} |
|
||||
|
|
||||
BlobList::BlobList() |
|
||||
: bl(::new_bloblist(nullptr, 0, nullptr, nullptr), &::free_bloblist), |
|
||||
_size(0) |
|
||||
{ |
|
||||
if (!bl.get()) |
|
||||
throw bad_alloc(); |
|
||||
bl->release_value = release_value; |
|
||||
} |
|
||||
|
|
||||
BlobList::BlobList(const BlobList& second) |
|
||||
: bl(::bloblist_dup(second.bl.get()), &::free_bloblist), |
|
||||
_size(second._size) |
|
||||
{ |
|
||||
if (!bl.get()) |
|
||||
throw bad_alloc(); |
|
||||
} |
|
||||
|
|
||||
BlobList& BlobList::operator= (const BlobList& second) |
|
||||
{ |
|
||||
bl = blobdata(::bloblist_dup(second.bl.get()), &::free_bloblist); |
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
void BlobList::release_value(char *v) |
|
||||
{ |
|
||||
delete[] v; |
|
||||
} |
|
||||
|
|
||||
void BlobList::push_back(const Blob& val) |
|
||||
{ |
|
||||
::bloblist_add(bl.get(), val.blob, val.size, val.mime_type.c_str(), val.filename.c_str()); |
|
||||
++_size; |
|
||||
} |
|
||||
}; |
|
||||
}; |
|
||||
|
|
@ -1,70 +0,0 @@ |
|||||
// C++ encapsulation of bloblist_t in pEp engine
|
|
||||
// this file is under GNU GPL 3.0, see LICENSE.txt
|
|
||||
|
|
||||
|
|
||||
#pragma once |
|
||||
|
|
||||
#include <string> |
|
||||
#include <iterator> |
|
||||
|
|
||||
#include <pEp/bloblist.h> |
|
||||
|
|
||||
namespace pEp { |
|
||||
namespace Common { |
|
||||
using namespace std; |
|
||||
|
|
||||
class BlobList { |
|
||||
public: |
|
||||
struct Blob { |
|
||||
string filename; |
|
||||
string mime_type; |
|
||||
char *blob = nullptr; |
|
||||
size_t size = 0; |
|
||||
content_disposition_type cd = PEP_CONTENT_DISP_ATTACHMENT; |
|
||||
}; |
|
||||
|
|
||||
class Iterator : public iterator< forward_iterator_tag, Blob > { |
|
||||
friend class BlobList; |
|
||||
|
|
||||
private: |
|
||||
::bloblist_t *p = nullptr; |
|
||||
::bloblist_t *_p = nullptr; |
|
||||
Blob _b; |
|
||||
BlobList *iterating = nullptr; |
|
||||
|
|
||||
public: |
|
||||
Iterator() { } |
|
||||
Iterator(const Iterator& second) : p(second.p), iterating(second.iterating) { } |
|
||||
Iterator& operator= (const Iterator& second); |
|
||||
~Iterator() { } |
|
||||
bool operator== (const Iterator& second) const { return p == second.p; } |
|
||||
bool operator!= (const Iterator& second) const { return p != second.p; } |
|
||||
const Blob& operator* (); |
|
||||
Iterator& operator++ (); |
|
||||
Iterator operator++ (int); |
|
||||
}; |
|
||||
|
|
||||
Iterator end(); |
|
||||
Iterator begin(); |
|
||||
|
|
||||
BlobList(); |
|
||||
BlobList(const BlobList& second); |
|
||||
BlobList& operator= (const BlobList& second); |
|
||||
~BlobList(); |
|
||||
|
|
||||
void push_back(const Blob& val); |
|
||||
size_t size() const { return _size; } |
|
||||
bool empty() const { return _size == 0; } |
|
||||
|
|
||||
operator ::bloblist_t *() { return bl.get(); } |
|
||||
operator const ::bloblist_t *() const { return bl.get(); } |
|
||||
|
|
||||
private: |
|
||||
static void release_value(char *v); |
|
||||
typedef unique_ptr< ::bloblist_t, decltype(&::free_bloblist) > blobdata; |
|
||||
blobdata bl; |
|
||||
size_t _size; |
|
||||
}; |
|
||||
}; |
|
||||
}; |
|
||||
|
|
Loading…
Reference in new issue