Repository navigation
Expand file tree
/
Copy pathDataSyncMagnr.cpp
More file actions
61 lines (52 loc) · 1.61 KB
/
Copy pathDataSyncMagnr.cpp
File metadata and controls
61 lines (52 loc) · 1.61 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
// DataSyncMagnr.cpp
#ifndef DATASYNCMAGNR_CPP
#define DATASYNCMAGNR_CPP
#include "DataSyncMagnr.h"
// Add data to all structures
template <typename T> void DataSyncMagnr<T>::addData(int key, const T &value) {
dataMap[key] = value;
dataTree[key] = value;
database[key] = value;
}
// Update data in all structures
template <typename T>
void DataSyncMagnr<T>::updateData(int key, const T &newValue) {
if (dataMap.find(key) != dataMap.end()) {
dataMap[key] = newValue;
dataTree[key] = newValue;
database[key] = newValue;
} else {
throw std::runtime_error("Key not found");
}
}
// Remove data from all structures
template <typename T> void DataSyncMagnr<T>::removeData(int key) {
dataMap.erase(key);
dataTree.erase(key);
database.erase(key);
}
// Retrieve data (from map as example)
template <typename T> T DataSyncMagnr<T>::getData(int key) const {
auto it = dataMap.find(key);
if (it != dataMap.end()) {
return it->second;
} else {
throw std::runtime_error("Key not found");
}
}
// Print data from all structures (for debugging)
template <typename T> void DataSyncMagnr<T>::printData() const {
std::cout << "Data from Map:" << std::endl;
for (const auto &pair : dataMap) {
std::cout << pair.first << ": " << pair.second << std::endl;
}
std::cout << "Data from Tree:" << std::endl;
for (const auto &pair : dataTree) {
std::cout << pair.first << ": " << pair.second << std::endl;
}
std::cout << "Data from Database:" << std::endl;
for (const auto &pair : database) {
std::cout << pair.first << ": " << pair.second << std::endl;
}
}
#endif // DATASYNCMAGNR_CPP