Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/addon/doxmlparser/examples/metrics/main.cpp

Source at commit 1322 created 9 years 5 months ago.
By meklort, Add doxygen to utils folder
1/******************************************************************************
2 *
3 * $Id: $
4 *
5 *
6 * Copyright (C) 1997-2006 by Dimitri van Heesch.
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation under the terms of the GNU General Public License is hereby
10 * granted. No representations are made about the suitability of this software
11 * for any purpose. It is provided "as is" without express or implied warranty.
12 * See the GNU General Public License for more details.
13 *
14 */
15
16/*! \mainpage Metrics
17 * This is a small example that shows how to use doxygen's XML output and
18 * the doxmlparser library. The example shows some very basic code metrics.
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <doxmlintf.h>
25
26bool isDocumented(IDocRoot *brief,IDocRoot *detailed)
27{
28 bool found=false;
29 if (brief)
30 {
31 IDocIterator *docIt = brief->contents();
32 if (docIt->current()) // method has brief description
33 {
34 found=true;
35 }
36 docIt->release();
37 }
38 if (detailed && !found)
39 {
40 IDocIterator *docIt = detailed->contents();
41 if (docIt->current())
42 {
43 found=true;
44 }
45 docIt->release();
46 }
47 return found;
48}
49
50int main(int argc,char **argv)
51{
52 if (argc!=2)
53 {
54 printf("Usage: %s xml_output_dir\n",argv[0]);
55 exit(1);
56 }
57
58 int numClasses=0;
59 int numDocClasses=0;
60 int numStructs=0;
61 int numUnions=0;
62 int numInterfaces=0;
63 int numExceptions=0;
64 int numNamespaces=0;
65 int numFiles=0;
66 int numGroups=0;
67 int numPages=0;
68 int numPackages=0;
69 int numPubMethods=0;
70 int numProMethods=0;
71 int numPriMethods=0;
72 int numDocPubMethods=0;
73 int numDocProMethods=0;
74 int numDocPriMethods=0;
75 int numFunctions=0;
76 int numAttributes=0;
77 int numVariables=0;
78 int numDocFunctions=0;
79 int numDocAttributes=0;
80 int numDocVariables=0;
81 int numParams=0;
82
83 IDoxygen *dox = createObjectModel();
84
85 dox->setDebugLevel(0);
86
87 if (!dox->readXMLDir(argv[1]))
88 {
89 printf("Error reading %s/index.xml\n",argv[1]);
90 exit(1);
91 }
92
93 ICompoundIterator *cli = dox->compounds();
94 ICompound *comp;
95 for (cli->toFirst();(comp=cli->current());cli->toNext())
96 {
97 printf("Processing %s...\n",comp->name()->latin1());
98 bool hasDocs = isDocumented(comp->briefDescription(),comp->detailedDescription());
99 switch (comp->kind())
100 {
101 case ICompound::Class:
102 numClasses++;
103 if (hasDocs) numDocClasses++;
104 break;
105 case ICompound::Struct: numStructs++; break;
106 case ICompound::Union: numUnions++; break;
107 case ICompound::Interface: numInterfaces++; break;
108 case ICompound::Exception: numExceptions++; break;
109 case ICompound::Namespace: numNamespaces++; break;
110 case ICompound::File: numFiles++; break;
111 case ICompound::Group: numGroups++; break;
112 case ICompound::Page: numPages++; break;
113 default: break;
114 }
115
116 ISectionIterator *sli = comp->sections();
117 ISection *sec;
118 for (sli->toFirst();(sec=sli->current());sli->toNext())
119 {
120 IMemberIterator *mli = sec->members();
121 IMember *mem;
122 for (mli->toFirst();(mem=mli->current());mli->toNext())
123 {
124 IParamIterator *pli = mem->parameters();
125 IParam *par;
126 if (comp->kind()==ICompound::Class ||
127 comp->kind()==ICompound::Struct ||
128 comp->kind()==ICompound::Interface
129 )
130 {
131 if (mem->kind()==IMember::Function ||
132 mem->kind()==IMember::Prototype ||
133 mem->kind()==IMember::Signal ||
134 mem->kind()==IMember::Slot ||
135 mem->kind()==IMember::DCOP
136 ) // is a "method"
137 {
138 if (mem->section()->isPublic())
139 {
140 numPubMethods++;
141 if (isDocumented(mem->briefDescription(),mem->detailedDescription()))
142 {
143 numDocPubMethods++;
144 }
145 }
146 else if (mem->section()->isProtected())
147 {
148 numProMethods++;
149 if (isDocumented(mem->briefDescription(),mem->detailedDescription()))
150 {
151 numDocProMethods++;
152 }
153 }
154 else if (mem->section()->isPrivate())
155 {
156 numPriMethods++;
157 if (isDocumented(mem->briefDescription(),mem->detailedDescription()))
158 {
159 numDocPriMethods++;
160 }
161 }
162 }
163 else if (mem->kind()==IMember::Variable ||
164 mem->kind()==IMember::Property
165 ) // is an "attribute"
166 {
167 numAttributes++;
168 if (isDocumented(mem->briefDescription(),mem->detailedDescription()))
169 {
170 numDocAttributes++;
171 }
172 }
173 }
174 else if (comp->kind()==ICompound::File ||
175 comp->kind()==ICompound::Namespace
176 )
177 {
178 if (mem->kind()==IMember::Function ||
179 mem->kind()==IMember::Prototype ||
180 mem->kind()==IMember::Signal ||
181 mem->kind()==IMember::Slot ||
182 mem->kind()==IMember::DCOP
183 ) // is a "method"
184 {
185 numFunctions++;
186 if (isDocumented(mem->briefDescription(),mem->detailedDescription()))
187 {
188 numDocFunctions++;
189 }
190 }
191 else if (mem->kind()==IMember::Variable ||
192 mem->kind()==IMember::Property
193 ) // is an "attribute"
194 {
195 numVariables++;
196 if (isDocumented(mem->briefDescription(),mem->detailedDescription()))
197 {
198 numDocVariables++;
199 }
200 }
201 }
202
203 for (pli->toFirst();(par=pli->current());pli->toNext())
204 {
205 numParams++;
206 }
207 const char *type = mem->typeString()->latin1();
208 if (type && strcmp(type, "void"))
209 {
210 numParams++; // count non-void return types as well
211 }
212 pli->release();
213 }
214 mli->release();
215 }
216 sli->release();
217
218 comp->release();
219 }
220 cli->release();
221
222 dox->release();
223
224 int numMethods = numPubMethods+numProMethods+numPriMethods;
225 int numDocMethods = numDocPubMethods+numDocProMethods+numDocPriMethods;
226
227 printf("Metrics:\n");
228 printf("-----------------------------------\n");
229 if (numClasses>0) printf("Classes: %10d (%d documented)\n",numClasses,numDocClasses);
230 if (numStructs>0) printf("Structs: %10d\n",numStructs);
231 if (numUnions>0) printf("Unions: %10d\n",numUnions);
232 if (numInterfaces>0) printf("Interfaces: %10d\n",numInterfaces);
233 if (numExceptions>0) printf("Exceptions: %10d\n",numExceptions);
234 if (numNamespaces>0) printf("Namespaces: %10d\n",numNamespaces);
235 if (numFiles>0) printf("Files: %10d\n",numFiles);
236 if (numGroups>0) printf("Groups: %10d\n",numGroups);
237 if (numPages>0) printf("Pages: %10d\n",numPages);
238 if (numPackages>0) printf("Packages: %10d\n",numPackages);
239 if (numMethods>0) printf("Methods: %10d (%d documented)\n",numMethods,numDocMethods);
240 if (numPubMethods>0) printf(" Public: %10d (%d documented)\n",numPubMethods,numDocPubMethods);
241 if (numProMethods>0) printf(" Protected: %10d (%d documented)\n",numProMethods,numDocProMethods);
242 if (numPriMethods>0) printf(" Private: %10d (%d documented)\n",numPriMethods,numDocPriMethods);
243 if (numFunctions>0) printf("Functions: %10d (%d documented)\n",numFunctions,numDocFunctions);
244 if (numAttributes>0) printf("Attributes: %10d (%d documented)\n",numAttributes,numDocAttributes);
245 if (numVariables>0) printf("Variables: %10d (%d documented)\n",numVariables,numDocVariables);
246 if (numParams>0) printf("Params: %10d\n",numParams);
247 printf("-----------------------------------\n");
248 if (numClasses>0) printf("Avg. #methods/compound: %10f\n",(double)numMethods/(double)numClasses);
249 if (numMethods>0) printf("Avg. #params/method: %10f\n",(double)numParams/(double)numMethods);
250 printf("-----------------------------------\n");
251
252 return 0;
253}
254
255

Archive Download this file

Revision: 1322