eo-cxx: Fix conversion from char* to std::string
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Fri, 15 Sep 2017 17:53:19 +0000 (14:53 -0300)
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Fri, 15 Sep 2017 17:56:23 +0000 (14:56 -0300)
src/bindings/cxx/eo_cxx/eo_cxx_interop.hh

index 47b11db..0bf92b5 100644 (file)
@@ -749,7 +749,9 @@ inline eina::string_view convert_to_return(const char** value, tag<const char**,
 {
   return {*value};
 }
-inline std::string convert_to_return(const char* value, tag<const char*, std::string>)
+template <typename S>
+inline std::string convert_to_return(const char* value, tag<const char*, S>
+                                     , typename std::enable_if<std::is_same<typename std::remove_cv<S>::type, std::string>::value>::type* = 0)
 {
   if(value)
     {
@@ -760,7 +762,36 @@ inline std::string convert_to_return(const char* value, tag<const char*, std::st
   else
     return {};
 }
-inline std::string convert_to_return(const char** value, tag<const char**, std::string>)
+template <typename S>
+inline std::string convert_to_return(const char** value, tag<const char**, S>
+                                     , typename std::enable_if<std::is_same<typename std::remove_cv<S>::type, std::string>::value>::type* = 0)
+{
+  if(value)
+    {
+       std::string r{*value};
+       free((void*)*value);
+       free((void*)value);
+       return r;
+    }
+  else
+    return {};
+}
+template <typename S>
+inline std::string convert_to_return(char* value, tag<char*, S>
+                                     , typename std::enable_if<std::is_same<typename std::remove_cv<S>::type, std::string>::value>::type* = 0)
+{
+  if(value)
+    {
+       std::string r{value};
+       free((void*)value);
+       return r;
+    }
+  else
+    return {};
+}
+template <typename S>
+inline std::string convert_to_return(char** value, tag<char**, S>
+                                     , typename std::enable_if<std::is_same<typename std::remove_cv<S>::type, std::string>::value>::type* = 0)
 {
   if(value)
     {