Browse Source

add wrapper for stringpair_t

master
roker 12 months ago
parent
commit
b8b855e075
3 changed files with 46 additions and 5 deletions
  1. +1
    -1
      src/Makefile
  2. +39
    -4
      src/types.cc
  3. +6
    -0
      src/types.hh

+ 1
- 1
src/Makefile View File

@ -15,7 +15,7 @@ ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDS)
endif
.PHONY: install uninstall clean
.PHONY: all install uninstall clean
all: $(TARGET)


+ 39
- 4
src/types.cc View File

@ -1,28 +1,63 @@
#include "types.hh"
#include <pEp/status_to_string.hh> // from libpEpAdapter
/*
#include <pEp/pEpEngine.h>
#include <pEp/stringpair.h>
#include <pEp/message.h>
*/
#include <string>
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 class Wrapper<::pEp_identity>;
template class Wrapper<::stringpair_t>;
template class Wrapper<::message>;
template<>
template<>
message* Wrapper<::message*>::_new<PEP_msg_direction, char*>(PEP_msg_direction dir, char* s)
{
message* m = new_message(dir);
if(!m)
{
throw EngineError(PEP_OUT_OF_MEMORY, "new_message()");
}
return 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(const std::string& key, const std::string& value)
{
return Wrapper<::stringpair_t*>::_new(key.c_str(), value.c_str());
}
Message m(PEP_dir_incoming, "Foo");
StringPair sp(std::string("foo"), std::string("bar"));
template class Wrapper<::pEp_identity>;
template class Wrapper<::stringpair_t>;
template class Wrapper<::message>;
} // end of namespace pEp

+ 6
- 0
src/types.hh View File

@ -6,12 +6,18 @@
#include "wrapper.hh"
#include <stdexcept>
#include <pEp/pEpEngine.h>
#include <pEp/stringpair.h>
#include <pEp/message.h>
namespace pEp
{
class EngineError : std::runtime_error
{
public:
EngineError(PEP_STATUS status, const char* message = nullptr);
};
using Identity = Wrapper<::pEp_identity>;
using StringPair = Wrapper<::stringpair_t>;


Loading…
Cancel
Save