initial version

LPA-1
Volker Birk 5 years ago
commit 88315be53a

@ -0,0 +1,4 @@
syntax: glob
*.o
*.a
*.swp

@ -0,0 +1,87 @@
#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;
}
};
};

@ -0,0 +1,65 @@
#pragma once
#include <vector>
#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* ();
operator bloblist_t *() { return p; }
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; }
private:
static void release_value(char *v);
typedef unique_ptr< ::bloblist_t, decltype(&::free_bloblist) > blobdata;
blobdata bl;
size_t _size;
};
};
};

@ -0,0 +1,23 @@
include Makefile.conf
-include local.conf
TARGET?=libpEpAdapter.a
PEPENGINE_IN?=$(HOME)
CXXFLAGS += -I$(HOME)/include -std=c++14
SOURCE=$(wildcard *.cc)
OBJECTS=$(subst .cc,.o,$(SOURCE))
all: $(TARGET)
%.o: %.cc %.hh
$(CXX) $(CXXFLAGS) -c $<
$(TARGET): $(OBJECTS)
ar -rc $@ $^
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJECTS)

@ -0,0 +1,2 @@
# TARGET=libpEpAdapter.a
# PEPENGINE_IN=$(HOME)
Loading…
Cancel
Save