You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

98 lines
2.3 KiB

#include "types.hh"
#include <pEp/identity_list.h>
#include <string>
namespace pEp {
template<>
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)
{
return ::new_identity(address, fpr, user_id, username);
}
template<>
void Wrapper<::pEp_identity*>::_free(::pEp_identity* id)
{
::free_identity(id);
}
template<>
::pEp_identity* Wrapper<::pEp_identity*>::copy_out() const
{
return identity_dup(value);
}
//////////////
template<>
void Wrapper<::identity_list*>::_free(::identity_list* sl)
{
::free_identity_list(sl);
}
template<>
::identity_list* Wrapper<::identity_list*>::copy_out() const
{
return identity_list_dup(value);
}
template<>
::pEp_identity* identity_list::*const
ListWrapper<::identity_list*, ::pEp_identity*>::Value = &identity_list::ident;
template<>
int IdentityList::size() const
{
return identity_list_length(value);
}
// faster than .size()==0 because it's not necessary to iterate throgh the whole list
template<>
bool IdentityList::empty() const
{
return !(value && value->ident);
}
template<>
void IdentityList::clear()
{
free_identity_list(value);
value = nullptr;
}
template<>
void IdentityList::push_back(pEp_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) :
Base{}
{
::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 ListWrapper<::identity_list*, ::pEp_identity*>;
} // end of namespace pEp