矩阵显示行

问题描述 投票:1回答:1

我知道默认的ArrayItems-Tag可以处理矩阵,但我发现结果不够。

给出这个例子

#include <cstdlib>
#include <cstdio>

struct matrix {
  int height;
  int width;
  double* values;
};

int main() {
  double* values = (double*)malloc(5 * 2 * sizeof(double));
  for (int i = 0; i < 10; ++i) values[i] = i * 2;
  matrix m = { 5, 2, values };

  return 0;
}

有了这个natvis

<?xml version="1.0" encoding="utf-8"?> 
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <Type Name="matrix">
    <DisplayString>{{Shape [{height} x {width}]}}</DisplayString>
    <Expand>
        <CustomListItems>
          <Variable Name="i" InitialValue="0" />
          <Loop>
            <Break Condition="i == height" />
            <Item>(values + (i * width)), 2</Item>
            <Exec>i++</Exec>
          </Loop>
        </CustomListItems>
      </Expand>
  </Type>
</AutoVisualizer>

结果是这样的输出,近乎完美。enter image description here

  • 我希望不要显示地址
  • 我希望我可以给元素一个自定义的格式指定器(比如%.2f)。

但我在我的natvis中作弊了。我写了 <Item>(values + (i * width)), 2</Item> 2为行的宽度。但如果我写 width 而不是2,它输出的是2而不是行。显然它打印的是 width但这并没有帮助。

enter image description here

有谁知道如何使这些行的大小可变?

visual-studio visual-studio-debugging natvis
1个回答
1
投票

试试 [width] nag:

<Item>(values + (i * width)), [width] nag</Item>
  • 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: 负责人: [size] - 扩充固定尺寸阵列。
  • na - "无地址"--压制地址。
  • g - 以便更好地查看浮点数据。
© www.soinside.com 2019 - 2024. All rights reserved.