Last active
January 27, 2019 14:04
-
-
Save SlavaMelanko/27aa1f4d1f0bc40d008150783432010f to your computer and use it in GitHub Desktop.
awe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// test | |
// | |
// Created by Slava Melanko on 12/17/18. | |
// Copyright © 2018 Slava Melanko. All rights reserved. | |
// | |
#include <algorithm> | |
#include <iostream> | |
#include <list> | |
#include <map> | |
#include <set> | |
#include <string> | |
#include <vector> | |
#include <unordered_map> | |
struct Info | |
{ | |
public: | |
virtual ~Info() noexcept = default; | |
}; | |
struct HardwareUnit | |
{ | |
public: | |
virtual ~HardwareUnit() noexcept = default; | |
virtual std::unique_ptr<Info> Scan() const = 0; | |
}; | |
struct CpuInfo : public Info | |
{ | |
std::string _name; | |
int _cores; | |
}; | |
struct CpuHardwareUnit : public HardwareUnit | |
{ | |
public: | |
std::unique_ptr<Info> Scan() const override | |
{ | |
std::unique_ptr<Info> info = std::make_unique<CpuInfo>(); | |
auto cpuInfo = reinterpret_cast<CpuInfo*>(info.get()); | |
cpuInfo->_name = "CPU"; | |
cpuInfo->_cores = 4; | |
return info; | |
} | |
}; | |
struct RamInfo : public Info | |
{ | |
struct Slot | |
{ | |
uint32_t _total; | |
}; | |
std::vector<Slot> _data; | |
}; | |
struct RamHardwareUnit : public HardwareUnit | |
{ | |
public: | |
std::unique_ptr<Info> Scan() const override | |
{ | |
std::unique_ptr<Info> info = std::make_unique<RamInfo>(); | |
auto ramInfo = reinterpret_cast<RamInfo*>(info.get()); | |
ramInfo->_data.push_back({ 1024 }); | |
ramInfo->_data.push_back({ 1024 }); | |
return info; | |
} | |
}; | |
int main(int argc, const char* argv[]) | |
{ | |
CpuHardwareUnit cpu; | |
auto info = cpu.Scan(); | |
auto cpuInfo = reinterpret_cast<CpuInfo*>(info.get()); | |
std::cout << cpuInfo->_name << ": " << cpuInfo->_cores << " cores\n"; | |
RamHardwareUnit ram; | |
info = ram.Scan(); | |
auto ramInfo = reinterpret_cast<RamInfo*>(info.get()); | |
std::cout << "RAM: " << ramInfo->_data[0]._total + ramInfo->_data[1]._total << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment