-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventManager.cpp
More file actions
54 lines (46 loc) · 1.45 KB
/
Copy pathEventManager.cpp
File metadata and controls
54 lines (46 loc) · 1.45 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
#include "EventManager.h"
#include <fstream>
#include <iostream>
#include <sstream>
// Method to read events from a file and store them
void EventManager::read_events(const std::string &filename) {
std::ifstream file(filename);
if (!file.is_open()) {
std::cerr << "Error opening file: " << filename << std::endl;
return;
}
std::string line;
// Read the first line to get the total number of timesteps
std::getline(file, line);
std::istringstream first_line(line);
first_line >> total_timesteps;
// Read the remaining lines for events
while (std::getline(file, line)) {
std::istringstream iss(line);
std::string event_type;
int x, y, z, density, timestep;
iss >> event_type;
if (event_type == "source") {
// Parse the density and timestep for source event
iss >> density >> timestep;
events.emplace_back(density, timestep);
} else if (event_type == "force") {
// Parse the vector and timestep for force event
iss >> x >> y >> z >> timestep;
events.emplace_back(x, y, z, timestep);
} else {
std::cerr << "Unknown event type: " << event_type << std::endl;
}
}
file.close();
}
// Method to get all events for a specific timestamp
std::vector<Event> EventManager::get_events_at_timestamp(int timestamp) const {
std::vector<Event> result;
for (const auto &event : events) {
if (event.timestep == timestamp) {
result.push_back(event);
}
}
return result;
}