Appendix B C API Code Samples

prevnext

Report Project Metrics


Description

This example reports the project-level metrics from an Understand for C++ database. Refer to udbMetricProject for a complete description of all project level metrics available for all supported languages.

Sample Code

 1	 static void reportProjectMetrics() {
 2	    UdbLanguage language;
 3	    language = udbDbLanguage();
 4	    if ((language & Udb_mask_language) == Udb_languageC)  {
 5	       printf ("\nProject Metrics:\n");
 6	       printf ("Number of Classes: %ld\n",
 7	                   ubMetricProject(Udb_cProjMetricCountClass) );
 8	       printf ("Number of Files: %ld\n", 
 9	                   udbMetricProject(Udb_cProjMetricCountFile) );
 10	       printf ("Number of Functions: %ld\n", 
 11	                   udbMetricProject(Udb_cProjMetricCountFunction) );
 12	       printf ("Number of Lines: %ld\n", 
 13	                   udbMetricProject(Udb_cProjMetricCountLine) );
 14	       printf ("Number of Blank Lines: %ld\n", 
 15	                   udbMetricProject(Udb_cProjMetricCountLineBlank) );
 16	       printf ("Number of Lines of Code: %ld\n", 
 17	                   udbMetricProject(Udb_cProjMetricCountLineCode) );
 18	       printf ("Number of Comment Lines: %ld\n", 
 19	                   udbMetricProject(Udb_cProjMetricCountLineComment) );
 20	       printf ("Ratio of Comment lines to Code lines: %ld\n", 
 21	                   udbMetricProject(Udb_cProjMetricRatioCommentCode) );
 22	    }
 23	 }

Explanation of Sample Code

line 3: Get the language of the current database. This is optional and is done only to confirm that an Understand for C++ database has been opened.

line 4: Check that the database language is C.

line 5: Print header.

lines 6-21: Print each project level metric. Each call to udbMetricProject() returns the requested project metric.

Sample Output

 Project Metrics:
 Number of Classes: 44
 Number of Files: 119
 Number of Functions: 456
 Number of Lines: 18050
 Number of Blank Lines: 2779
 Number of Lines of Code: 11951
 Number of Comment Lines: 4299
 Ratio of Comment lines to Code lines: 35

prevnext


Scientific Toolworks, Inc.
http://www.scitools.com
Voice: (802) 763-2995
Fax: (802) 763-3066
support@scitools.com
sales@scitools.com