2021-06-18 10:10:03 +02:00
|
|
|
#include "types.hh"
|
|
|
|
|
|
|
|
#include <pEp/status_to_string.hh> // from libpEpAdapter
|
|
|
|
#include <pEp/stringlist.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace pEp
|
|
|
|
{
|
|
|
|
template<>
|
|
|
|
void Wrapper<::stringlist_t*>::_free(::stringlist_t* sl)
|
|
|
|
{
|
|
|
|
::free_stringlist(sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2021-06-18 10:42:55 +02:00
|
|
|
const char* stringlist_t::* const ListWrapper<stringlist_t*, const char*>::Value = &stringlist_t::value;
|
2021-06-18 10:10:03 +02:00
|
|
|
|
|
|
|
template<>
|
|
|
|
int StringList::size() const
|
|
|
|
{
|
|
|
|
return stringlist_length(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// faster than .size()==0 because it's not necessary to iterate throgh the whole list
|
|
|
|
template<>
|
|
|
|
bool StringList::empty() const
|
|
|
|
{
|
|
|
|
return !(value && value->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void StringList::erase( const StringList::iterator& it)
|
|
|
|
{
|
|
|
|
if(it.value && it.value->value)
|
|
|
|
{
|
|
|
|
value = stringlist_delete(value, it.value->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void StringList::clear()
|
|
|
|
{
|
|
|
|
free_stringlist(value);
|
|
|
|
value = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void StringList::push_back(const char*&& s)
|
|
|
|
{
|
|
|
|
auto last = stringlist_add(value, s);
|
|
|
|
if(value==nullptr)
|
|
|
|
value = last;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
ListWrapper<::stringlist_t*, const char*>::ListWrapper(const std::initializer_list<const char*>& il)
|
|
|
|
: StringList{}
|
|
|
|
{
|
|
|
|
::stringlist_t* last = nullptr;
|
|
|
|
for(const char* s : il)
|
|
|
|
{
|
|
|
|
last = stringlist_add(last, s);
|
|
|
|
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<::stringlist_t*, const char*>;
|
|
|
|
|
|
|
|
} // end of namespace pEp
|