Poco::Environment を紹介します。
このクラスは、環境変数と一般的なシステム情報へのアクセスを提供します。
EnvironmentTest.cpp
・各 method の使用例を示します。
・set() の例は無いですが、他と同様に使えます。
#include <Poco/Environment.h> #include <Poco/Format.h> #include <string> #include "ScopedLogMessage.h" #include "PrepareConsoleLogger.h" const std::string kShellStr("SHELL"); const std::string kNotExistStr("NOT_EXIST"); const std::string kNotExistDefaultStr("NOT_EXIST_DEFAULT"); const std::string kManPathStr("MANPATH"); int main(int /*argc*/, char** /*argv*/) { PrepareConsoleLogger logger(Poco::Logger::ROOT, Poco::Message::PRIO_INFORMATION); ScopedLogMessage msg("EnvironmentTest ", "start", "end"); // Poco::Environment::get try { msg.Message(Poco::format(" %s: %s" , kShellStr , Poco::Environment::get(kShellStr))); } catch(Poco::NotFoundException& exc) { msg.Message(exc.displayText()); } msg.Message(Poco::format(" %s: %s" , kNotExistStr , Poco::Environment::get(kNotExistStr, kNotExistDefaultStr))); // Poco::Environment::has msg.Message(Poco::format(" has %s: %s", kManPathStr, std::string(Poco::Environment::has(kManPathStr) ? "yes":"no"))); // Poco::Environment::nodeId try { Poco::Environment::NodeId nodeId; Poco::Environment::nodeId(nodeId); msg.Message(Poco::format(" nodeId: %02?x:%02?x:%02?x:%02?x:%02?x:%02?x" , nodeId[0] , nodeId[1] , nodeId[2] , nodeId[3] , nodeId[4] , nodeId[5])); } catch(Poco::SystemException& exc) { msg.Message(exc.displayText()); } msg.Message(Poco::format(" nodeId: %s" , Poco::Environment::nodeId())); // Poco::Environment::nodeName msg.Message(Poco::format(" nodeName: %s" , Poco::Environment::nodeName())); // Poco::Environment::osArchitecture msg.Message(Poco::format(" osArchitecture: %s" , Poco::Environment::osArchitecture())); // Poco::Environment::osName msg.Message(Poco::format(" osName: %s" , Poco::Environment::osName())); // Poco::Environment::osVersion msg.Message(Poco::format(" osVersion: %s" , Poco::Environment::osVersion())); // Poco::Environment::processorCount msg.Message(Poco::format(" processorCount: %u" , Poco::Environment::processorCount())); return 0; } |
Results of execution
・On Linux
[0] EnvironmentTest start [0] SHELL: /bin/bash [0] NOT_EXIST: NOT_EXIST_DEFAULT [0] has MANPATH: no [0] nodeId: 00:0c:29:13:da:fb [0] nodeId: 00:0c:29:13:da:fb [0] nodeName: debian [0] osArchitecture: i686 [0] osName: Linux [0] osVersion: 2.6.26-2-686 [0] processorCount: 1 [0] EnvironmentTest end |
・On Macintosh OSX 10.6.4
[0] EnvironmentTest start [0] SHELL: /bin/bash [0] NOT_EXIST: NOT_EXIST_DEFAULT [0] has MANPATH: yes [0] nodeId: 00:16:cb:b0:aa:e4 [0] nodeId: 00:16:cb:b0:aa:e4 [0] nodeName: Mac-mini.local [0] osArchitecture: i386 [0] osName: Darwin [0] osVersion: 10.4.0 [0] processorCount: 2 [0] EnvironmentTest end |
・On Windows XP sp3
[0] EnvironmentTest start [0] Not found: SHELL [0] NOT_EXIST: NOT_EXIST_DEFAULT [0] has MANPATH: no [0] nodeId: 00:0c:29:ea:ce:98 [0] nodeId: 00:0c:29:ea:ce:98 [0] nodeName: SETSU-SHY3M0TG8 [0] osArchitecture: IA32 [0] osName: Windows NT [0] osVersion: 5.1 (Build 2600: Service Pack 3) [0] processorCount: 1 [0] EnvironmentTest end |
Downloads
・ここをクリックすると、makefile や VC++ プロジェクトなど一式がダウンロードできます。
(2013.05.31 updated)
・2010年6月25日からのダウンロード数:962
Subversion
・フリーの Subversion ホスティングサービス Assemblaで、ソースコードを管理しています。
Reference
・http://pocoproject.org にある PlatformAndEnvironment のプレセンテーション。(PDF)
![]() |
Copyright © 2010 Round Square Inc. All rights reserved. |
---|
0 Comments.