00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <UT/UT_NTStreamUtil.h>
00032 #include <UT/UT_IStream.h>
00033 #include <CMD/CMD_Args.h>
00034 #include <PI/PI_ResourceManager.h>
00035 #include <MOT/MOT_Director.h>
00036
00037 static int verbose = 0;
00038
00039 static void
00040 printIndent(int indent)
00041 {
00042 while (indent > 0)
00043 {
00044 cout << " ";
00045 indent--;
00046 }
00047 }
00048
00049 static void
00050 printNode(OP_Node *node, OP_Node *input, int indent)
00051 {
00052 int i, noutputs;
00053 OP_Node *out;
00054
00055 printIndent(indent);
00056 cout << node->getName();
00057 if (input)
00058 cout << " is wired to " << input->getName();
00059 cout << endl;
00060
00061
00062 noutputs = node->nOutputs();
00063 for (i = 0; i < noutputs; i++)
00064 {
00065 out = node->getOutput(i);
00066 printNode(out, node, indent+1);
00067 }
00068 }
00069
00070 static void
00071 printNetwork(OP_Network *net, int indent = 0)
00072 {
00073 int i, nkids;
00074 OP_Node *node;
00075 OP_Network *kidnet;
00076
00077
00078
00079
00080 nkids = net->getNchildren();
00081 for (i = 0; i < nkids; i++)
00082 {
00083 node = net->getChild(i);
00084
00085
00086
00087 if (node->nInputs() == 0)
00088 printNode(node, 0, indent);
00089 }
00090
00091
00092
00093
00094 for (i = 0; i < nkids; i++)
00095 {
00096 node = net->getChild(i);
00097 if (node->isNetwork())
00098 {
00099
00100 kidnet = (OP_Network *)node;
00101 if (kidnet->getNchildren())
00102 {
00103 printIndent(indent+1);
00104 cout << kidnet->getName() << " contains:" << endl;
00105 printNetwork(kidnet, indent+2);
00106 }
00107 }
00108 }
00109 }
00110
00111 int
00112 main(int argc, char *argv[])
00113 {
00114 CMD_Args args;
00115 MOT_Director *boss;
00116 int i;
00117
00118 boss = new MOT_Director("traverse");
00119 OPsetDirector(boss);
00120 PIcreateResourceManager();
00121
00122 args.initialize(argc, argv);
00123 args.stripOptions("v");
00124
00125 if (args.found('v'))
00126 verbose = 1;
00127
00128
00129 for (i = 1; i < args.argc(); i++)
00130 {
00131 UT_IFStream is;
00132 if (is.open(args(i), UT_ISTREAM_ASCII))
00133 {
00134
00135 if (verbose)
00136 cout << "Loading: " << args(i) << endl;
00137 if (!boss->loadNetwork(is, 1))
00138 cerr << "Error loading network for " << args(i) << endl;
00139 }
00140 }
00141
00142 if (verbose)
00143 cout << "Traversing the HIP file(s)" << endl;
00144
00145 printNetwork(boss);
00146
00147 return 0;
00148 }