2

I'm trying to modify autoexp.dat to write a visualizer and I'm only partly achieving what I want. I have a class (below) where Bar1 and Bar2 are dynamically allocated arrays

class Foo
{
   double* Bar1;
   double* Bar2;
   int size;
}

and the visualizer in the [Visualizer] section of autoexp.dat that I've come up with looks like

Foo{
    children
    (
        #(
            [size]: [$c.size],

            #(
                    [Bar1]: #array(expr: $c.Bar1[$i], size: $c.size)
             ),
            #(
                    [Bar2]: #array(expr: $c.Bar2[$i], size: $c.size)
            )
        )
    )
}

Unfortunately, the output for this is

Foo
    [size] 24
    [Bar1] 1
    [Bar1] 1
    .
    .
    [Bar1] 1
    [Bar2] 0
    [Bar2] 0
    .
    .
    [Bar2] 0

I would like it to show

Foo
    [size] 24
    [Bar1]
         [0] 1
         [1] 1
          .
          .
         [23] 1
    [Bar2]
         [0] 0
         [1] 0
          .
          .
         [23] 0

where Bar1 and Bar2 are collapsible, but more importantly I have the indices.

2 Answers 2

2
+200

Extending the suggestion from @IronMensan, you could use a switch statement to get around the dynamic size limitation, perhaps using a suitable length as the default to avoid the switch getting too long...

Foo{
    children(
        #(
            #([size]: [$c.size]),
            #(
                #switch ($c.size)
                #case  0 (  #(Bar1: [$c.Bar1,  0])  )
                #case  1 (  #(Bar1: [$c.Bar1,  1])  )
                #case  2 (  #(Bar1: [$c.Bar1,  2])  )
                #case  3 (  #(Bar1: [$c.Bar1,  3])  )
                #case  4 (  #(Bar1: [$c.Bar1,  4])  )
                #case  5 (  #(Bar1: [$c.Bar1,  5])  )

                #default (  #(Bar1: [$c.Bar1, 50])  )
            ),
            #(
                #switch ($c.size)
                #case  0 (  #(Bar2: [$c.Bar2,  0])  )
                #case  1 (  #(Bar2: [$c.Bar2,  1])  )
                #case  2 (  #(Bar2: [$c.Bar2,  2])  )
                #case  3 (  #(Bar2: [$c.Bar2,  3])  )
                #case  4 (  #(Bar2: [$c.Bar2,  4])  )
                #case  5 (  #(Bar2: [$c.Bar2,  5])  )

                #default (  #(Bar2: [$c.Bar2, 50])  )
            )
        )
    )
}
Sign up to request clarification or add additional context in comments.

Comments

1

The only way I know how to make Bar1 and Bar2 collapsable won't allow you to use a dynamic size:

Foo{
    children
    (
        #(
            [size]: [$c.size],
            [Bar1]: [$c.Bar1,30],
            [Bar2]: [$c.Bar2,30]
        )
    )
}

You could do something with multi-demensional arrays like this:

Foo {
    children
    (
        #(
            [size]: [$c.size],

            #array(expr: (0==$i/$c.size)*$c.Bar1[$i]+(1==$i/$c.size)*$c.Bar2[$i-$c.size], rank: 2, size: ($r==1)*$c.size+($r==0)*2)
        )
    )
}

This will list the members as:

[0,0] (value of Bar1[0])
[0,1] (value of Bar1[1])
...
[0,N] (value of Bar1[N])
[1,0] (value of Bar2[0])
...

Another way is to do this:

Foo {
    children
    (
        #(
            [size]: [$c.size],

            #array(expr: (0==$i%2)*$c.Bar1[$i/2]+(1==$i%2)*$c.Bar2[$i/2], rank: 2, size: ($r==0)*$c.size+($r==1)*2)
        )
    )
}

This will interleave the values like this:

[0,0] (value of Bar1[0])
[1,0] (value of Bar2[0])
[0,1] (value of Bar1[1])
[1,1] (value of Bar2[1])
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.