#include "types.hh" #include // from libpEpAdapter /* #include #include #include */ #include namespace pEp { EngineError::EngineError(PEP_STATUS status, const char* message) : std::runtime_error( std::string{"EngineError: "} + (message ? '"' + std::string{message} + "\" " : std::string{} ) + status_to_string(status) ) {} //////////////// template<> template<> message* Wrapper<::message*>::_new(PEP_msg_direction dir, const char* s) { message* m = new_message(dir); if(!m) { throw EngineError(PEP_OUT_OF_MEMORY, "new_message()"); } return m; } template<> void Wrapper<::message*>::_free(::message* m) { free_message(m); } //////////////// template<> template<> ::stringpair_t* Wrapper<::stringpair_t*>::_new(const char* key, const char* value) { stringpair_t* sp = new_stringpair(key, value); if(!sp) { throw EngineError(PEP_OUT_OF_MEMORY, "new_stringpair()"); } return sp; } template<> template<> ::stringpair_t* Wrapper<::stringpair_t*>::_new(char* key, char* value) { return _new( const_cast(key), const_cast(value) ); } template<> template<> ::stringpair_t* Wrapper<::stringpair_t*>::_new(const std::string& key, const std::string& value) { return Wrapper<::stringpair_t*>::_new(key.c_str(), value.c_str()); } template<> void Wrapper<::stringpair_t*>::_free(::stringpair_t* sp) { free_stringpair(sp); } template<> void Wrapper<::stringpair_list_t*>::_free(::stringpair_list_t* spl) { free_stringpair_list(spl); } template<> stringpair_t* stringpair_list_t::* const ListWrapper::Value = &stringpair_list_t::value; template<> int StringPairList::size() const { return stringpair_list_length(value); } // faster than .size()==0 because it's not necessary to iterate throgh the whole list template<> bool StringPairList::empty() const { return !(value && value->value); } template<> void StringPairList::erase( const StringPairList::iterator& it) { if(it.value && it.value->value && it.value->value->key) { value = stringpair_list_delete_by_key(value, it.value->value->key); } } template<> void StringPairList::clear() { free_stringpair_list(value); value = nullptr; } template<> void StringPairList::push_back(::stringpair_t*&& sp) { auto last = stringpair_list_add(value, sp); if(value==nullptr) value = last; sp = nullptr; } template<> void StringPairList::push_back(StringPair&& sp) { auto last = stringpair_list_add(value, sp.move_out()); if(value==nullptr) value = last; } template<> ListWrapper<::stringpair_list_t*, stringpair_t*>::ListWrapper(const std::initializer_list& il) : StringPairList{} { ::stringpair_list_t* last = nullptr; for(const StringPair& sp : il) { last = stringpair_list_add(last, stringpair_dup(sp.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 Wrapper<::stringpair_t>; template class Wrapper<::message>; template class ListWrapper<::stringpair_list_t*, ::stringpair_t*>; } // end of namespace pEp