Topic
  • 1 reply
  • Latest Post - ‏2013-09-09T15:58:57Z by s.st1led
s.st1led
s.st1led
2 Posts

Pinned topic [.NET] Programmatically add an array value to a tuple

‏2013-09-05T15:37:08Z |

Hi everybody, I'm trying to programmatically assign integer user-defined values for an array field of a tuple using the .NET APIs, but got stuck. I'm pretty sure the method I should use is ITupleBuffer.SetIntMapValue(), but the second argument taken is an IIntMap that I have no clue how to get.

For instance, for a string or integer field I just use the methods SetIntValue() or SetSymbolValue() whose second arguments are integers and strings. For a set field, I would use SetIntCollectionValue(), whose second argument is an IIntCollection that I can compute from CP.IntSet() that takes an int[] as parameter.

Unfortunately, there is no CP.IntMap(). The closer I can get is a CP.IntArray() that I can manually fill with the values in my integer array, but the IntArray doesn't implement the IIntMap interface.

What's the standard practice I should follow?

 

Regards,

Stefano

 

  • s.st1led
    s.st1led
    2 Posts
    ACCEPTED ANSWER

    Re: [.NET] Programmatically add an array value to a tuple

    ‏2013-09-09T15:58:57Z  

    For those interested, I found a workaround, that requires to already have an instance of a tuple you want to create in a OplDataSource (or an OplDataElements created from an OplDataSource). The OplDatSource should be created from a data file where the tuple has been instanced: you don't have to care for the values of the tuple fields, since they will be re-assigned.

    First, you need to retrieve a TupleBuffer via MakeTupleBuffer(i), where i stands for an index of an actual tuple in a TupleSet (and not -1, like if you want to create a new one). Then the IIntMap object can be retrieved via GetIntMapValue(). Finally, you can set the values in the IIntMap via Set() and then assign the IIntMap object to the TupleBuffer via SetIntMapValue().

    It's a bit counter-intuitive to have to "get" something in order to "create" it, but I couldn't find any other way.

     

    Regards,

    Stefano

  • s.st1led
    s.st1led
    2 Posts

    Re: [.NET] Programmatically add an array value to a tuple

    ‏2013-09-09T15:58:57Z  

    For those interested, I found a workaround, that requires to already have an instance of a tuple you want to create in a OplDataSource (or an OplDataElements created from an OplDataSource). The OplDatSource should be created from a data file where the tuple has been instanced: you don't have to care for the values of the tuple fields, since they will be re-assigned.

    First, you need to retrieve a TupleBuffer via MakeTupleBuffer(i), where i stands for an index of an actual tuple in a TupleSet (and not -1, like if you want to create a new one). Then the IIntMap object can be retrieved via GetIntMapValue(). Finally, you can set the values in the IIntMap via Set() and then assign the IIntMap object to the TupleBuffer via SetIntMapValue().

    It's a bit counter-intuitive to have to "get" something in order to "create" it, but I couldn't find any other way.

     

    Regards,

    Stefano