forked from bishyboi/DSAProj_3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
119 lines (105 loc) · 3.42 KB
/
main.cpp
File metadata and controls
119 lines (105 loc) · 3.42 KB
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
#include <fstream>
#include <iostream>
#include <sstream>
#include "Graphics.h"
#include "HashMap.h"
#include <tuple>
#include "Heap.h"
int main()
{
// make the data structures
HashMap map(200);
Heap heap(200);
// data for storing words
std::vector<std::string> row;
std::string entry;
// open in the file and read each line
std::string line;
std::fstream file("output_extra_clean/output_extra_clean1950.csv", std::ios::in);
if (file.is_open())
{
getline(file, line);
while (!file.eof())
{
row.clear();
getline(file, line);
// break up the line into words
std::stringstream s(line);
while (getline(s, entry, ','))
{
row.emplace_back(entry);
}
// make a song object with data
song temp;
temp.ExpLyrics = std::stoi(row[0]);
temp.language = row[1];
temp.year = std::stoi(row[2]);
// add data to data structure
map.insert(temp);
heap.insert(temp);
}
}
// graphing data
std::vector<double> Data = {0};
std::string dataTime1 = "0";
std::string dataTime2 = "0";
// GUI loop
Graphics GUI;
while (GUI.window.isOpen())
{
sf::Event event;
// event handeling
while (GUI.window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
GUI.window.close();
if (event.type == sf::Event::MouseButtonPressed)
{
// if mouse hits language button go into edit mode
if (!GUI.acceptingText)
{
if (GUI.textBack.getGlobalBounds().contains(sf::Vector2f(sf::Mouse::getPosition(GUI.window))))
{
GUI.acceptingText = true;
GUI.textBoxString = "";
}
}
}
if (event.type == sf::Event::TextEntered && GUI.acceptingText)
{
// make sure character is english letter
if ((event.text.unicode < 123 && event.text.unicode > 64) || event.text.unicode == 32)
{
GUI.textBoxString.push_back(static_cast<char>(event.text.unicode));
}
}
if (event.type == sf::Event::KeyPressed && GUI.acceptingText)
{
if (event.key.code == sf::Keyboard::BackSpace)
{
if (!GUI.textBoxString.empty())
{
GUI.textBoxString.pop_back();
}
}
// if string is entered run algo on that language
if (event.key.code == sf::Keyboard::Enter)
{
// run hash map
auto temp = (map.Algo(GUI.textBoxString));
Data = std::get<0>(temp);
dataTime1 = std::get<1>(temp);
dataTime2 = heap.algo(GUI.textBoxString);
// run heap
dataTime2 = heap.algo(GUI.textBoxString);
GUI.acceptingText = false;
}
}
}
// set up and render frame
GUI.window.clear();
GUI.drawConstants(dataTime1, dataTime2);
GUI.drawGraph(Data);
GUI.window.display();
}
}