POCO C++库学习和分析 -- 平台与环境
在写程序的时候,有时候需要收集一些系统信息,用作软硬件的绑定或生成唯一的注册码信息等。Poco中提供了一个很简单的类Environment来实现这个功能。这个类的定义如下:
class Foundation_API Environment
/// This class provides access to environment variables
/// and some general system information.
{
public:
typedef UInt8 NodeId[6]; /// Ethernet address.
static std::string get(const std::string& name);
/// Returns the value of the environment variable
/// with the given name. Throws a NotFoundException
/// if the variable does not exist.
static std::string get(const std::string& name, const std::string& defaultValue);
/// Returns the value of the environment variable
/// with the given name. If the environment variable
/// is undefined, returns defaultValue instead.
static bool has(const std::string& name);
/// Returns true iff an environment variable
/// with the given name is defined.