Used code snipped donated by szaszmango - which uses vectors to create

the CPU objects
This commit is contained in:
ganome 2025-01-29 20:55:57 -07:00
parent 63815adecc
commit cfa53d4fc3
Signed by untrusted user who does not match committer: Ganome
GPG Key ID: 944DE53336D81B83
6 changed files with 39 additions and 63 deletions

View File

@ -3,27 +3,27 @@
/* this function's Incoming arguments are a pointer to the CPU class
"CPU *pCPU" and the new mainclock speed
*/
void setCPUmainclock(CPU *pCPU, string mkey, string mmainclock) {
void setCPUmainclock(CPU *pCPU, std::string mkey, std::string mmainclock) {
pCPU->HardwareSpecs[mkey] = mmainclock;
}
void setCPUboostclock(CPU *pCPU, string mkey, string mboostclock) {
void setCPUboostclock(CPU *pCPU, std::string mkey, std::string mboostclock) {
pCPU->HardwareSpecs[mkey] = mboostclock;
}
void setCPUarch(CPU *pCPU, string mkey, std::string march) {
void setCPUarch(CPU *pCPU, std::string mkey, std::string march) {
pCPU->HardwareSpecs[mkey] = march;
}
void setCPUbits(CPU *pCPU, string mkey, int mbits) {
void setCPUbits(CPU *pCPU, std::string mkey, int mbits) {
pCPU->HardwareSpecs[mkey] = mbits;
}
void setCPUcores(CPU *pCPU, string mkey, int mcores) {
void setCPUcores(CPU *pCPU, std::string mkey, int mcores) {
pCPU->HardwareSpecs[mkey] = mcores;
}
void setCPUthreads(CPU *pCPU, string mkey, int mthreads) {
void setCPUthreads(CPU *pCPU, std::string mkey, int mthreads) {
pCPU->HardwareSpecs[mkey] = mthreads;
// create an IF catch to set threads cores * 2 as a fall back
}

View File

@ -3,7 +3,7 @@
/* this function's Incoming arguments are a pointer to the Hardware class
"Hardware *pHardware" and the new mainclock speed
*/
void setHardwaremanufacturer(Hardware *pHardware, string mmanufacturer) {
void setHardwaremanufacturer(Hardware *pHardware, std::string mmanufacturer) {
// cout << "Coming from the setHardwaremanufacturer function in setHardware" << endl;
pHardware->manufacturer = mmanufacturer;
@ -14,11 +14,11 @@ void setHardwarereleasedyear(Hardware *pHardware, int mreleasedyear) {
pHardware->releasedyear = mreleasedyear;
}
void setHardwaremodel(Hardware *pHardware, string mmodel) {
void setHardwaremodel(Hardware *pHardware, std::string mmodel) {
pHardware->model = mmodel;
}
void Hardwaredictadd(CPU *pHardware, string mkey, string mvalue) {
void Hardwaredictadd(CPU *pHardware, std::string mkey, std::string mvalue) {
// cout << "The incoming key/value is: " << mkey << "/" << mvalue << endl;
// cout << "\nThe current manufacturer is: " << pHardware->HardwareSpecs[mkey] << endl;

View File

@ -1,39 +1,28 @@
#pragma once
#include "hardware.h"
#include <vector>
#include <fstream>
using namespace std;
string line;
string& line2 = line;
/*
* THIS PORTION OF CODE WAS DONATED BY szaszmango from brodie's server!
*/
void genCPUclasses() {
fstream cpuList;
cpuList.open("lists/cpulist", ios::in);
// This magic returns a vector which contain all the objects created using the CPU class
std::vector<CPU> genCPUclasses() {
std::vector<CPU> resultCpuList;
std::ifstream cpuList{"lists/cpulist", std::ifstream::in};
if(cpuList.is_open()) {
cout << "File opened\n";
std::cout << "File opened\n";
}
else { cout << "Failed to open file!" << endl; }
else { std::cout << "Failed to open file!\n"; }
while (getline(cpuList, line)) {
// cout << line << endl;
line2 = line;
CPU *line = new CPU;
// BEGIN troubleshoot
line->HardwareSpecs["model"] = line2;
// cout << line->HardwareSpecs["model"] << endl;
cout << line2 << endl;
std::string line;
while (std::getline(cpuList, line)) {
CPU cpu;
cpu.HardwareSpecs["model"] = line;
resultCpuList.push_back(std::move(cpu));
std::cout << "Loaded CPU: " << line << std::endl;
}
cpuList.close();
};
// CPU *A7800x3d = new CPU;
// CPU *Ii75820k = new CPU;
// std::string a7800x3d(std::string man){
// CPU A7800x3d;
// A7800x3d.manufacturer = "AMD";
// return man;
// };
return resultCpuList;
}

View File

@ -1,19 +0,0 @@
std::vector<CPU> genCPUclasses() {
std::vector<CPU> resultCpuList;
std::ifstream cpuList{"lists/cpulist", std::ifstream::in};
if(cpuList.is_open()) {
std::cout << "File opened\n";
}
else { std::cout << "Failed to open file!\n"; }
while (std::getline(cpuList, line)) {
CPU cpu;
cpu.HardwareSpecs["model"] = line;
resultCpuList.push_back(std::move(cpu));
// cout << cpu.HardwareSpecs["model"] << '\n';
cout << line << endl;
}
return resultCpuList;
}

View File

@ -5,7 +5,7 @@
// #define class struct // Uncomment this line to switch all the classes to structs
using namespace std;
// using namespace std;
class Hardware {
@ -70,6 +70,6 @@ class CPU: public Hardware {
class GPU: public Hardware {
public:
map<std::string, GPU> GPUSpecs;
std::map<std::string, GPU> GPUSpecs;
// GPUSpecs["Ram"] = GPU { "Ram", "12Gb" };
};

View File

@ -7,13 +7,19 @@
int main() {
using namespace std;
genCPUclasses();
// using namespace std;
int counter= 0;
auto cpus = genCPUclasses();
for (CPU& cpu: cpus) {
// cpus[counter].HardwareSpecs["model"] = "value";
std::cout << cpu.HardwareSpecs["model"] << " loaded at index: " << counter << std::endl;
counter++;
}
//Testing the new dictionaries
// cout << "Lets try the setCPU function!\n";
// cout << "A7800x3d main clock speed is: " << line->HardwareSpecs["mainclock"] << endl;
// std::cout << "A7800x3d main clock speed is: " << A7800x3d->HardwareSpecs["mainclock"] << std::endl;
// setHardwaremanufacturer(A7800x3d, "AMD");
// setCPUcores(A7800x3d, "cores", 8);
// setCPUthreads(A7800x3d, "threads", 16);