+#include <vector>
#include <cassert>
#include <GdomeSmartDOM.hh>
unsigned max_attributes;
unsigned max_depth;
unsigned max_children;
+std::vector<unsigned> depths;
+std::vector<unsigned> widths;
bool
is_blank(const std::string& s)
n_children++;
}
max_children = std::max(max_children, n_children);
+
+ if (!node.get_firstChild())
+ depths.push_back(depth);
+ else
+ widths.push_back(n_children);
}
void
print_results(const std::string& URI)
{
+ unsigned tot_depth = 0;
+ for (std::vector<unsigned>::const_iterator p = depths.begin(); p != depths.end(); p++)
+ tot_depth += *p;
+
+ unsigned tot_width = 0;
+ for (std::vector<unsigned>::const_iterator p = widths.begin(); p != widths.end(); p++)
+ tot_width += *p;
+
std::cout << "<stats for=\"" << URI << "\">" << std::endl;
- std::cout << " <depth>" << max_depth << "</depth>" << std::endl;
+ std::cout << " <depth>" << std::endl;
+ std::cout << " <max>" << max_depth << "</max>" << std::endl;
+ std::cout << " <leaf-avg>" << tot_depth / ((double) depths.size()) << "</leaf-avg>" << std::endl;
+ std::cout << " </depth>" << std::endl;
+ std::cout << " <width>" << std::endl;
+ std::cout << " <max>" << max_children << "</max>" << std::endl;
+ std::cout << " <inner-avg>" << tot_width / ((double) widths.size()) << "</inner-avg>" << std::endl;
+ std::cout << " </width>" << std::endl;
std::cout << " <elements>" << std::endl;
std::cout << " <total>" << n_elements << "</total>" << std::endl;
std::cout << " <leaf>" << n_leaf_elements << "</leaf>" << std::endl;
std::cout << " <total>" << n_attributes << "</total>" << std::endl;
std::cout << " <max>" << max_attributes << "</max>" << std::endl;
std::cout << " </attributes>" << std::endl;
- std::cout << " <children>" << std::endl;
- std::cout << " <max>" << max_children << "</max>" << std::endl;
- std::cout << " </children>" << std::endl;
std::cout << "</stats>" << std::endl;
}
int
main(int argc, char* argv[])
{
+ if (argc != 2) {
+ std::cerr << "Usage: stats <URI>" << std::endl;
+ return -1;
+ }
+
DOM::DOMImplementation di;
DOM::Document doc = di.createDocumentFromURI(argv[1]);
visit(doc, 0);