CCCC - C and C++ Code Counter  9999-git
CCCC Development version (post-3.1.4)
cccc_met.cc
Go to the documentation of this file.
1 /*
2  CCCC - C and C++ Code Counter
3  Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com)
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 // cccc_met.cc
20 
21 #include "cccc.h"
22 #include "cccc_itm.h"
23 #include "cccc_met.h"
24 #include <sstream>
25 using std::ostringstream;
26 
27 #include "cccc_opt.h"
28 
29 extern const char *internal_treatments[];
30 
32 {
36  width=0;
37  precision=0;
38 
39  string option_dummy, treatment_dummy, lothresh_str,
40  hithresh_str, numthresh_str, width_str, precision_str;
41 
42  if(
43  // treatment_line.Extract(option_dummy) &&
44  // treatment_line.Extract(treatment_dummy) &&
45  treatment_line.Extract(code) &&
46  treatment_line.Extract(lothresh_str) &&
47  treatment_line.Extract(hithresh_str) &&
48  treatment_line.Extract(numerator_threshold) &&
49  treatment_line.Extract(width) &&
50  treatment_line.Extract(precision) &&
51  treatment_line.Extract(name)
52  )
53  {
54  lower_threshold=atof(lothresh_str.c_str());
55  upper_threshold=atof(hithresh_str.c_str());
56  }
57 }
58 
60 {
61  set_ratio(0,0);
62  set_treatment("");
63 }
64 
65 CCCC_Metric::CCCC_Metric(int n, const char* treatment_tag)
66 {
67  set_ratio(n,1); set_treatment(treatment_tag);
68 }
69 
70 CCCC_Metric::CCCC_Metric(int n, int d, const char* treatment_tag)
71 {
72  set_ratio(n,d); set_treatment(treatment_tag);
73 }
74 
75 void CCCC_Metric::set_treatment(const char* code)
76 {
78 }
79 
80 void CCCC_Metric::set_ratio(float _num, float _denom)
81 {
82  numerator=_num; denominator=_denom;
83 }
84 
86 {
87  EmphasisLevel retval=elLOW;
89  {
91  {
92  retval=elHIGH;
93  }
95  {
96  retval=elMEDIUM;
97  }
98  }
99  return retval;
100 }
101 
102 string CCCC_Metric::code() const
103 {
104  string retval;
105  if(treatment != NULL) { retval=treatment->code; }
106  return retval;
107 }
108 
109 string CCCC_Metric::name() const
110 {
111  string retval;
112  if(treatment != NULL) { retval=treatment->name; }
113  return retval;
114 }
115 
117 {
118  string retval;
119  char numerator_too_low='-';
120  char infinity='*';
121 
122  ostringstream valuestr;
123  valuestr.setf(std::ios::fixed);
124  int width=6, precision=0;
125  float n_threshold=0, low_threshold=1e9, high_threshold=1e9;
126  if(treatment!=NULL)
127  {
128  width=treatment->width;
129  precision=treatment->precision;
130  n_threshold=treatment->numerator_threshold;
131  low_threshold=treatment->lower_threshold;
132  high_threshold=treatment->upper_threshold;
133  }
134  valuestr.width(width);
135  valuestr.precision(precision);
136  if(numerator<n_threshold)
137  {
138  string too_low_string(width,numerator_too_low);
139  valuestr << too_low_string;
140  }
141  else if(denominator==0)
142  {
143  string infinity_string(width,infinity);
144  valuestr << infinity_string;
145  }
146  else
147  {
148  double result=numerator;
149  result/=denominator;
150  if(result!=0.0L)
151  {
152  // Visual C++ and GCC appear to give different behaviours
153  // when rounding a value which is exactly half way between
154  // two points representable in the desired format.
155  // An example of this occurs results from prn14, where the
156  // numerator 21 and denominator 16 are combined to give the
157  // value 1.2125 exactly, which Visual Studio renders as 1.213,
158  // GCC renders as 1.212. For consistency with the existing
159  // reference data, I choose to apply a very small downward
160  // rounding factor. The rounding factor is only applied if
161  // the value is not exactly equal to zero, as applying it
162  // to zero causes the value to be displayed as -0.0 instead
163  // of 0.0.
164  const double ROUNDING_FACTOR = 1.0e-9;
165  result-=ROUNDING_FACTOR;
166  }
167  valuestr << result;
168  }
169  retval=valuestr.str();
170  return retval;
171 }
172 
173 const char *internal_treatments[] =
174 {
175  "LOCf@30@100@0@6@0@Lines of code/function@",
176  "LOCm@500@2000@0@6@0@Lines of code/module @",
177  "LOCp@999999@999999@0@6@0@Lines of code/project @",
178  "MVGf@10@30@0@6@0@Cyclomatic complexity/function@",
179  "MVGm@200@1000@0@6@0@Cyclomatic complexity/module@",
180  "MVGp@999999@999999@0@6@0@Cyclomatic complexity/project@",
181  "COM@999999@999999@0@6@0@Comment lines@",
182  "M_C@5@10@5@6@3@MVG/COM McCabe/comment line@",
183  "L_C@7@30@20@6@3@LOC/COM Lines of code/comment line@",
184  "FI@12@20@0@6@0@Fan in (overall)@",
185  "FIv@6@12@0@6@0@Fan in (visible uses only)@",
186  "FIc@6@12@0@6@0@Fan in (concrete uses only)@",
187  "FO@12@20@0@6@0@Fan out (overall)@",
188  "FOv@6@12@0@6@0@Fan out (visible uses only)@",
189  "FOc@6@12@0@6@0@Fan out (concrete uses only)@",
190  "IF4@100@1000@0@6@0@Henry-Kafura/Shepperd measure (overall)@",
191  "IF4v@30@100@0@6@0@Henry-Kafura/Shepperd measure (visible only)@",
192  "IF4c@30@100@0@6@0@Henry-Kafura/Shepperd measure (concrete only)@",
193  "WMC1@30@100@0@6@0@Weighting function = 1 unit per method@",
194  "WMCv@10@30@0@6@0@Weighting function = 1 unit per visible method@",
195  "DIT@3@60@6@0@Depth of Inheritance Tree@",
196  "NOC@4@15@0@6@0@Number of children@",
197  "CBO@12@30@0@6@0@Coupling between objects@",
198  NULL
199 };
200 
201 
202 
203 
204 
205 
206 
207 
Metric_Treatment(CCCC_Item &treatment_line)
Definition: cccc_met.cc:31
float denominator
Definition: cccc_met.h:70
Definition: cccc_met.h:27
Metric_Treatment * treatment
Definition: cccc_met.h:69
void set_ratio(float _num, float _denom=1.0)
Definition: cccc_met.cc:80
string code() const
Definition: cccc_met.cc:102
EmphasisLevel emphasis_level() const
Definition: cccc_met.cc:85
string value_string() const
Definition: cccc_met.cc:116
float lower_threshold
Definition: cccc_met.h:49
bool Extract(string &s)
Definition: cccc_itm.cc:47
static Metric_Treatment * getMetricTreatment(const string &metric_tag)
Definition: cccc_opt.cc:253
string name() const
Definition: cccc_met.cc:109
int numerator_threshold
Definition: cccc_met.h:56
void set_treatment(const char *code)
Definition: cccc_met.cc:75
const char * internal_treatments[]
Definition: cccc_met.cc:173
EmphasisLevel
Definition: cccc_met.h:27
float numerator
Definition: cccc_met.h:70
float upper_threshold
Definition: cccc_met.h:49