-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataStore.cpp
executable file
·298 lines (228 loc) · 8.12 KB
/
DataStore.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DataStore.cpp (ver 1.0) - Hold all the Static Data required to be stored for analysis. //
// //
// 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 <string>
#include <vector>
#include "DataStore.h"
#include <iomanip>
///////////////////////////////////////////////////////////////
// Initialize Static Data
std::string DataStore::currentPackageName = "" ;
std::string DataStore::currentFileName = "" ;
int DataStore::curr_function_cyclo = 0;
int DataStore::depth_scope_nesting = 0;
int DataStore::current_file_size = 0;
DataStore::mode DataStore::parse_mode = FIRST_PASS;
std::vector<std::pair<std::string,std::string>> DataStore::namespaceList;
std::vector<std::pair<std::string,int>> DataStore::fileSizeList;
std::map<std::string,TypeItem> DataStore::TypeTable;
///////////////////////////////////////////////////////////////
// Set Parse Mode.
void DataStore::setParseMode(DataStore::mode currMode)
{
parse_mode = currMode;
}
///////////////////////////////////////////////////////////////
// Get Parse Mode.
DataStore::mode DataStore::getParseMode()
{
return parse_mode;
}
///////////////////////////////////////////////////////////////
// Set Current Package Name
void DataStore::setcurrentPackageName(std::string currPkgName)
{
currentPackageName = currPkgName;
}
///////////////////////////////////////////////////////////////
// Get Current Package Name
std::string DataStore::getcurrentPackageName()
{
return currentPackageName;
}
///////////////////////////////////////////////////////////////
// Set Current File Name
void DataStore::setcurrentFileName(std::string FileName)
{
currentFileName = FileName;
}
///////////////////////////////////////////////////////////////
// Get Current File Name
std::string DataStore::getcurrentFileName()
{
return currentFileName;
}
///////////////////////////////////////////////////////////////
// Set Current Cyclomatic Complexity
void DataStore::setCurr_function_cyclo(int cyclo)
{
curr_function_cyclo = cyclo;
}
///////////////////////////////////////////////////////////////
// Get Current Cyclomatic Complexity.
int DataStore::getCurr_function_cyclo()
{
return curr_function_cyclo;
}
///////////////////////////////////////////////////////////////
// Set Depth Scope Nesting
void DataStore::setDepth_scope_nesting(int depth)
{
depth_scope_nesting = depth;
}
///////////////////////////////////////////////////////////////
// Get Depth Scope Nesting
int DataStore::getDepth_scope_nesting()
{
return depth_scope_nesting;
}
///////////////////////////////////////////////////////////////
// Set Current File Size.
void DataStore::setCurrent_File_Size(int size)
{ current_file_size = size;
}
//////////////////////////////////////////////////////////////
// Set Current File Size
int DataStore::getCurrent_File_Size()
{ return current_file_size; }
///////////////////////////////////////////////////////////////
// Inrement Cyclomatic Complexity
void DataStore::Increment_Cyclo()
{
curr_function_cyclo++;
}
///////////////////////////////////////////////////////////////
// Insert Namespace when "using" detected.
void DataStore::InsertNamespace(std::string fileName,std::string Namespace)
{
std::pair<std::string,std::string> temp;
temp.first = fileName;
temp.second = Namespace;
namespaceList.push_back(temp);
}
///////////////////////////////////////////////////////////////
// Insert the size of the file.
void DataStore::InsertFileSize(std::string fileName,int size)
{
std::pair<std::string,int> temp;
temp.first = fileName;
temp.second = size;
fileSizeList.push_back(temp);
}
///////////////////////////////////////////////////////////////
// Get size of a file by name.
int DataStore::GetFileSize(std::string fileName)
{
int size = 0;
for ( int i = 0 ; i < (int)fileSizeList.size() ; i++ )
{
if ( fileSizeList[i].first == fileName )
{ size = fileSizeList[i].second; break; }
}
return size;
}
//void DataStore::addTypeVectorToTypeTable(std::string key,std::vector<TypeItem> vecItem)
//{
// if ( DataStore::TypeTable.find(key) == DataStore::TypeTable.end() )
// {
// DataStore::TypeTable[key] = vecItem;
// }
//}
//std::vector<TypeItem>* DataStore::getTypeVector(std::string key)
//{
// return &DataStore::TypeTable[key];
//}
///////////////////////////////////////////////////////////////
// Add Type to the Table
void DataStore::addTypeToTypeTable(std::string key,TypeItem ti)
{
if ( DataStore::TypeTable.find(key) == DataStore::TypeTable.end() )
{
DataStore::TypeTable[key] = ti;
}
}
///////////////////////////////////////////////////////////////
// Check if a key exists in the TypeTable.
bool DataStore::findKeyInTypeTable(std::string key)
{
std::map<std::string,TypeItem>::iterator it ;
it = TypeTable.find(key);
if ( it != TypeTable.end() )
return true;
return false;
}
///////////////////////////////////////////////////////////////
// Get TypeItem using key ( Fully Qualified Type Name )
TypeItem DataStore::getTypeItemFromTypeTable(std::string key)
{
return TypeTable[key];
}
void DataStore::printDetectedTypes(std::string package)
{
/* std::vector<TypeItem>* tiPtr = DataStore::getTypeVector(package);
std::cout<<"\n\n "<<package<<"\n";
std::cout<<" "<<std::string(49,'-')<<"\n";
std::cout<<"\n\n "<<std::setw(5)<<"filename"<<" "<<"line #"<<" "<<" type"<<"\n";
std::cout<<" "<<std::string(49,'-')<<"\n";
for ( int i = 0 ; i < (int)((*tiPtr).size()) ; i++)
{
std::cout<<" "<<std::setw(5)<<(*tiPtr)[i].getFileName()<<" "<<std::setw(5)<<(*tiPtr)[i].getLineNumber()<<" "<<(*tiPtr)[i].getFullyQualifiedName()<<"\n";
}*/
}
///////////////////////////////////////////////////////////////
// Test Function to display namespace associated to a file.
void DataStore::printNamespace(std::string file)
{
std::cout<<"\n\n "<<file<<"\n";
std::cout<<" "<<std::string(49,'-')<<"\n";
std::cout<<"\n\n "<<std::setw(5)<<"filename"<<" "<<"namespace"<<"\n";
std::cout<<" "<<std::string(49,'-')<<"\n";
for ( int i = 0 ; i < (int)namespaceList.size() ; i++)
{
if ( namespaceList[i].first == file )
std::cout<<" "<<std::setw(5)<<file<<" "<<std::setw(5)<<namespaceList[i].second<<"\n";
}
}
///////////////////////////////////////////////////////////////
// Get Name space list for a file.
std::vector<std::string> DataStore::GetNamespace(std::string fileName)
{
std::vector<std::string> temp;
for ( int i = 0 ; i < (int)namespaceList.size() ; i++)
{
if ( namespaceList[i].first == fileName )
{ temp.push_back(namespaceList[i].second);}
}
return temp;
}
///////////////////////////////////////////////////////////////
// Test Stub
#ifdef TEST_DATABASE
int main ( int argc, char* argv[])
{
std::cout<<"Testing Storage";
DataStore::setcurrentPackageName("testing.cpp");
std::cout<<DataStore::getcurrentPackageName();
TypeItem ti;
ti.setFileName("test.cpp");
ti.setLineNumber(12);
ti.setpackageName("test_package");
DataStore::addTypeToTypeTable("variable",ti);
bool find = DataStore::findKeyInTypeTable("varialbe");
std::cout<<"\nVariable found or not : "<<find;
DataStore::setParseMode(DataStore::FIRST_PASS);
std::cout<<DataStore::getParseMode();
DataStore::InsertFileSize("test",12);
std::vector<std::string> test = DataStore::GetNamespace("test");
std::cout<<test[0];
std::getchar();
}
#endif