From 2f1ad9ec273a0ff9e746e9f6c4cac2ce81cb31e4 Mon Sep 17 00:00:00 2001 From: Oskar Date: Thu, 3 Oct 2024 12:20:34 +0200 Subject: small test to play around abit with classes --- class-tests.hpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 class-tests.hpp (limited to 'class-tests.hpp') diff --git a/class-tests.hpp b/class-tests.hpp new file mode 100644 index 0000000..8ac10a2 --- /dev/null +++ b/class-tests.hpp @@ -0,0 +1,78 @@ +/* + Made this file mainly to just play around with classes and play around with the features. + No real use for this code. + */ +#ifndef CLASS_TESTS_HPP +#define CLASS_TESTS_HPP +#include +#include +#include +#include +#include + +struct ERROR_RESULT { + friend class CLASS_TESTS; +private: + bool fail = false; + bool partial = false; + bool success = false; +}; + +class CLASS_TESTS { +public: + CLASS_TESTS(): Kernel(""), Distro_OS(""), EnvVarHOME(""), TotalMemoryBytes(0), CurTime(0) { } + CLASS_TESTS(std::string K, std::string D, std::string H, size_t B, time_t T): + Kernel(K), Distro_OS(D), EnvVarHOME(H), TotalMemoryBytes(B), CurTime(T){ } + void print_CT(); + ERROR_RESULT Get_System_Info(); + ERROR_RESULT Get_Errors() { return res; }; + bool isFailed() { return res.fail; } + bool isPartial() { return res.partial; } + bool isSuccess() { return res.success; } +private: + std::string Kernel; + std::string Distro_OS; + std::string EnvVarHOME; + size_t TotalMemoryBytes; + time_t CurTime; + ERROR_RESULT res; +}; + +void CLASS_TESTS::print_CT() { + std::cout << Kernel << "\n" + << Distro_OS << "\n" + << EnvVarHOME << "\n" + << TotalMemoryBytes << "\n" + << CurTime << std::endl; +} + +ERROR_RESULT CLASS_TESTS::Get_System_Info() { + + struct utsname gsi; + if(uname(&gsi) == -1) { + res.fail = true; + return res; + } + + Kernel = gsi.sysname; + Distro_OS = gsi.release; + char *r = std::getenv("HOME"); + if(r == NULL) { + res.fail = false; + res.partial = true; + return res; + } + + EnvVarHOME = r; + CurTime = time(NULL); + if(CurTime == -1) { + res.partial = true; + } + + TotalMemoryBytes = 4096; + res.partial = false; + res.success = true; + return res; +} + +#endif -- cgit v1.2.3