Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
5 replies Latest Post - ‏2013-11-12T12:58:28Z by PatrickGuay
PatrickGuay
PatrickGuay
89 Posts
ACCEPTED ANSWER

Pinned topic Casting a skip into a DxlObject

‏2013-11-11T15:45:34Z |

Hi, 

What is the deal with DxlObjects, there is absolutely no documentation on this data structure in the 9.5 reference manual.

I am trying to recuperate the contents of a DxlObject that I have stored in a skipList.using the following syntax:

DxlObject currDiscussion = skip_post_snapshot_disc[keyStr] DxlObject

However this give me an error message: "incorrect context for binary op ([)"

 

Previously (in a different script) I was able to recuperate the contents of a DxlObject from a skip using a for loop 

DxlObject hist = new

for hist in skipHistory do
{

...

}

 

So what's the deal with trying to grab it by directly casting?

Thanks to anyone who can provide info on a subject that never existed... 

Patrick

 

  • Mathias Mamsch
    Mathias Mamsch
    1946 Posts
    ACCEPTED ANSWER

    Re: Casting a skip into a DxlObject

    ‏2013-11-11T19:26:52Z  in response to PatrickGuay

    Well first of all, you need to know, that DxlObjects are exactly the same as Skip lists with a string key. DxlObjects are a syntax play, trying to mimic objects in other scripting languages. So the code:

    Skip sk = createString();
    put (sk, "Hello", "World!");

    is exactly equal to:

    DxlObject sk = new();
    sk->"Hello" = "World!";

    My guess is, that since DXL has always had problems with functions returning different types (like the Array get) function, which can lead to crashes if used badly, Telelogic figured to never officially support DxlObjects. Maybe they simply got forgotten as a new development in some version and not documented since (like a lot of other DXL).

    So: DxlObjects are really nothing more than a String-Skip and a try to make DXL look a little nicer.

    Anyway regarding type casting (which you can do for example with the addr_ function) you should know that is only useful in a couple of situations. One of it is Pseudo-Object-Oriented DXL where you can use DxlObjects as a basetype for your objects. Normally you then declare your own data-type and take a DxlObject and cast it to that type.

    The other advantages of DxlObjects is, that you can inline the find() result in an expression. So for example you can write:

    Skip sk = createString();
    put (sk, "Hello", "World!");
    print "Finding Hello: " ((((addr_ sk) DxlObject)->"Hello") string) "\n"

    which for a Skip list you would have to write:

    Skip sk = createString();
    put(sk, "Hello", "World!");
    string s = null;
    find (sk, "Hello", s);
    print "Finding Hello: " s "\n";

    So obviously the second form is much nicer to read, although you have to write more code. You can of course get the key/value pairs from a DxlObject by iterating over it as a skip list. I used that for cloning class objects in some function, without having to hardcode their properties:

    DxlObject dx = new();
    dx->"Hello" = "World!";
    dx->"World" = "Dude!";

    string sValue, sKey;
    Skip sk = addr_ dx;
    for sValue in sk do {
       string sKey = (key sk) string; 
       print "Key: " sKey " Value: " sValue "!\n";
    }

    Regards, Mathias

    Updated on 2013-11-11T19:32:12Z at 2013-11-11T19:32:12Z by Mathias Mamsch
    • PatrickGuay
      PatrickGuay
      89 Posts
      ACCEPTED ANSWER

      Re: Casting a skip into a DxlObject

      ‏2013-11-11T20:03:59Z  in response to Mathias Mamsch

      Mathias, I agree with what you are saying, however, it seems a little strange that a skip can be placed within multiple levels of skips and that we can access any sublevel skips with the appropriate cast (as long as we know the key of the n-level skip) however we cannot do the same for DxlObjects considering they are the same thing.

      // This is legal

      for Skip_value in reqConds_copy do {
              keyValue = (int key reqConds_copy)
              reqInfo_skip = reqConds_copy[keyValue] Skip;

      // we could go on and on and on here unpilling skips by simply extracting skips in this fashion

      }

       

      // This is NOT legal

      for Skip_value in reqConds_copy do {
              keyValue = (int key reqConds_copy)
              DxlObject obj = reqConds_copy[keyValue] DxlObject;

       

      }

       

      For the time being I have gone back to storing a complex data structure by embedding skips inside of skips. I saw someone write that DXL is "c--"s dumb cousin, i guess DxlObjects are an afterthought.

      PG

       

       

       

      • llandale
        llandale
        2943 Posts
        ACCEPTED ANSWER

        Re: Casting a skip into a DxlObject

        ‏2013-11-11T21:37:02Z  in response to PatrickGuay

        I could not make your "legal" code work.  Adding declarations:

        // This is legal
        Skip reqConds_copy = create()
        Skip  reqInfo_skip
        string Skip_value
        int keyValue

        for Skip_value in reqConds_copy do {
                keyValue = (int key reqConds_copy)
                reqInfo_skip = reqConds_copy[keyValue] Skip;
        // we could go on and on and on here unpilling skips by simply extracting skips in this fashion

        }

        I do have a couple monster scripts that have Skips inside of other Skips; but they all do this:

        • for skpMiddle in skpOuter do
        • {  for skpInner in skpMiddle do

        -Louie

    • llandale
      llandale
      2943 Posts
      ACCEPTED ANSWER

      Re: Casting a skip into a DxlObject

      ‏2013-11-11T21:43:11Z  in response to Mathias Mamsch

      Did not occur to me the physical similarity of Skips and DxlObjects thanks, but I will say that conceptually the DXLO "Fields" should tend to be fixed by the coder and not dynamic data inserted at run time; and are more like stone-age "Structures".  And the DXLOs themselves tend to be dynamic (created, one per some real world item) where as "Skips" tend to be hard coded in the script.

  • PatrickGuay
    PatrickGuay
    89 Posts
    ACCEPTED ANSWER

    Re: Casting a skip into a DxlObject

    ‏2013-11-12T12:58:28Z  in response to PatrickGuay

    Thanks for your feedback. For the time being I have embedded a skip within a skip in order to achieve the same result.