0

I would like to convert a struct from c source code (same file) (which can include more structs of structs) and I would like to walk that "structure". Is there an optimal way to do this? Some sort of Tree class that I could convert to a graphical tree would be nice. At the farthest "leaf" struct, I'll want to be able to access the struct members also, not just the tree structure of the structs. I'm open to any algorithms. This strikes me as a recursive type algorithm. I just don't want to waste time reinventing the wheel. No it's not homework, but it is work related :) . If any knows of preexisting tools that already do this. I can provide more details below if anyone needs them.

dude
  • 1,321
  • 2
  • 10
  • 7
  • Uhh.. can you rephrase the question? – Wug Nov 07 '12 at 16:40
  • It strikes me as a recursive algorithm as well, but everything is too vague to say anything more. It's easier to post code than describe code, so post the code. – john Nov 07 '12 at 16:41
  • 2
    do you mean in the sense of the visitor pattern, or in the sense of documenting your source code? – Ian Nov 07 '12 at 16:41
  • If you are just looking for some ways to handle n-ary tree data structures, this question has some great answers adressing this: http://stackoverflow.com/questions/205945/why-does-the-c-stl-not-provide-any-tree-containers – femtoRgon Nov 07 '12 at 16:46
  • basically if I have struct a { typeX b; c_struct c; typeZ d } a_struct;" and then typeY c is further defined as - struct c { typeK k, typeL l } c_struct. I would like to create a tree data structure of that. I figured there might already be some c or c++ indexing code out there that does this already, preferably public_domain :) . I will look into the visitor pattern [lan], and thanks for the stackoverflow reference femtoRgon. – dude Nov 07 '12 at 17:15

1 Answers1

0

If you are just documenting your code, I recommend using doxygen software.

If you are to parse your code file, take a look at boost libraries:

This example might give you some motivation.

For graphic displaying I can't recommend anything c++ but maybe NodeBox which is based on boost.

Nevertheless, C++ is probably not the right tool of choice for tasks like this. Try rather (say) python.

As a last option, you can also go and do your own recursive traverser and output your data into an / that can be read by some graph displaying program.

Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91