eolian-cxx: Added stringshare
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Tue, 21 Jun 2016 19:35:09 +0000 (16:35 -0300)
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Tue, 21 Jun 2016 19:35:09 +0000 (16:35 -0300)
src/bindings/cxx/eo_cxx/eo_cxx_interop.hh
src/lib/eolian_cxx/grammar/type_impl.hpp
src/tests/eolian_cxx/name1_name2_type_generation.c
src/tests/eolian_cxx/name1_name2_type_generation.eo

index 30ce803..570f5c8 100644 (file)
@@ -26,6 +26,10 @@ template <>
 struct in_traits<eina::string_view> { typedef eina::string_view type; };
 template <>
 struct in_traits<eina::string_view const> { typedef eina::string_view const type; };
+template <>
+struct in_traits<eina::stringshare> { typedef eina::stringshare type; };
+template <>
+struct in_traits<eina::stringshare const> { typedef eina::stringshare const type; };
 template <typename T>
 struct in_traits<T&> { typedef T& type; };
 template <typename T>
@@ -129,6 +133,11 @@ void assign_out_impl(efl::eina::string_view* view, const char* string, Tag)
   if(view)
     *view = {string};
 }
+template <typename Tag>
+void assign_out_impl(efl::eina::stringshare& to, const char* from, Tag)
+{
+  to = {from};
+}
 template <typename T>
 void assign_out_impl(T*& lhs, T& rhs, tag<T*, T>) // optional
 {
@@ -462,6 +471,10 @@ inline const char* convert_to_c_impl(efl::eina::stringshare x, tag<const char*,
 {
    return x.c_str();
 }
+inline const char* convert_to_c_impl(efl::eina::stringshare x, tag<const char*, efl::eina::stringshare, true>)
+{
+   return eina_stringshare_ref(x.c_str());
+}
 template <typename T>
 Eina_Promise* convert_to_c_impl(efl::eina::future<T> const&, tag<Eina_Promise*, efl::eina::future<T>const&>)
 {
@@ -625,6 +638,10 @@ T convert_to_return(U* value, tag<T, U*>, typename std::enable_if<is_range<T>::v
   // const should be to the type if value is const
   return T{const_cast<typename std::remove_const<U>::type*>(value)};
 }
+inline eina::stringshare convert_to_return(const Eina_Stringshare* value, tag<const char*, efl::eina::stringshare>)
+{
+  return efl::eina::stringshare(value);
+}
 template <typename T>
 T convert_to_return(const char** /*value*/, tag<const char**, T>, typename std::enable_if<std::is_same<T, efl::eina::string_view*>::value>::type* = 0)
 {
index 2e75e12..3e67d85 100644 (file)
@@ -96,6 +96,12 @@ struct visitor_generate
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
                 return replace_base_type(r, " ::efl::eina::string_view");
               }}
+           , {"stringshare", nullptr, [&]
+              {
+                regular_type_def r = regular;
+                r.base_qualifier.qualifier ^= qualifier_info::is_ref;
+                return replace_base_type(r, " ::efl::eina::stringshare");
+              }}
            , {"generic_value", nullptr, [&]
               { return regular_type_def{" ::efl::eina::value", regular.base_qualifier, {}};
               }}
index 9af748d..322c18c 100644 (file)
@@ -88,6 +88,20 @@ void _name1_name2_type_generation_instringptr(Eo *obj EINA_UNUSED, Type_Generati
 {
   ck_assert_str_eq(*v, "foobar");
 }
+
+void _name1_name2_type_generation_instringshare(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED, const char *v EINA_UNUSED)
+{
+  ck_assert_str_eq(v, "foobar");
+  ck_assert(eina_stringshare_add(v) == v);
+  eina_stringshare_del(v);
+}
+
+void _name1_name2_type_generation_instringshareown(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED, const char * v EINA_UNUSED)
+{
+  ck_assert_str_eq(v, "foobar");
+  eina_stringshare_del(v);
+}
+
 void _name1_name2_type_generation_instringptrown(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED, const char * *v)
 {
   ck_assert_str_eq(*v, "foobar");
@@ -165,6 +179,16 @@ const char * * _name1_name2_type_generation_returnstringptr(Eo *obj EINA_UNUSED,
   return &foobar;
 }
 
+Eina_Stringshare* _name1_name2_type_generation_returnstringshare(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED)
+{
+  return eina_stringshare_add("foobar");
+}
+
+Eina_Stringshare* _name1_name2_type_generation_returnstringshareown(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED)
+{
+  return eina_stringshare_add("foobar");
+}
+
 const char * _name1_name2_type_generation_returnstringown(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED)
 {
   const char foobar[] = "foobar";
@@ -204,6 +228,16 @@ void _name1_name2_type_generation_outintptrownfree(Eo *obj EINA_UNUSED, Type_Gen
 {
 }
 
+void _name1_name2_type_generation_outstringshare(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED, Eina_Stringshare** v)
+{
+  *v = eina_stringshare_add("foobar");
+}
+
+void _name1_name2_type_generation_outstringshareown(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED, Eina_Stringshare** v)
+{
+  *v = eina_stringshare_add("foobar");
+}
+
 void _name1_name2_type_generation_inclassname(Eo *obj EINA_UNUSED, Type_Generation_Data *pd EINA_UNUSED, Name1_Name2_Type_Generation *v EINA_UNUSED)
 {
 }
index e202423..fe2ca5d 100644 (file)
@@ -64,6 +64,16 @@ class Name1.Name2.Type_Generation (Eo.Base)
          @in v: own(ref(string));
        }
      }
+     instringshare {
+       params {
+         @in v: stringshare;
+       }
+     }
+     instringshareown {
+       params {
+         @in v: own(stringshare);
+       }
+     }
      // return
      returnrefint {
        return: ref(int);
@@ -97,6 +107,12 @@ class Name1.Name2.Type_Generation (Eo.Base)
      returnstringownptr {
        return: own(ref(string));
      }
+     returnstringshare {
+        return: stringshare;
+     }
+     returnstringshareown {
+        return: own(stringshare);
+     }
      // out
      outvoidptr {
        params {
@@ -123,6 +139,17 @@ class Name1.Name2.Type_Generation (Eo.Base)
          @out v: free(own(ref(int)), free);
        }
      }
+     outstringshare {
+       params {
+         @out v: stringshare;
+       }
+     }
+     outstringshareown {
+       params {
+         @out v: own(stringshare);
+       }
+     }
+     // classname
      inclassname {
        params {
          @in v: Name1.Name2.Type_Generation;