Class OS

Synopsis

#include <src/easylogging++.h>

class OS : base::StaticClass

Description

Operating System helper static class used internally. You should not use it.

Mentioned in

Inheritance

Ancestors: StaticClass

Methods

currentHostGets current host name or computer name.
currentUserGets current username.
getBashOutputRuns command on terminal and returns the output.
getDeviceNameReads android device name.
getEnvironmentVariableGets environment variable. This is cross-platform and CRT safe (for VC++)
getPropertyReads android property value.
getWindowsEnvironmentVariableGets environment variables for Windows based OS. We are not using getenv(const char*) because of CRT deprecation.
termSupportsColorWhether or not terminal supports colors.

Source

Lines 1141-1181 in src/easylogging++.h.

class OS : base::StaticClass {
 public:
#if ELPP_OS_WINDOWS
  /// @brief Gets environment variables for Windows based OS.
  ///        We are not using <code>getenv(const char*)</code> because of CRT deprecation
  /// @param varname Variable name to get environment variable value for
  /// @return If variable exist the value of it otherwise nullptr
  static const char* getWindowsEnvironmentVariable(const char* varname);
#endif  // ELPP_OS_WINDOWS
#if ELPP_OS_ANDROID
  /// @brief Reads android property value
  static std::string getProperty(const char* prop);

  /// @brief Reads android device name
  static std::string getDeviceName(void);
#endif  // ELPP_OS_ANDROID

  /// @brief Runs command on terminal and returns the output.
  ///
  /// @detail This is applicable only on unix based systems, for all other OS, an empty string is returned.
  /// @param command Bash command
  /// @return Result of bash output or empty string if no result found.
  static const std::string getBashOutput(const char* command);

  /// @brief Gets environment variable. This is cross-platform and CRT safe (for VC++)
  /// @param variableName Environment variable name
  /// @param defaultVal If no environment variable or value found the value to return by default
  /// @param alternativeBashCommand If environment variable not found what would be alternative bash command
  ///        in order to look for value user is looking for. E.g, for 'user' alternative command will 'whoami'
  static std::string getEnvironmentVariable(const char* variableName, const char* defaultVal,
      const char* alternativeBashCommand = nullptr);
  /// @brief Gets current username.
  static std::string currentUser(void);

  /// @brief Gets current host name or computer name.
  ///
  /// @detail For android systems this is device name with its manufacturer and model separated by hyphen
  static std::string currentHost(void);
  /// @brief Whether or not terminal supports colors
  static bool termSupportsColor(void);
};





Add Discussion

Log in to comment