[glibmm] gmmproc: Add NULL option to _WRAP_METHOD



commit de3b3fa11ef8da622c2752be08e0b789eaf42572
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu Feb 4 15:11:02 2016 +0100

    gmmproc: Add NULL option to _WRAP_METHOD
    
    * tools/pm/Function.pm:
    * tools/pm/Output.pm: Accept {NULL} or {!NULL} after the name of a string
    parameter in _WRAP_METHOD. It specifies how to translate an empty string to
    a C string. {NULL}: nullptr, {!NULL}: pointer to an empty string.
    Both {NULL} and {!NULL} can be useful, because the default translation is
    different for mandatory and optional ({?}) parameters.

 tools/pm/Function.pm |   16 +++++++++++++---
 tools/pm/Output.pm   |   12 +++++++++---
 2 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/tools/pm/Function.pm b/tools/pm/Function.pm
index 728187b..d3cd8ea 100644
--- a/tools/pm/Function.pm
+++ b/tools/pm/Function.pm
@@ -5,10 +5,13 @@ use warnings;
 use Util;
 use FunctionBase;
 
-# These are flags that indicate whether parameters are optional or output
-# parameters.
+# These flags indicate whether parameters are optional or output parameters.
 use constant FLAG_PARAM_OPTIONAL => 1;
 use constant FLAG_PARAM_OUTPUT => 2;
+# These flags indicate how an empty string shall be translated to a C string:
+# to a nullptr or to a pointer to an empty string.
+use constant FLAG_PARAM_NULLPTR => 4;
+use constant FLAG_PARAM_EMPTY_STRING => 8;
 
 BEGIN {
      use Exporter   ();
@@ -21,7 +24,8 @@ BEGIN {
      %EXPORT_TAGS = ( );
      # your exported package globals go here,
      # as well as any optionally exported functions
-     @EXPORT_OK   = qw($Var1 %Hashit &func3 FLAG_PARAM_OPTIONAL FLAG_PARAM_OUTPUT);
+     @EXPORT_OK   = qw($Var1 %Hashit &func3 FLAG_PARAM_OPTIONAL FLAG_PARAM_OUTPUT
+                       FLAG_PARAM_NULLPTR FLAG_PARAM_EMPTY_STRING);
      }
 our @EXPORT_OK;
 
@@ -238,6 +242,12 @@ sub parse_param($$)
       $flags = FLAG_PARAM_OPTIONAL if($options =~ /\?/);
       $flags |= FLAG_PARAM_OUTPUT if($options =~ />>/);
 
+      # Delete "NULL" from $options, so it won't be interpreted as a parameter name.
+      if ($options =~ s/(!?\bNULL\b)//)
+      {
+        $flags |= ($1 eq "!NULL") ? FLAG_PARAM_EMPTY_STRING : FLAG_PARAM_NULLPTR;
+      }
+
       # Check if it should be mapped to a C param.
       if ($options =~ /(\w+|\.)/)
       {
diff --git a/tools/pm/Output.pm b/tools/pm/Output.pm
index ef18385..610ab15 100644
--- a/tools/pm/Output.pm
+++ b/tools/pm/Output.pm
@@ -19,7 +19,8 @@
 package Output;
 use strict;
 use open IO => ":utf8";
-use Function qw(FLAG_PARAM_OPTIONAL FLAG_PARAM_OUTPUT);
+use Function qw(FLAG_PARAM_OPTIONAL FLAG_PARAM_OUTPUT FLAG_PARAM_NULLPTR
+                FLAG_PARAM_EMPTY_STRING);
 
 use DocsParser;
 
@@ -1265,8 +1266,13 @@ sub convert_args_cpp_to_c($$$$$)
             $cppParamName,
             $wrap_line_number);
 
-      if (($$cpp_param_flags[$cpp_param_index] & FLAG_PARAM_OPTIONAL) &&
-       $cppParamType =~ /^(const\s+)?(std::string|Glib::ustring)&?/)
+      # Shall an empty string be translated to a nullptr or to a pointer to
+      # an empty string? The default is "pointer to an empty string" for
+      # mandatory parameters, nullptr for optional parameters.
+      if (($$cpp_param_flags[$cpp_param_index] & FLAG_PARAM_NULLPTR) ||
+        (($$cpp_param_flags[$cpp_param_index] &
+         (FLAG_PARAM_OPTIONAL | FLAG_PARAM_EMPTY_STRING)) == FLAG_PARAM_OPTIONAL && # OPTIONAL and not 
EMPTY_STRING
+        $cppParamType =~ /^(const\s+)?(std::string|Glib::ustring)&?/))
       {
         push(@conversions, "$cppParamName.empty() ? nullptr : " . $std_conversion);
       }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]