libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YEnvVar.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YEnvVar.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef YEnvVar_h
00026 #define YEnvVar_h
00027 
00028 #include <string>
00029 #include <iosfwd>
00030 
00031 
00032 
00033 /**
00034  * Helper class to represent an environment variable and its value.
00035  **/
00036 class YEnvVar
00037 {
00038 public:
00039     /**
00040      * Constructor:
00041      * Retrieve the environment variable 'name' and store the value
00042      * (unless 'name' is empty).
00043      **/
00044     YEnvVar( const std::string & name = std::string() );
00045 
00046     /**
00047      * Return the name of the environment variable.
00048      **/
00049     std::string name() const { return _name; }
00050 
00051     /**
00052      * Return 'true' if the environment variable is set.
00053      **/
00054     bool isSet() const { return _isSet; }
00055 
00056     /**
00057      * Return the value of the environment variable.
00058      **/
00059     std::string value() const { return _value; }
00060 
00061     /**
00062      * Return 'true' if the environment variable is set and the value is
00063      * 'str'.
00064      **/
00065     bool isEqual( const std::string & str, bool caseSensitive = false ) const;
00066 
00067     /**
00068      * Case-insensitive comparison (shortcut for isEqual() ):
00069      * Return 'true' if the environment variable is set and the value is
00070      * 'str'.
00071      **/
00072     bool operator==( const std::string & str ) const
00073         { return isEqual( str ); }
00074 
00075     /**
00076      * Return 'true' if the environment variable is set and the value contains
00077      * 'str'.
00078      **/
00079     bool contains( const std::string & str, bool caseSensitive = false ) const;
00080 
00081 
00082 private:
00083 
00084     std::string _name;
00085     std::string _value;
00086     bool        _isSet;
00087 };
00088 
00089 
00090 /**
00091  * Stream output for YEnvVar
00092  **/
00093 std::ostream & operator<<( std::ostream & stream, const YEnvVar env );
00094 
00095 
00096 /**
00097  * Return 'str' converted to lower case.
00098  **/
00099 std::string tolower( const std::string & str );
00100 
00101 
00102 #endif // YEnvVar_h
 All Classes Functions Variables Enumerations Friends