add identity & identity_list.
parent
2e1241bb5f
commit
9f2d01a2bf
@ -1,28 +1,68 @@
|
||||
#include "types.hh"
|
||||
|
||||
#include <pEp/identity_list.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace pEp
|
||||
{
|
||||
|
||||
template<>
|
||||
void Wrapper<::identity_list*>::_free(::identity_list* sl)
|
||||
{
|
||||
::free_identity_list(sl);
|
||||
}
|
||||
|
||||
template<>
|
||||
pEp_identity* identity_list::* const ListWrapper<identity_list*, const char*>::Value = &identity_list::ident;
|
||||
|
||||
template<>
|
||||
pEp_identity* Wrapper<::pEp_identity*>::_new<const char*, const char*, const char*, const char*>
|
||||
(const char* address, const char* fpr, const char* user_id, const char* username)
|
||||
int identity_list::size() const
|
||||
{
|
||||
pEp_identity* id = new_identity(address, fpr, user_id, username);
|
||||
if(!id)
|
||||
{
|
||||
throw EngineError(PEP_OUT_OF_MEMORY, "new_identity()");
|
||||
}
|
||||
return id;
|
||||
return identity_list_length(value);
|
||||
}
|
||||
|
||||
// faster than .size()==0 because it's not necessary to iterate throgh the whole list
|
||||
template<>
|
||||
bool identity_list::empty() const
|
||||
{
|
||||
return !(value && value->ident);
|
||||
}
|
||||
|
||||
template<>
|
||||
void identity_list::clear()
|
||||
{
|
||||
free_identity_list(value);
|
||||
value = nullptr;
|
||||
}
|
||||
|
||||
template<>
|
||||
void Wrapper<::pEp_identity*>::_free(::pEp_identity* id)
|
||||
void identity_list::push_back(pEp_identity*&& id)
|
||||
{
|
||||
free_identity(id);
|
||||
auto last = identity_list_add(value, id);
|
||||
if(value==nullptr)
|
||||
value = last;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
ListWrapper<::identity_list*, pEp_identity*>::ListWrapper(const std::initializer_list<Wrapper<pEp_identity*>>& il)
|
||||
: identity_list{}
|
||||
{
|
||||
::identity_list* last = nullptr;
|
||||
for(const Wrapper<pEp_identity*>& id : il)
|
||||
{
|
||||
last = identity_list_add(last, identity_dup(id.get()));
|
||||
if(last==nullptr)
|
||||
{
|
||||
throw std::runtime_error("Cannot create StringPairList from {}: Out Of Memory.");
|
||||
}
|
||||
if(value==nullptr)
|
||||
value = last; // save the head of linked list.
|
||||
}
|
||||
}
|
||||
|
||||
////////////////
|
||||
|
||||
template class Wrapper<::pEp_identity*>;
|
||||
template class ListWrapper<::identity_list*, ::pEp_identity*>;
|
||||
|
||||
} // end of namespace pEp
|
||||
|
Loading…
Reference in New Issue