Poco C ++ database learning and analysis-platform and Environment
Before writingProgramSometimes some system information needs to be collected for software and hardware binding or generating unique registration code information. Poco provides a simple class environment to implement this function. The class is defined as follows:
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. static void set (const STD: string & name, const STD: string & value); // sets the environment variable with the given name // to the given value. static STD: String osname (); // returns the operating system name. static STD: String osversion (); // returns the operating system version. static STD: String osarchitecture (); // returns the operating system architecture. static STD: String nodename (); // returns the node (or host) Name. static void nodeid (nodeid & ID); // returns the ethernet address of the first Ethernet // adapter found on the system. ///// throws a systemexception if no Ethernet adapter is available. static STD: String nodeid (); // returns the ethernet address (Format "XX: XX ") /// of the first Ethernet Adapter found on the system. ///// throws a systemexception if no Ethernet adapter is available. static unsigned processorcount (); // returns the number of processors installed in the system. //// if the number of processors cannot be determined, returns 1. static poco: uint32 libraryversion (); // returns the poco c ++ libraries version as a hexadecimal // number in format 0 xaabbccdd, where //-AA is the major version number, //-BB is the minor version number, //-CC is the revision number, and //-dd is the patch level number. ///// some patch level ranges have special meanings: //-DX mark development releases, ///-Ax mark Alpha releases, and //-bx mark beta releases .};
From the definition, we can see that its functions include:
1. obtain the information of the first network card of the system.
2. Get and set the environment variable value of the specified name
3. Get the operating system name, version, and structure
4. Get the number of processors
The following is an example:
# Include "stdafx. H "# include" poco/environment. H "# include <iostream> using poco: Environment; int main (INT argc, char ** argv) {STD: cout <" OS name: "<environment:: osname () <STD: Endl <"OS version:" <environment: osversion () <STD: Endl <"OS arch: "<environment: osarchitecture () <STD: Endl <" node name: "<environment: nodename () <STD :: endl <"Node ID:" <environment: nodeid () <STD: Endl <"processor count:" <environment: processorcount () <STD: Endl <"library version:" <environment: libraryversion () <STD: Endl; If (Environment: Has ("Temp ")) STD: cout <"Temp:" <environment: Get ("Temp") <STD: Endl; Environment: Set ("poco ", "foo"); Return 0 ;}
The internal implementation of environment is very simple and relies on the environmentimpl class. Each operating system implements its own environmentimpl class, thus implementing unified interfaces for different operating systems.
(Copyright, reprinted, please indicate the author and the source http://blog.csdn.net/arau_sh/article/details/8698406)