lfreist / hwinfo

cross platform C++ library for hardware information (CPU, RAM, GPU, ...)
MIT License
438 stars 76 forks source link

Reduce library requirement from C++17 to C++11 #32

Closed facug91 closed 1 year ago

facug91 commented 1 year ago

Solve #31
I made some decisions that maybe you think would be better otherwise. If so, tell me and I'll change it.
For the record, I've only tried it on Linux, but I've also modified the apple and windows code.

facug91 commented 1 year ago

I don't know how to solve the MacOS problem, I don't have one to try out. I guess that if a use something like reinterpret_cast<void *>(os_name.data()), it might work, but I'm not sure.

lfreist commented 1 year ago

Thanks. Right now, I don't have access to MacOS as well but I'll take care of it.

lfreist commented 1 year ago

I guess that if a use something like reinterpret_cast<void *>(os_name.data()), it might work, but I'm not sure.

I am not sure how this results in the produced error but this should be done anyways:

It makes no sense to call sizeof(std::string). What we want is the size of the underlying char array and not the size of the std::string object.

Either try size = std::string::size() or since I hard coded the size, just use size = 1024.

If this won't work, i would recommend not to use std::string here but simply a raw char array and then construct a std::string using the char pointer and its size modified by the sysctl function when returning the result.

I can also give these approaches a try at the start of the coming week if you want.

facug91 commented 1 year ago

I apologize for the clang formatting errors. I have Ubuntu 20 on my machine and I couldn't install clang-format-14. After a few tries, I ended up using an Ubuntu 22 Docker container and was able to fix the issues.
I still can't test if the Apple and Windows implementations work, but at least they are compiling fine.

facug91 commented 1 year ago

I think it might be beneficial to add a new job to the CI to run Example. That way, one could see the library running, and the output it generates.