pdidev / pdi

The PDI Data Interface
https://pdi.dev
BSD 3-Clause "New" or "Revised" License
6 stars 1 forks source link

Setting value of pointer datatype #171

Open jbigot opened 4 years ago

jbigot commented 4 years ago

In GitLab by @ksiero on Apr 2, 2020, 15:02

With @jbigot we have discussed functionality of setting the pointer datatype value from yaml file. We have several cases of using this feature:

  1. Set only the value of the pointer.\ a. NULL pointer value:
metadata:
  pointer_data:
    type: pointer
    subtype: int
plugins:
  set_value:
     on_init:
       - expose:
         - pointer_data: ~

b. copy address from another pointer:

metadata:
  pointer_A: {type: pointer, subtype: int}
  pointer_B: {type: pointer, subtype: int}
plugins:
  set_value:
     on_init:
       - expose:
         - pointer_A: ~ # nullptr
         - pointer_B: $pointer_A  # B points the same place as A
  1. Allocate memory and do a shallow/deep copy:
    metadata:
    pointer_A:
    type: pointer
    subtype: 
      type: record
      buffersize: 8
      members:
        pointer_B:
          disp: 0
          type: pointer
          subtype: int
    pointer_B:
    type: pointer
    subtype: 
      type: record
      buffersize: 8
      members:
        pointer_B:
          disp: 0
          type: pointer
          subtype: int
    plugins:
    set_value:
     on_init:
       - expose:
         - pointer_B: 
             allocate: true
             shallow_copy: pointer_A
         - pointer_B: 
             allocate: true
             deep_copy: pointer_A
     on_event:
       some_event:
         - expose:
           - pointer_B: 
               allocate: false
               shallow_copy: pointer_A
           - pointer_B: 
               allocate: false
               deep_copy: pointer_A
  2. Just allocate memory.
    metadata:
    pointer_data:
    type: pointer
    subtype: int
    plugins:
    set_value:
     on_init:
        - pointer_data: 
            allocate: true  # just allocate memory
  3. Allocate memory and set the values to the subtype.

    metadata:
    scalar_data: int
    pointer_data:
    type: pointer
    subtype: int
    plugins:
    set_value:
     on_init:
        - pointer_data:
            allocate: true         # allocate memory 
            subvalue: $scalar_data # set the value
     on_event:
       some_event:
        - pointer_data:
            allocate: false        # default, memory is allocated
            subvalue: $scalar_data # set the value
    metadata:
    pointer_data:
    type: pointer
    subtype:
      type: array
      size: 4
      subtype: int
    plugins:
    set_value:
     on_init:
        - pointer_data:
            allocate: true         # allocate memory
            subvalue: [0, 0, 0, 0] # set the value
     on_event:
       some_event:
        - pointer_data:
            allocate: false        # default, memory is allocated
            subvalue: [1, 2, 3, 4] # set the value
    metadata:
    pointer_data:
    type: pointer
    subtype:
      type: record
      buffersize: 20
      members:
         member_1:
           disp: 0
           type: int
         member_2:
           disp: 4
           type: array
           size: 4
           subtype: char
    plugins:
    set_value:
     on_init:
       - expose:
         - pointer_data:
            allocate: true  # allocate memory 
            subvalue:       # set the value
              - member_1: 0
              - member_2: "abc"
     on_event:
       some_event:
        - pointer_data:
            allocate: false        # default, memory is allocated
            subvalue:              # set the value
              - member_1: 4
              - member_2: "xyz"

This is my proposition. Any thoughts?

jbigot commented 3 years ago

unassigned @ksiero