Bläddra i källkod

finished the core part

runningwater 2 år sedan
förälder
incheckning
165c2a5804
2 ändrade filer med 28 tillägg och 6 borttagningar
  1. 20 5
      sysinfo.cpp
  2. 8 1
      sysinfo.h

+ 20 - 5
sysinfo.cpp

@@ -1,11 +1,26 @@
 #include "sysinfo.h"
 
-SysInfo::SysInfo()
-{
+#include <QtGlobal>
 
+#ifdef Q_OS_WIN
+#include "sysinfowindowsimpl.h"
+#elif defined(Q_OS_MAC)
+#include "sysinfomacimpl.h"
+#elif defined(Q_IS_LINUX)
+#include "sysinfolinuximpl.h"
+#endif
+
+SysInfo &SysInfo::instance() {
+#ifdef Q_OS_WIN
+  static SysInfoWindowsImpl singleton;
+#elif defined(Q_OS_MAC)
+  static SysInfoMacImpl singleton;
+#elif defined(Q_OS_LINUX)
+  static SysInfoLinuxImpl singleton;
+#endif
+  return singleton;
 }
 
-SysInfo::~SysInfo()
-{
+SysInfo::SysInfo() {}
 
-}
+SysInfo::~SysInfo() {}

+ 8 - 1
sysinfo.h

@@ -6,7 +6,7 @@
  */
 class SysInfo {
  public:
-  SysInfo();
+  static SysInfo& instance();
   virtual ~SysInfo();
 
   // Allows the derived class to perform any initialization process depending on
@@ -14,6 +14,13 @@ class SysInfo {
   virtual void init() = 0;
   virtual double cpuLoadAverage() = 0;
   virtual double memoryUsed() = 0;
+
+ protected:
+  explicit SysInfo();
+
+ private:
+  SysInfo(const SysInfo& rhs);
+  SysInfo& operator=(const SysInfo& rhs);
 };
 
 #endif  // SYSINFO_H