Claw  1.7.0
system_info_unix.hpp
Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2011 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien.jorge@gamned.org
00024 */
00031 #ifndef __CLAW_SYSTEM_INFO_UNIX_HPP__
00032 #define __CLAW_SYSTEM_INFO_UNIXHPP__
00033 
00034 #include <cstdlib>
00035 #include <string>
00036 
00037 namespace claw
00038 {
00044   class system_info
00045   {
00046   public:
00047     /*------------------------------------------------------------------------*/
00051     static std::string get_user_name()
00052     {
00053       std::string result( get_environment("USER") );
00054 
00055       if ( result.empty() )
00056          result = get_environment("LOGNAME");
00057 
00058       return result;
00059     } // get_user_name()
00060 
00061     /*------------------------------------------------------------------------*/
00065     static std::string get_user_directory()
00066     {
00067       return get_environment("HOME");
00068     } // get_user_directory()
00069 
00070     /*------------------------------------------------------------------------*/
00074     template<typename Sequence>
00075     static void get_path( Sequence& path )
00076     {
00077       //
00078     } // get_path()
00079 
00080     /*------------------------------------------------------------------------*/
00084     static std::string get_host_name()
00085     {
00086       return get_environment("HOSTNAME");
00087     } // get_host_name()
00088 
00089     /*------------------------------------------------------------------------*/
00094     static std::string get_temporary_directory()
00095     {
00096       return get_environment("TMPDIR");
00097     } // get_temporary_directory()
00098 
00099     /*------------------------------------------------------------------------*/
00104     static std::string get_environment( const std::string& var )
00105     {
00106       char* value = getenv( var.c_str() );
00107       std::string result;
00108 
00109       if ( value )
00110   result = value;
00111 
00112       return result;
00113     } // get_environment()
00114 
00115   }; // class system_info
00116 } // namespace claw
00117 
00118 #endif // __CLAW_SYSTEM_INFO_UNIX_HPP__