[libvtemm] Corrections to internalroutines and StdStringArrayHandle.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: svn-commits-list gnome org
- Subject: [libvtemm] Corrections to internalroutines and StdStringArrayHandle.
- Date: Wed, 20 May 2009 15:13:46 -0400 (EDT)
commit a61a72da608424424869fadc0e7220ec33a6c363
Author: Krzesimir Nowak <krnowak svn gnome org>
Date: Wed May 20 21:08:41 2009 +0200
Corrections to internalroutines and StdStringArrayHandle.
* src/libvtemm/internalroutines.cc: get_c_string_vector is
rewritten to use changes in StdStringArrayHandle.
* src/libvtemm/shared.h: StdStringArrayHandle have custom traits
now - to_c_type returns 0, when std::string (or Glib::ustring) is
empty.
---
src/libvtemm/internalroutines.cc | 18 +++++++++---------
src/libvtemm/shared.h | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/src/libvtemm/internalroutines.cc b/src/libvtemm/internalroutines.cc
index 32d65b8..cf26144 100644
--- a/src/libvtemm/internalroutines.cc
+++ b/src/libvtemm/internalroutines.cc
@@ -39,22 +39,22 @@ get_c_string(const std::string& cpp_string)
char**
get_c_string_vector(const StdStringArrayHandle& cpp_string_vector)
{
- if (cpp_string_vector.empty() || cpp_string_vector[0].empty())
+ unsigned int cpp_string_vector_size = cpp_string_vector.size();
+ const char* const* data = cpp_string_vector.data();
+ if ((!cpp_string_vector_size) || (!(data[0])))
{
return 0;
}
- unsigned int cpp_string_vector_len = cpp_string_vector.size();
- if (cpp_string_vector[cpp_string_vector_len - 1].empty())
+ if (!(data[cpp_string_vector_size - 1]))
{
- cpp_string_vector_len--;
+ cpp_string_vector_size--;
}
- char** c_string_vector = reinterpret_cast<char**>(g_malloc0(cpp_string_vector_len + 1));
- const char* const * temp_c_string_vector = cpp_string_vector.data();
- for (unsigned int iter = 0; iter < cpp_string_vector_len; iter++)
+ char** dup = reinterpret_cast<char**>(g_malloc0((cpp_string_vector_size + 1) * sizeof(char*)));
+ for (unsigned int iter = 0; iter < cpp_string_vector_size; iter++)
{
- c_string_vector[iter] = g_strdup(temp_c_string_vector[iter]);
+ dup[iter] = g_strdup(data[iter]);
}
- return c_string_vector;
+ return dup;
}
} // namespace Vte
diff --git a/src/libvtemm/shared.h b/src/libvtemm/shared.h
index c83a244..b215c3d 100644
--- a/src/libvtemm/shared.h
+++ b/src/libvtemm/shared.h
@@ -30,7 +30,42 @@ namespace Gnome
namespace Vte
{
-typedef Glib::ArrayHandle<std::string> StdStringArrayHandle;
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+
+struct StdStringNullTraits
+{
+ typedef std::string CppType;
+ typedef const char* CType;
+ typedef char* CTypeNonConst;
+
+ static CType to_c_type(const std::string& str)
+ {
+ return (str.empty()) ? 0 : str.c_str();
+ }
+ static CType to_c_type(const Glib::ustring& str)
+ {
+ return (str.empty()) ? 0 : str.c_str();
+ }
+ static CType to_c_type(CType str)
+ {
+ return str;
+ }
+ static CppType to_cpp_type(CType str)
+ {
+ return (str) ? std::string(str) : std::string();
+ }
+ static void release_c_type(CType str)
+ {
+ g_free(const_cast<CTypeNonConst>(str));
+ }
+};
+
+#endif // DOXYGEN_SHOULD_SKIP_THIS
+
+/** StdStringArrayHandle - when converted to vector holding c strings, every
+ * empty std::string in StdStringArrayHandle is converted to 0.
+ */
+typedef Glib::ArrayHandle<std::string, StdStringNullTraits> StdStringArrayHandle;
} // namespace Vte
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]