Skip to content

Commit

Permalink
Commom hat::system_info base class
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMemes committed Oct 2, 2024
1 parent ed4e9ff commit 3a255b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
26 changes: 16 additions & 10 deletions include/libhat/System.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
#include <libhat/Defines.hpp>
#include <string>

namespace hat {
struct system_info {
system_info(const system_info&) = delete;
system_info& operator=(const system_info&) = delete;
system_info(system_info&&) = delete;
system_info& operator=(system_info&&) = delete;
protected:
system_info();
};
}

#if defined(LIBHAT_X86)
namespace hat {

struct system_info_x86 {
struct system_info_x86 : hat::system_info {
std::string cpu_vendor{};
std::string cpu_brand{};
struct {
Expand All @@ -23,34 +34,29 @@ namespace hat {
bool popcnt;
bool bmi;
} extensions{};

system_info_x86(const system_info_x86&) = delete;
system_info_x86& operator=(const system_info_x86&) = delete;
private:
system_info_x86();
friend const system_info_x86& get_system();
static const system_info_x86 instance;
};

using system_info = system_info_x86;
using system_info_impl = system_info_x86;
}
#elif defined(LIBHAT_ARM)
namespace hat {

struct system_info_arm {
system_info_arm(const system_info_arm&) = delete;
system_info_arm& operator=(const system_info_arm&) = delete;
struct system_info_arm : hat::system_info {
private:
system_info_arm() = default;
friend const system_info_arm& get_system();
static const system_info_arm instance;
};

using system_info = system_info_arm;
using system_info_impl = system_info_arm;
}
#endif

namespace hat {

const system_info& get_system();
const system_info_impl& get_system();
}
8 changes: 5 additions & 3 deletions src/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace hat {

const system_info system_info::instance{};
const system_info& get_system() {
return system_info::instance;
system_info::system_info() {}

const system_info_impl system_info_impl::instance{};
const system_info_impl& get_system() {
return system_info_impl::instance;
}
}

0 comments on commit 3a255b1

Please sign in to comment.