-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.cpp
executable file
·108 lines (81 loc) · 3.13 KB
/
Package.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Package.cpp (ver 1.0) - Class to hold information about each package ( .h + .cpp ) file. //
// //
// Language : Visual C++, 2010 //
// Platform : Toshiba Satellite (R25-S3503), Windows 7 Professional //
// Application : CSE687 - Project #1 - CodeMetricsAnalyzer, Spring 2011 //
// Author : Harshal Bhakta, Syracuse University. //
// E-mail : harshal.c.bhakta@gmail.com //
// Cell : 714-876-4273 //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include "Package.h"
///////////////////////////////////////////////////////////////
// Function to add the control to the list of controls.
void Package::addControl(Control ct)
{ ControlList.push_back(ct); }
///////////////////////////////////////////////////////////////
// Function to add the function to the list of controls.
void Package::addFunction(Function fn)
{ FunctionList.push_back(fn); }
///////////////////////////////////////////////////////////////
// Function to add the variable to the list of controls.
void Package::addVariable(std::string package,std::string name, std::string fromFile ,int fromLine,std::string toFile,int toLine,int loc_reference)
{
std::vector<Variable>* vbPtr = this->getVariableList();
bool variable_exists = false;
for ( int i = 0 ; i < (int)(*vbPtr).size() ; i++)
{
if ( (*vbPtr)[i].getVariableName() == name )
{
variable_exists = true;
(*vbPtr)[i].setRefDensity((*vbPtr)[i].getRefDensity()+1);
if ( (*vbPtr)[i].getLocReference() < loc_reference )
{ // Update only when new locality of reference detected.
(*vbPtr)[i].setLocReference(loc_reference);
(*vbPtr)[i].setFromFileName(fromFile);
(*vbPtr)[i].setFromFileLine(fromLine);
(*vbPtr)[i].setToFileName(toFile);
(*vbPtr)[i].setToFileLine(toLine);
}
break;
}
}
if ( !variable_exists )
{ // Variable not detected yet. Add to list.
Variable vb;
vb.setVariableName(name);
vb.setFromFileName(fromFile);
vb.setFromFileLine(fromLine);
vb.setToFileName(toFile);
vb.setToFileLine(toLine);
vb.setRefDensity(1);
vb.setLocReference(loc_reference);
(*vbPtr).push_back(vb);
}
}
///////////////////////////////////////////////////////////////
// Test Stub.
#ifdef TEST_PACKAGE
void main ( int argc , char *argv[] )
{
Package pk;
Function fk;
fk.setFunctionName("Test");
fk.setNoOfLines(12);
fk.setDepthOfNesting(20);
fk.setCycloComplexity(15);
Variable vb;
vb.setVariableName("LocOfReference");
vb.setLocReference(20);
vb.setRefDensity(5);
Control ct;
ct.setControlName("For");
// ct.setBreadthControlSpan(12);
std::cout<<"CT -> Breadth Control Span = " << ct.getBreadthControlSpan();
pk.addFunction(fk);
pk.addControl(ct);
pk.addVariable(vb);
std::getchar();
}
#endif