Sha256: 3c5211bdf237fa58cfa05999d9856ffccabab6d4547ac4795a4f318adf14078d

Contents?: true

Size: 1.84 KB

Versions: 9

Compression:

Stored size: 1.84 KB

Contents

###
# wxRuby3 Common typemap definitions
# Copyright (c) M.J.N. Corino, The Netherlands
###

require_relative '../core/mapping'

module WXRuby3

  module Typemap

    # Typemaps for converting between wxDateTime and Ruby's Date and Time
    # classes. These are used in CalendarCtrl etc
    module DateTime

      include Typemap::Module

      define do

        map 'wxDateTime&' => 'Time,Date,DateTime' do

          add_header_code <<~__CODE
            #ifndef __WXRB_DATETIME_HELPERS__
            #include <wx/datetime.h>
            
            WXRB_EXPORT_FLAG VALUE wxRuby_wxDateTimeToRuby(const wxDateTime& dt);
            
            WXRB_EXPORT_FLAG wxDateTime* wxRuby_wxDateTimeFromRuby(VALUE ruby_value);
            #endif
            __CODE

          # Accepts any Time-like object from Ruby and creates a wxDateTime
          map_in temp: 'std::unique_ptr<wxDateTime> tmp_dt',
                 code: 'tmp_dt.reset(wxRuby_wxDateTimeFromRuby($input)); $1 = tmp_dt.get();'

          # Converts a return value of wxDateTime& to a Ruby Time object
          map_out code: '$result = wxRuby_wxDateTimeToRuby(*$1);'

          map_directorin code: '$input = wxRuby_wxDateTimeToRuby($1);'

          map_typecheck precedence: 'SWIGOBJECT', code: <<~__CODE
            $1 = rb_obj_is_kind_of($input, rb_cTime) || rb_respond_to($input, rb_intern ("to_time"));
            __CODE
        end

        map 'wxDateTime' => 'Time,Date,DateTime' do

          # Converts a return value of wxDateTime to a Ruby Time object
          map_out code: '$result = wxRuby_wxDateTimeToRuby($1);'

          map_directorout temp: 'std::unique_ptr<wxDateTime> tmp_dt', code: <<~__CODE
            tmp_dt.reset(wxRuby_wxDateTimeFromRuby($input));
            $result = *tmp_dt.get();
            __CODE

        end

      end # define

    end # DateTime

  end # Typemap

end # WXRuby3

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
wxruby3-0.9.0.pre.rc.3 rakelib/lib/typemap/datetime.rb
wxruby3-0.9.0.pre.rc.2 rakelib/lib/typemap/datetime.rb
wxruby3-0.9.0.pre.rc.1 rakelib/lib/typemap/datetime.rb
wxruby3-0.9.0.pre.beta.14 rakelib/lib/typemap/datetime.rb
wxruby3-0.9.0.pre.beta.13 rakelib/lib/typemap/datetime.rb
wxruby3-0.9.0.pre.beta.11 rakelib/lib/typemap/datetime.rb
wxruby3-0.9.0.pre.beta.10 rakelib/lib/typemap/datetime.rb
wxruby3-0.9.0.pre.beta.9 rakelib/lib/typemap/datetime.rb
wxruby3-0.9.0.pre.beta.8 rakelib/lib/typemap/datetime.rb